From 08e63e5fab93154ca85d16e459226f01aeab5a2d Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Apr 2022 15:04:00 -0400 Subject: [PATCH] Minor cleanup 2: Electric Boogaloo - Reword pins on top setting - Make "Latest" button style match old UI - Sort sources by name --- .../source/interactor/GetEnabledSources.kt | 62 ++++++++----------- .../eu/kanade/domain/source/model/Source.kt | 8 +-- .../presentation/source/SourceScreen.kt | 8 ++- .../data/preference/PreferencesHelper.kt | 2 +- .../ui/browse/source/SourcePresenter.kt | 2 +- .../ui/setting/SettingsBrowseController.kt | 9 ++- app/src/main/res/values/strings.xml | 4 +- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt index 980738794c..05e681b042 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt @@ -12,46 +12,36 @@ import kotlinx.coroutines.flow.distinctUntilChanged class GetEnabledSources( private val repository: SourceRepository, - private val preferences: PreferencesHelper + private val preferences: PreferencesHelper, ) { fun subscribe(): Flow> { - return preferences.pinnedSources().asFlow() - .combine(preferences.enabledLanguages().asFlow()) { pinList, enabledLanguages -> - Config(pinSet = pinList, enabledSources = enabledLanguages) - } - .combine(preferences.disabledSources().asFlow()) { config, disabledSources -> - config.copy(disabledSources = disabledSources) - } - .combine(preferences.lastUsedSource().asFlow()) { config, lastUsedSource -> - config.copy(lastUsedSource = lastUsedSource) - } - .combine(repository.getSources()) { (pinList, enabledLanguages, disabledSources, lastUsedSource), sources -> - val pinsOnTop = preferences.pinsOnTop().get() - sources - .filter { it.lang in enabledLanguages || it.id == LocalSource.ID } - .filterNot { it.id.toString() in disabledSources } - .flatMap { - val flag = if ("${it.id}" in pinList) Pins.pinned else Pins.unpinned - val source = it.copy(pin = flag) - val toFlatten = mutableListOf(source) - if (source.id == lastUsedSource) { - toFlatten.add(source.copy(isUsedLast = true, pin = source.pin - Pin.Actual)) - } - if (pinsOnTop.not() && Pin.Pinned in source.pin) { - toFlatten[0] = toFlatten[0].copy(pin = source.pin + Pin.Forced) - toFlatten.add(source.copy(pin = source.pin - Pin.Actual)) - } - toFlatten + return combine( + preferences.pinnedSources().asFlow(), + preferences.enabledLanguages().asFlow(), + preferences.disabledSources().asFlow(), + preferences.lastUsedSource().asFlow(), + repository.getSources(), + ) { pinnedSourceIds, enabledLanguages, disabledSources, lastUsedSource, sources -> + val duplicatePins = preferences.duplicatePinnedSources().get() + sources + .filter { it.lang in enabledLanguages || it.id == LocalSource.ID } + .filterNot { it.id.toString() in disabledSources } + .sortedBy { it.name } + .flatMap { + val flag = if ("${it.id}" in pinnedSourceIds) Pins.pinned else Pins.unpinned + val source = it.copy(pin = flag) + val toFlatten = mutableListOf(source) + if (source.id == lastUsedSource) { + toFlatten.add(source.copy(isUsedLast = true, pin = source.pin - Pin.Actual)) } - } + if (duplicatePins && Pin.Pinned in source.pin) { + toFlatten[0] = toFlatten[0].copy(pin = source.pin + Pin.Forced) + toFlatten.add(source.copy(pin = source.pin - Pin.Actual)) + } + toFlatten + } + } .distinctUntilChanged() } } - -private data class Config( - val pinSet: Set = setOf(), - val enabledSources: Set = setOf(), - val disabledSources: Set = setOf(), - val lastUsedSource: Long? = null -) diff --git a/app/src/main/java/eu/kanade/domain/source/model/Source.kt b/app/src/main/java/eu/kanade/domain/source/model/Source.kt index 4878ada028..0f9d429ad3 100644 --- a/app/src/main/java/eu/kanade/domain/source/model/Source.kt +++ b/app/src/main/java/eu/kanade/domain/source/model/Source.kt @@ -26,11 +26,11 @@ data class Source( ?.asImageBitmap() } - val key: () -> Long = { + val key: () -> String = { when { - isUsedLast -> id shr 16 - Pin.Forced in pin -> id shr 32 - else -> id + isUsedLast -> "$id-lastused" + Pin.Forced in pin -> "$id-forced" + else -> "$id" } } } diff --git a/app/src/main/java/eu/kanade/presentation/source/SourceScreen.kt b/app/src/main/java/eu/kanade/presentation/source/SourceScreen.kt index 5621b73a32..b1441967d8 100644 --- a/app/src/main/java/eu/kanade/presentation/source/SourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/source/SourceScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.material3.AlertDialog import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -195,7 +196,12 @@ fun SourceItem( } if (item.supportsLatest) { TextButton(onClick = { onClickLatest(item) }) { - Text(text = stringResource(id = R.string.latest)) + Text( + text = stringResource(id = R.string.latest), + style = LocalTextStyle.current.copy( + color = MaterialTheme.colorScheme.primary + ), + ) } } SourcePinButton( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 678be90e1a..e7351d163a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -324,7 +324,7 @@ class PreferencesHelper(val context: Context) { fun autoClearChapterCache() = prefs.getBoolean(Keys.autoClearChapterCache, false) - fun pinsOnTop() = flowPrefs.getBoolean("pins_on_top", true) + fun duplicatePinnedSources() = flowPrefs.getBoolean("duplicate_pinned_sources", false) fun setChapterSettingsDefault(manga: Manga) { prefs.edit { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt index 2aed114ebb..d770abb8a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcePresenter.kt @@ -44,7 +44,7 @@ class SourcePresenter( } } - private suspend fun collectLatestSources(sources: List) { + private fun collectLatestSources(sources: List) { val map = TreeMap> { d1, d2 -> // Catalogues without a lang defined will be placed at the end when { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index 6a3b22587f..5192a588a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -22,13 +22,12 @@ class SettingsBrowseController : SettingsController() { titleRes = R.string.browse preferenceCategory { - titleRes = R.string.pref_category_general + titleRes = R.string.label_sources switchPreference { - bindTo(preferences.pinsOnTop()) - titleRes = R.string.pref_move_on_top - summaryRes = R.string.pref_move_on_top_summary - defaultValue = true + bindTo(preferences.duplicatePinnedSources()) + titleRes = R.string.pref_duplicate_pinned_sources + summaryRes = R.string.pref_duplicate_pinned_sources_summary } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f8543f843..b3b4629fd8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -419,10 +419,10 @@ Track + Show duplicated pinned sources + Repeat pinned sources in their respective language groups Check for extension updates Only include pinned sources - Move pins on top - Move up pins to top of the source list Create backup