From f1acafc89f4df63da5fb33935903c9b451fd38f3 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 11 May 2020 23:51:48 -0400 Subject: [PATCH] Moved "Show all categories" to display settings Alos fixing some small library visual bugs --- .../ui/library/DisplayBottomSheet.kt | 14 +++++ .../tachiyomi/ui/library/LibraryController.kt | 5 +- .../ui/library/LibraryGestureDetector.kt | 8 +-- .../ui/library/category/CategoryItem.kt | 38 +------------ .../library/category/CategoryRecyclerView.kt | 28 +--------- .../main/res/layout/display_bottom_sheet.xml | 56 ++++++++++++------- 6 files changed, 60 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt index 84eaa82cf7..5f7e34d4b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt @@ -83,6 +83,9 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee controller.reattachAdapter() if (sheetBehavior.isCollapsed()) dismiss() } + show_all.bindToPreference(preferences.showAllCategories()) { + controller.presenter.getLibrary() + } uniform_grid.bindToPreference(preferences.uniformGrid()) { controller.reattachAdapter() } @@ -116,6 +119,17 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee } } + /** + * Binds a checkbox or switch view with a boolean preference. + */ + private fun CompoundButton.bindToPreference(pref: com.tfcporciuncula.flow.Preference, block: (() -> Unit)? = null) { + isChecked = pref.get() + setOnCheckedChangeListener { _, isChecked -> + pref.set(isChecked) + block?.invoke() + } + } + /** * Binds a radio group with a int preference. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index c0cd19508a..e1ad80f536 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -242,7 +242,7 @@ class LibraryController( return if (presenter.showAllCategories) { !recycler.canScrollVertically(-1) } else { - getVisibleHeader()?.category?.id == presenter.categories.firstOrNull()?.id + getVisibleHeader()?.category?.order == presenter.categories.minBy { it.order }?.order } } @@ -250,7 +250,7 @@ class LibraryController( return if (presenter.showAllCategories) { !recycler.canScrollVertically(1) } else { - getVisibleHeader()?.category?.id == presenter.categories.lastOrNull()?.id + getVisibleHeader()?.category?.order == presenter.categories.maxBy { it.order }?.order } } @@ -775,6 +775,7 @@ class LibraryController( private fun onRefresh() { activity?.invalidateOptionsMenu() + showCategories(false) presenter.getLibrary() destroyActionModeIfNeeded() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt index 7f56e3e897..fc6636747c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt @@ -33,16 +33,10 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur controller.filter_bottom_sheet.sheetBehavior?.hide() } result = true - } else if (abs(diffX) >= abs(diffY) && abs(diffX) > MainActivity.SWIPE_THRESHOLD && abs( + } else if (abs(diffX) >= abs(diffY) && abs(diffX) > MainActivity.SWIPE_THRESHOLD * 3 && abs( velocityX ) > MainActivity.SWIPE_VELOCITY_THRESHOLD ) { - // val transition = androidx.transition.AutoTransition() - // transition.duration = 150 - - androidx.transition.TransitionManager.beginDelayedTransition( - controller.library_layout - ) if (diffX <= 0) { controller.category_hopper_frame.updateLayoutParams { anchorGravity = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryItem.kt index 6356779c8e..b024cb7c0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryItem.kt @@ -1,41 +1,24 @@ package eu.kanade.tachiyomi.ui.library.category import android.view.View -import android.widget.CheckBox import android.widget.TextView import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.items.AbstractItem -import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get class CategoryItem(val category: Category) : AbstractItem>() { /** defines the type defining this item. must be unique. preferably an id */ - override val type: Int = if (category.id == -1) { - R.id.auto_checkbox - } else { - R.id.category_text - } + override val type: Int = R.id.category_text /** defines the layout which will be used for this item in the list */ - override val layoutRes: Int = if (category.id == -1) { - R.layout.auto_ext_checkbox - } else { - R.layout.catergory_text_view - } + override val layoutRes: Int = R.layout.catergory_text_view override var identifier = category.id?.toLong() ?: -1L override fun getViewHolder(v: View): FastAdapter.ViewHolder { - return if (category.id == -1) { - ShowAllViewHolder(Injekt.get().showAllCategories(), v) - } else { - ViewHolder(v) - } + return ViewHolder(v) } class ViewHolder(view: View) : FastAdapter.ViewHolder(view) { @@ -49,19 +32,4 @@ class CategoryItem(val category: Category) : AbstractItem, view: View) : - FastAdapter.ViewHolder(view) { - - val checkbox: CheckBox? = view.findViewById(R.id.auto_checkbox) - - init { - checkbox?.setText(R.string.show_all_categories) - } - - override fun bindView(item: CategoryItem, payloads: List) { - checkbox?.isChecked = pref.get() - } - override fun unbindView(item: CategoryItem) {} - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt index f805f38aef..3c7822a2de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/category/CategoryRecyclerView.kt @@ -2,18 +2,14 @@ package eu.kanade.tachiyomi.ui.library.category import android.content.Context import android.util.AttributeSet -import android.view.View import android.view.ViewGroup -import android.widget.CheckBox import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.adapters.ItemAdapter -import com.mikepenz.fastadapter.listeners.CustomEventHook import com.mikepenz.fastadapter.listeners.OnBindViewHolderListenerImpl import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category -import eu.kanade.tachiyomi.data.database.models.CategoryImpl import eu.kanade.tachiyomi.util.view.marginBottom class CategoryRecyclerView @JvmOverloads constructor( @@ -27,9 +23,6 @@ class CategoryRecyclerView @JvmOverloads constructor( var onShowAllClicked: (Boolean) -> Unit = { } private val itemAdapter = ItemAdapter() var selectedCategory: Int = 0 - val headerItem = CategoryItem(CategoryImpl().apply { - id = -1 - }) init { fastAdapter = FastAdapter.with(itemAdapter) @@ -38,7 +31,7 @@ class CategoryRecyclerView @JvmOverloads constructor( } fun setCategories(items: List) { - itemAdapter.set(listOf(headerItem) + items.map(::CategoryItem)) + itemAdapter.set(items.map(::CategoryItem)) fastAdapter.onBindViewHolderListener = (object : OnBindViewHolderListenerImpl() { override fun onBindViewHolder( @@ -48,7 +41,7 @@ class CategoryRecyclerView @JvmOverloads constructor( ) { super.onBindViewHolder(viewHolder, position, payloads) (viewHolder as? CategoryItem.ViewHolder)?.categoryTitle?.isSelected = - selectedCategory + 1 == position + selectedCategory == position } }) fastAdapter.onClickListener = { _, _, item, _ -> @@ -56,28 +49,13 @@ class CategoryRecyclerView @JvmOverloads constructor( onCategoryClicked(item.category.order) true } - fastAdapter.addEventHook(object : CustomEventHook() { - override fun onBind(viewHolder: ViewHolder): View? { - return if (viewHolder is CategoryItem.ShowAllViewHolder) { - viewHolder.checkbox - } else { - null - } - } - - override fun attachEvent(view: View, viewHolder: ViewHolder) { - (view as? CheckBox)?.setOnCheckedChangeListener { _, isChecked -> - onShowAllClicked(isChecked) - } - } - }) } fun setCategories(selected: Int) { selectedCategory = selected for (i in 0..manager.itemCount) { (findViewHolderForAdapterPosition(i) as? CategoryItem.ViewHolder)?.categoryTitle?.isSelected = - selectedCategory + 1 == i + selectedCategory == i } } diff --git a/app/src/main/res/layout/display_bottom_sheet.xml b/app/src/main/res/layout/display_bottom_sheet.xml index 353207fc37..03d884c6a5 100644 --- a/app/src/main/res/layout/display_bottom_sheet.xml +++ b/app/src/main/res/layout/display_bottom_sheet.xml @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/display_bottom_sheet" android:layout_width="match_parent" - android:background="@drawable/bottom_sheet_rounded_background" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:background="@drawable/bottom_sheet_rounded_background"> - + android:orientation="vertical"> - + android:orientation="horizontal" + android:paddingStart="12dp" + android:paddingEnd="12dp"> - + + + + + + + + android:layout_marginEnd="12dp" + android:text="@string/show_all_categories" /> - - + + + android:text="@string/more_library_settings" />