Minor cleanup 2: Electric Boogaloo
- Reword pins on top setting - Make "Latest" button style match old UI - Sort sources by name (cherry picked from commit 08e63e5fab93154ca85d16e459226f01aeab5a2d) # Conflicts: # app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt # app/src/main/java/eu/kanade/domain/source/model/Source.kt
This commit is contained in:
parent
7e0c1308bd
commit
e2056982eb
@ -12,83 +12,66 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
|
||||
class GetEnabledSources(
|
||||
private val repository: SourceRepository,
|
||||
private val preferences: PreferencesHelper
|
||||
private val preferences: PreferencesHelper,
|
||||
) {
|
||||
|
||||
fun subscribe(): Flow<List<Source>> {
|
||||
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)
|
||||
}
|
||||
return combine(
|
||||
preferences.pinnedSources().asFlow(),
|
||||
combine(
|
||||
preferences.enabledLanguages().asFlow(),
|
||||
preferences.disabledSources().asFlow(),
|
||||
preferences.lastUsedSource().asFlow(),
|
||||
) { a, b, c -> Triple(a, b, c) },
|
||||
// SY -->
|
||||
.combine(preferences.dataSaverExcludedSources().asFlow()) { config, excludedFromDataSaver ->
|
||||
config.copy(excludedFromDataSaver = excludedFromDataSaver)
|
||||
}
|
||||
.combine(preferences.sourcesTabSourcesInCategories().asFlow()) { config, sourcesInCategories ->
|
||||
config.copy(sourcesInCategories = sourcesInCategories)
|
||||
}
|
||||
.combine(preferences.sourcesTabCategoriesFilter().asFlow()) { config, sourceCategoriesFilter ->
|
||||
config.copy(sourceCategoriesFilter = sourceCategoriesFilter)
|
||||
}
|
||||
combine(
|
||||
preferences.dataSaverExcludedSources().asFlow(),
|
||||
preferences.sourcesTabSourcesInCategories().asFlow(),
|
||||
preferences.sourcesTabCategoriesFilter().asFlow(),
|
||||
) { a, b, c -> Triple(a, b, c) },
|
||||
// SY <--
|
||||
.combine(repository.getSources()) { (pinList, enabledLanguages, disabledSources, lastUsedSource, excludedFromDataSaver, sourcesInCategories, sourceCategoriesFilter), sources ->
|
||||
val pinsOnTop = preferences.pinsOnTop().get()
|
||||
val sourcesAndCategories = sourcesInCategories.map {
|
||||
it.split('|').let { (source, test) -> source.toLong() to test }
|
||||
}
|
||||
val sourcesInSourceCategories = sourcesAndCategories.map { it.first }
|
||||
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
|
||||
// SY -->
|
||||
val categories = sourcesAndCategories.filter { (id) -> id == it.id }
|
||||
.map(Pair<*, String>::second)
|
||||
.toSet()
|
||||
// SY <--
|
||||
val source = it.copy(
|
||||
pin = flag,
|
||||
isExcludedFromDataSaver = it.id.toString() in excludedFromDataSaver,
|
||||
categories = categories
|
||||
)
|
||||
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))
|
||||
}
|
||||
// SY -->
|
||||
categories.forEach { category ->
|
||||
toFlatten.add(source.copy(category = category, pin = source.pin - Pin.Actual))
|
||||
}
|
||||
if (sourceCategoriesFilter && Pin.Actual !in toFlatten[0].pin && source.id in sourcesInSourceCategories) {
|
||||
toFlatten.removeAt(0)
|
||||
}
|
||||
// SY <--
|
||||
toFlatten
|
||||
}
|
||||
repository.getSources(),
|
||||
) { pinnedSourceIds, (enabledLanguages, disabledSources, lastUsedSource), (excludedFromDataSaver, sourcesInCategories, sourceCategoriesFilter), sources ->
|
||||
val duplicatePins = preferences.duplicatePinnedSources().get()
|
||||
val sourcesAndCategories = sourcesInCategories.map {
|
||||
it.split('|').let { (source, test) -> source.toLong() to test }
|
||||
}
|
||||
val sourcesInSourceCategories = sourcesAndCategories.map { it.first }
|
||||
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
|
||||
// SY -->
|
||||
val categories = sourcesAndCategories.filter { (id) -> id == it.id }
|
||||
.map(Pair<*, String>::second)
|
||||
.toSet()
|
||||
// SY <--
|
||||
val source = it.copy(
|
||||
pin = flag,
|
||||
isExcludedFromDataSaver = it.id.toString() in excludedFromDataSaver,
|
||||
categories = categories
|
||||
)
|
||||
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))
|
||||
}
|
||||
// SY -->
|
||||
categories.forEach { category ->
|
||||
toFlatten.add(source.copy(category = category, pin = source.pin - Pin.Actual))
|
||||
}
|
||||
if (sourceCategoriesFilter && Pin.Actual !in toFlatten[0].pin && source.id in sourcesInSourceCategories) {
|
||||
toFlatten.removeAt(0)
|
||||
}
|
||||
// SY <--
|
||||
toFlatten
|
||||
}
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private data class Config(
|
||||
val pinSet: Set<String> = setOf(),
|
||||
val enabledSources: Set<String> = setOf(),
|
||||
val disabledSources: Set<String> = setOf(),
|
||||
val lastUsedSource: Long? = null,
|
||||
// SY -->
|
||||
val excludedFromDataSaver: Set<String> = setOf(),
|
||||
val sourcesInCategories: Set<String> = setOf(),
|
||||
val sourceCategoriesFilter: Boolean = false,
|
||||
// SY <--
|
||||
)
|
||||
|
@ -31,12 +31,12 @@ data class Source(
|
||||
?.asImageBitmap()
|
||||
}
|
||||
|
||||
val key: () -> Long = {
|
||||
val key: () -> String = {
|
||||
when {
|
||||
isUsedLast -> id shr 16
|
||||
Pin.Forced in pin -> id shr 32
|
||||
category != null -> id shr 48 + category.hashCode()
|
||||
else -> id
|
||||
isUsedLast -> "$id-lastused"
|
||||
Pin.Forced in pin -> "$id-forced"
|
||||
category != null -> "$id-$category"
|
||||
else -> "$id"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import androidx.compose.material3.Checkbox
|
||||
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
|
||||
@ -243,7 +244,12 @@ fun SourceItem(
|
||||
}
|
||||
if (item.supportsLatest /* SY --> */ && showLatest /* SY <-- */) {
|
||||
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
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,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 {
|
||||
|
@ -82,7 +82,7 @@ class SourcePresenter(
|
||||
// SY <--
|
||||
}
|
||||
|
||||
private suspend fun collectLatestSources(sources: List<Source>) {
|
||||
private fun collectLatestSources(sources: List<Source>) {
|
||||
val map = TreeMap<String, MutableList<Source>> { d1, d2 ->
|
||||
// Catalogues without a lang defined will be placed at the end
|
||||
when {
|
||||
@ -121,14 +121,14 @@ class SourcePresenter(
|
||||
}
|
||||
|
||||
// SY -->
|
||||
private suspend fun updateCategories(categories: Set<String>) {
|
||||
private fun updateCategories(categories: Set<String>) {
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
sourceCategories = categories.sortedWith(compareByDescending(String.CASE_INSENSITIVE_ORDER) { it })
|
||||
)
|
||||
}
|
||||
}
|
||||
private suspend fun updateShowLatest(showLatest: Boolean) {
|
||||
private fun updateShowLatest(showLatest: Boolean) {
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
showLatest = showLatest
|
||||
|
@ -70,13 +70,12 @@ class SettingsBrowseController : SettingsController() {
|
||||
// SY <--
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,10 +419,10 @@
|
||||
<string name="action_track">Track</string>
|
||||
|
||||
<!-- Browse section -->
|
||||
<string name="pref_duplicate_pinned_sources">Show duplicated pinned sources</string>
|
||||
<string name="pref_duplicate_pinned_sources_summary">Repeat pinned sources in their respective language groups</string>
|
||||
<string name="pref_enable_automatic_extension_updates">Check for extension updates</string>
|
||||
<string name="pref_search_pinned_sources_only">Only include pinned sources</string>
|
||||
<string name="pref_move_on_top">Move pins on top</string>
|
||||
<string name="pref_move_on_top_summary">Move up pins to top of the source list</string>
|
||||
|
||||
<!-- Backup section -->
|
||||
<string name="pref_create_backup">Create backup</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user