Fix language in source filter list jumping to top incorrectly
Fixes #9068 (cherry picked from commit f5ad95d78a857c226d53e010e52e8563ecd38f0d) # Conflicts: # app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt
This commit is contained in:
parent
4baa396aa6
commit
18f65d4ca4
@ -7,13 +7,14 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import tachiyomi.domain.source.model.Source
|
import tachiyomi.domain.source.model.Source
|
||||||
import tachiyomi.domain.source.repository.SourceRepository
|
import tachiyomi.domain.source.repository.SourceRepository
|
||||||
|
import java.util.SortedMap
|
||||||
|
|
||||||
class GetLanguagesWithSources(
|
class GetLanguagesWithSources(
|
||||||
private val repository: SourceRepository,
|
private val repository: SourceRepository,
|
||||||
private val preferences: SourcePreferences,
|
private val preferences: SourcePreferences,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun subscribe(): Flow<Map<String, List<Source>>> {
|
fun subscribe(): Flow<SortedMap<String, List<Source>>> {
|
||||||
return combine(
|
return combine(
|
||||||
preferences.enabledLanguages().changes(),
|
preferences.enabledLanguages().changes(),
|
||||||
preferences.disabledSources().changes(),
|
preferences.disabledSources().changes(),
|
||||||
@ -24,7 +25,8 @@ class GetLanguagesWithSources(
|
|||||||
.thenBy(String.CASE_INSENSITIVE_ORDER) { it.name },
|
.thenBy(String.CASE_INSENSITIVE_ORDER) { it.name },
|
||||||
)
|
)
|
||||||
|
|
||||||
sortedSources.groupBy { it.lang }
|
sortedSources
|
||||||
|
.groupBy { it.lang }
|
||||||
.toSortedMap(
|
.toSortedMap(
|
||||||
compareBy<String> { it !in enabledLanguage }.then(LocaleHelper.comparator),
|
compareBy<String> { it !in enabledLanguage }.then(LocaleHelper.comparator),
|
||||||
)
|
)
|
||||||
|
@ -74,7 +74,7 @@ private fun SourcesFilterContent(
|
|||||||
state.items.forEach { (language, sources) ->
|
state.items.forEach { (language, sources) ->
|
||||||
val enabled = language in state.enabledLanguages
|
val enabled = language in state.enabledLanguages
|
||||||
item(
|
item(
|
||||||
key = language.hashCode(),
|
key = language,
|
||||||
contentType = "source-filter-header",
|
contentType = "source-filter-header",
|
||||||
) {
|
) {
|
||||||
SourcesFilterHeader(
|
SourcesFilterHeader(
|
||||||
@ -84,35 +84,36 @@ private fun SourcesFilterContent(
|
|||||||
onClickItem = onClickLanguage,
|
onClickItem = onClickLanguage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!enabled) return@forEach
|
if (enabled) {
|
||||||
// SY -->
|
// SY -->
|
||||||
item(
|
item(
|
||||||
key = "toggle-$language",
|
key = "toggle-$language",
|
||||||
contentType = "source-filter-toggle",
|
contentType = "source-filter-toggle",
|
||||||
) {
|
) {
|
||||||
val toggleEnabled = remember(state.disabledSources) {
|
val toggleEnabled = remember(state.disabledSources) {
|
||||||
sources.none { it.id.toString() in state.disabledSources }
|
sources.none { it.id.toString() in state.disabledSources }
|
||||||
|
}
|
||||||
|
SourcesFilterToggle(
|
||||||
|
modifier = Modifier.animateItemPlacement(),
|
||||||
|
isEnabled = toggleEnabled,
|
||||||
|
onClickItem = {
|
||||||
|
onClickSources(!toggleEnabled, sources)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// SY <--
|
||||||
|
items(
|
||||||
|
items = sources,
|
||||||
|
key = { "source-filter-${it.key()}" },
|
||||||
|
contentType = { "source-filter-item" },
|
||||||
|
) { source ->
|
||||||
|
SourcesFilterItem(
|
||||||
|
modifier = Modifier.animateItemPlacement(),
|
||||||
|
source = source,
|
||||||
|
enabled = "${source.id}" !in state.disabledSources,
|
||||||
|
onClickItem = onClickSource,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
SourcesFilterToggle(
|
|
||||||
modifier = Modifier.animateItemPlacement(),
|
|
||||||
isEnabled = toggleEnabled,
|
|
||||||
onClickItem = {
|
|
||||||
onClickSources(!toggleEnabled, sources)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// SY <--
|
|
||||||
items(
|
|
||||||
items = sources,
|
|
||||||
key = { "source-filter-${it.key()}" },
|
|
||||||
contentType = { "source-filter-item" },
|
|
||||||
) { source ->
|
|
||||||
SourcesFilterItem(
|
|
||||||
modifier = Modifier.animateItemPlacement(),
|
|
||||||
source = source,
|
|
||||||
enabled = "${source.id}" !in state.disabledSources,
|
|
||||||
onClickItem = onClickSource,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import kotlinx.coroutines.launch
|
|||||||
import tachiyomi.domain.source.model.Source
|
import tachiyomi.domain.source.model.Source
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import java.util.SortedMap
|
||||||
|
|
||||||
class SourcesFilterScreenModel(
|
class SourcesFilterScreenModel(
|
||||||
private val preferences: SourcePreferences = Injekt.get(),
|
private val preferences: SourcePreferences = Injekt.get(),
|
||||||
@ -72,7 +73,7 @@ sealed class SourcesFilterState {
|
|||||||
) : SourcesFilterState()
|
) : SourcesFilterState()
|
||||||
|
|
||||||
data class Success(
|
data class Success(
|
||||||
val items: Map<String, List<Source>>,
|
val items: SortedMap<String, List<Source>>,
|
||||||
val enabledLanguages: Set<String>,
|
val enabledLanguages: Set<String>,
|
||||||
val disabledSources: Set<String>,
|
val disabledSources: Set<String>,
|
||||||
) : SourcesFilterState() {
|
) : SourcesFilterState() {
|
||||||
|
@ -11,10 +11,14 @@ import java.util.Locale
|
|||||||
*/
|
*/
|
||||||
object LocaleHelper {
|
object LocaleHelper {
|
||||||
|
|
||||||
val comparator = compareBy<String>(
|
/**
|
||||||
{ getDisplayName(it) },
|
* Sorts by display name, except keeps the "all" (displayed as "Multi") locale at the top.
|
||||||
{ it == "all" },
|
*/
|
||||||
)
|
val comparator = { a: String, b: String ->
|
||||||
|
if (a == "all") -1
|
||||||
|
else if (b == "all") 1
|
||||||
|
else getDisplayName(a).compareTo(getDisplayName(b))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns display name of a string language code.
|
* Returns display name of a string language code.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user