Minor cleanup 2: Electric Boogaloo
- Reword pins on top setting - Make "Latest" button style match old UI - Sort sources by name
This commit is contained in:
parent
0ec9496d26
commit
08e63e5fab
@ -12,46 +12,36 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
|||||||
|
|
||||||
class GetEnabledSources(
|
class GetEnabledSources(
|
||||||
private val repository: SourceRepository,
|
private val repository: SourceRepository,
|
||||||
private val preferences: PreferencesHelper
|
private val preferences: PreferencesHelper,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun subscribe(): Flow<List<Source>> {
|
fun subscribe(): Flow<List<Source>> {
|
||||||
return preferences.pinnedSources().asFlow()
|
return combine(
|
||||||
.combine(preferences.enabledLanguages().asFlow()) { pinList, enabledLanguages ->
|
preferences.pinnedSources().asFlow(),
|
||||||
Config(pinSet = pinList, enabledSources = enabledLanguages)
|
preferences.enabledLanguages().asFlow(),
|
||||||
}
|
preferences.disabledSources().asFlow(),
|
||||||
.combine(preferences.disabledSources().asFlow()) { config, disabledSources ->
|
preferences.lastUsedSource().asFlow(),
|
||||||
config.copy(disabledSources = disabledSources)
|
repository.getSources(),
|
||||||
}
|
) { pinnedSourceIds, enabledLanguages, disabledSources, lastUsedSource, sources ->
|
||||||
.combine(preferences.lastUsedSource().asFlow()) { config, lastUsedSource ->
|
val duplicatePins = preferences.duplicatePinnedSources().get()
|
||||||
config.copy(lastUsedSource = lastUsedSource)
|
sources
|
||||||
}
|
.filter { it.lang in enabledLanguages || it.id == LocalSource.ID }
|
||||||
.combine(repository.getSources()) { (pinList, enabledLanguages, disabledSources, lastUsedSource), sources ->
|
.filterNot { it.id.toString() in disabledSources }
|
||||||
val pinsOnTop = preferences.pinsOnTop().get()
|
.sortedBy { it.name }
|
||||||
sources
|
.flatMap {
|
||||||
.filter { it.lang in enabledLanguages || it.id == LocalSource.ID }
|
val flag = if ("${it.id}" in pinnedSourceIds) Pins.pinned else Pins.unpinned
|
||||||
.filterNot { it.id.toString() in disabledSources }
|
val source = it.copy(pin = flag)
|
||||||
.flatMap {
|
val toFlatten = mutableListOf(source)
|
||||||
val flag = if ("${it.id}" in pinList) Pins.pinned else Pins.unpinned
|
if (source.id == lastUsedSource) {
|
||||||
val source = it.copy(pin = flag)
|
toFlatten.add(source.copy(isUsedLast = true, pin = source.pin - Pin.Actual))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
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()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class Config(
|
|
||||||
val pinSet: Set<String> = setOf(),
|
|
||||||
val enabledSources: Set<String> = setOf(),
|
|
||||||
val disabledSources: Set<String> = setOf(),
|
|
||||||
val lastUsedSource: Long? = null
|
|
||||||
)
|
|
||||||
|
@ -26,11 +26,11 @@ data class Source(
|
|||||||
?.asImageBitmap()
|
?.asImageBitmap()
|
||||||
}
|
}
|
||||||
|
|
||||||
val key: () -> Long = {
|
val key: () -> String = {
|
||||||
when {
|
when {
|
||||||
isUsedLast -> id shr 16
|
isUsedLast -> "$id-lastused"
|
||||||
Pin.Forced in pin -> id shr 32
|
Pin.Forced in pin -> "$id-forced"
|
||||||
else -> id
|
else -> "$id"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import androidx.compose.material3.AlertDialog
|
|||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@ -195,7 +196,12 @@ fun SourceItem(
|
|||||||
}
|
}
|
||||||
if (item.supportsLatest) {
|
if (item.supportsLatest) {
|
||||||
TextButton(onClick = { onClickLatest(item) }) {
|
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(
|
SourcePinButton(
|
||||||
|
@ -324,7 +324,7 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun autoClearChapterCache() = prefs.getBoolean(Keys.autoClearChapterCache, false)
|
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) {
|
fun setChapterSettingsDefault(manga: Manga) {
|
||||||
prefs.edit {
|
prefs.edit {
|
||||||
|
@ -44,7 +44,7 @@ class SourcePresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun collectLatestSources(sources: List<Source>) {
|
private fun collectLatestSources(sources: List<Source>) {
|
||||||
val map = TreeMap<String, MutableList<Source>> { d1, d2 ->
|
val map = TreeMap<String, MutableList<Source>> { d1, d2 ->
|
||||||
// Catalogues without a lang defined will be placed at the end
|
// Catalogues without a lang defined will be placed at the end
|
||||||
when {
|
when {
|
||||||
|
@ -22,13 +22,12 @@ class SettingsBrowseController : SettingsController() {
|
|||||||
titleRes = R.string.browse
|
titleRes = R.string.browse
|
||||||
|
|
||||||
preferenceCategory {
|
preferenceCategory {
|
||||||
titleRes = R.string.pref_category_general
|
titleRes = R.string.label_sources
|
||||||
|
|
||||||
switchPreference {
|
switchPreference {
|
||||||
bindTo(preferences.pinsOnTop())
|
bindTo(preferences.duplicatePinnedSources())
|
||||||
titleRes = R.string.pref_move_on_top
|
titleRes = R.string.pref_duplicate_pinned_sources
|
||||||
summaryRes = R.string.pref_move_on_top_summary
|
summaryRes = R.string.pref_duplicate_pinned_sources_summary
|
||||||
defaultValue = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,10 +419,10 @@
|
|||||||
<string name="action_track">Track</string>
|
<string name="action_track">Track</string>
|
||||||
|
|
||||||
<!-- Browse section -->
|
<!-- 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_enable_automatic_extension_updates">Check for extension updates</string>
|
||||||
<string name="pref_search_pinned_sources_only">Only include pinned sources</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 -->
|
<!-- Backup section -->
|
||||||
<string name="pref_create_backup">Create backup</string>
|
<string name="pref_create_backup">Create backup</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user