mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-24 13:01:51 +01:00
Moved "Show all categories" to display settings
Alos fixing some small library visual bugs
This commit is contained in:
parent
f091a9bb51
commit
f1acafc89f
@ -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<Boolean>, block: (() -> Unit)? = null) {
|
||||
isChecked = pref.get()
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
pref.set(isChecked)
|
||||
block?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a radio group with a int preference.
|
||||
*/
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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<CoordinatorLayout.LayoutParams> {
|
||||
anchorGravity =
|
||||
|
@ -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<FastAdapter.ViewHolder<CategoryItem>>() {
|
||||
|
||||
/** 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<CategoryItem> {
|
||||
return if (category.id == -1) {
|
||||
ShowAllViewHolder(Injekt.get<PreferencesHelper>().showAllCategories(), v)
|
||||
} else {
|
||||
ViewHolder(v)
|
||||
}
|
||||
return ViewHolder(v)
|
||||
}
|
||||
|
||||
class ViewHolder(view: View) : FastAdapter.ViewHolder<CategoryItem>(view) {
|
||||
@ -49,19 +32,4 @@ class CategoryItem(val category: Category) : AbstractItem<FastAdapter.ViewHolder
|
||||
categoryTitle.text = null
|
||||
}
|
||||
}
|
||||
|
||||
class ShowAllViewHolder(val pref: Preference<Boolean>, view: View) :
|
||||
FastAdapter.ViewHolder<CategoryItem>(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<Any>) {
|
||||
checkbox?.isChecked = pref.get()
|
||||
}
|
||||
override fun unbindView(item: CategoryItem) {}
|
||||
}
|
||||
}
|
||||
|
@ -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<CategoryItem>()
|
||||
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<Category>) {
|
||||
itemAdapter.set(listOf(headerItem) + items.map(::CategoryItem))
|
||||
itemAdapter.set(items.map(::CategoryItem))
|
||||
fastAdapter.onBindViewHolderListener =
|
||||
(object : OnBindViewHolderListenerImpl<CategoryItem>() {
|
||||
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<CategoryItem>() {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/settings_scroll_view"
|
||||
@ -29,6 +29,11 @@
|
||||
android:paddingEnd="12dp"
|
||||
android:text="@string/display_as" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/display_group"
|
||||
android:layout_width="match_parent"
|
||||
@ -55,6 +60,16 @@
|
||||
android:text="@string/comfortable_grid" />
|
||||
</RadioGroup>
|
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox
|
||||
android:id="@+id/show_all"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/show_all_categories" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
style="@style/TextAppearance.MaterialComponents.Headline6"
|
||||
android:layout_width="match_parent"
|
||||
@ -95,6 +110,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:text="@string/large" />
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -186,7 +202,7 @@
|
||||
style="@style/Theme.Widget.Button.TextButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/more_library_settings"/>
|
||||
android:text="@string/more_library_settings" />
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user