Option to move collapsed dynamic categories to bottom of the list

This commit is contained in:
Jays2Kings 2021-04-19 01:19:31 -04:00
parent 85596ea61d
commit a0dba53128
7 changed files with 29 additions and 3 deletions

View File

@ -280,6 +280,8 @@ class PreferencesHelper(val context: Context) {
fun collapsedDynamicCategories() = flowPrefs.getStringSet("collapsed_dynamic_categories", mutableSetOf()) fun collapsedDynamicCategories() = flowPrefs.getStringSet("collapsed_dynamic_categories", mutableSetOf())
fun collapsedDynamicAtBottom() = flowPrefs.getBoolean("collapsed_dynamic_at_bottom", false)
fun hiddenSources() = flowPrefs.getStringSet("hidden_catalogues", mutableSetOf()) fun hiddenSources() = flowPrefs.getStringSet("hidden_catalogues", mutableSetOf())
fun pinnedCatalogues() = rxPrefs.getStringSet("pinned_catalogues", emptySet()) fun pinnedCatalogues() = rxPrefs.getStringSet("pinned_catalogues", emptySet())

View File

@ -590,7 +590,7 @@ class LibraryPresenter(
}.flatten().toMutableList() }.flatten().toMutableList()
val hiddenDynamics = preferences.collapsedDynamicCategories().get() val hiddenDynamics = preferences.collapsedDynamicCategories().get()
val headers = tagItems.map { item -> var headers = tagItems.map { item ->
Category.createCustom( Category.createCustom(
item.key, item.key,
preferences.librarySortingMode().getOrDefault(), preferences.librarySortingMode().getOrDefault(),
@ -611,6 +611,9 @@ class LibraryPresenter(
it.name it.name
} }
} }
if (preferences.collapsedDynamicAtBottom().get()) {
headers = headers.filterNot { it.isHidden } + headers.filter { it.isHidden }
}
headers.forEach { category -> headers.forEach { category ->
val catId = category.id ?: return@forEach val catId = category.id ?: return@forEach
val headerItem = tagItems[if (category.sourceId != null) "${category.name}$sourceSplitter${category.sourceId}" else category.name] val headerItem = tagItems[if (category.sourceId != null) "${category.name}$sourceSplitter${category.sourceId}" else category.name]

View File

@ -2,8 +2,10 @@ package eu.kanade.tachiyomi.ui.library.display
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.LibraryCategoryLayoutBinding import eu.kanade.tachiyomi.databinding.LibraryCategoryLayoutBinding
import eu.kanade.tachiyomi.util.bindToPreference import eu.kanade.tachiyomi.util.bindToPreference
import eu.kanade.tachiyomi.util.lang.withSubtitle
import eu.kanade.tachiyomi.util.system.toInt import eu.kanade.tachiyomi.util.system.toInt
import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView import eu.kanade.tachiyomi.widget.BaseLibraryDisplayView
import kotlin.math.min import kotlin.math.min
@ -22,6 +24,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
categoryShow.bindToPreference(preferences.showCategoryInTitle()) { categoryShow.bindToPreference(preferences.showCategoryInTitle()) {
controller?.showMiniBar() controller?.showMiniBar()
} }
dynamicToBottom.text = context.getString(R.string.move_dynamic_to_bottom)
.withSubtitle(context, R.string.when_grouping_by_sources_tags)
dynamicToBottom.bindToPreference(preferences.collapsedDynamicAtBottom()) {
controller?.presenter?.getLibrary()
}
val hideHopper = min( val hideHopper = min(
2, 2,
preferences.hideHopper().get().toInt() * 2 + preferences.autohideHopper().get() preferences.hideHopper().get().toInt() * 2 + preferences.autohideHopper().get()

View File

@ -32,8 +32,8 @@ class RecentsOptionsSheet(activity: Activity) :
BottomSheetBehavior.from(binding.root.parent as ViewGroup).skipCollapsed = true BottomSheetBehavior.from(binding.root.parent as ViewGroup).skipCollapsed = true
val titleText = context.getString(R.string.show_reset_history_button) val titleText = context.getString(R.string.show_reset_history_button)
val subtitleText = context.getString(R.string.press_and_hold_to_also_reset) binding.showRemoveHistory.text = titleText
binding.showRemoveHistory.text = titleText.withSubtitle(binding.showRemoveHistory.context, subtitleText) .withSubtitle(binding.showRemoveHistory.context, R.string.press_and_hold_to_also_reset)
} }
private fun initGeneralPreferences() { private fun initGeneralPreferences() {

View File

@ -12,6 +12,7 @@ import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.text.style.SuperscriptSpan import android.text.style.SuperscriptSpan
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlin.math.floor import kotlin.math.floor
@ -99,6 +100,9 @@ fun String.indexesOf(substr: String, ignoreCase: Boolean = true): List<Int> {
} }
} }
fun String.withSubtitle(context: Context, @StringRes subtitleRes: Int) =
withSubtitle(context, context.getString(subtitleRes))
fun String.withSubtitle(context: Context, subtitle: String): Spanned { fun String.withSubtitle(context: Context, subtitle: String): Spanned {
val spannable = SpannableStringBuilder(this + "\n" + subtitle) val spannable = SpannableStringBuilder(this + "\n" + subtitle)
spannable.setSpan( spannable.setSpan(

View File

@ -27,6 +27,14 @@
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:text="@string/show_all_categories" /> android:text="@string/show_all_categories" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/dynamic_to_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:text="@string/move_dynamic_to_bottom" />
<eu.kanade.tachiyomi.widget.MaterialSpinnerView <eu.kanade.tachiyomi.widget.MaterialSpinnerView
android:id="@+id/hide_hopper_spinner" android:id="@+id/hide_hopper_spinner"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -119,6 +119,8 @@
library from the browse tab.</string> library from the browse tab.</string>
<string name="no_matches_for_filters">No matches found for your current filters</string> <string name="no_matches_for_filters">No matches found for your current filters</string>
<string name="show_all_categories">Show all categories</string> <string name="show_all_categories">Show all categories</string>
<string name="move_dynamic_to_bottom">Move collapsed dynamic categories to bottom</string>
<string name="when_grouping_by_sources_tags">When grouping library by sources, status, etc.</string>
<string name="always_show_current_category">Always show current category</string> <string name="always_show_current_category">Always show current category</string>
<string name="category_hopper_long_press">Category hopper long-press action</string> <string name="category_hopper_long_press">Category hopper long-press action</string>
<string name="expand_collapse_all_categories">Expand/collapse all categories</string> <string name="expand_collapse_all_categories">Expand/collapse all categories</string>