Fix language in source filter list jumping to top incorrectly
Fixes #9068
This commit is contained in:
parent
14c465d36f
commit
f5ad95d78a
4 changed files with 28 additions and 20 deletions
|
@ -6,13 +6,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(),
|
||||||
|
@ -23,7 +24,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),
|
||||||
)
|
)
|
||||||
|
|
|
@ -64,7 +64,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(
|
||||||
|
@ -74,18 +74,19 @@ private fun SourcesFilterContent(
|
||||||
onClickItem = onClickLanguage,
|
onClickItem = onClickLanguage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!enabled) return@forEach
|
if (enabled) {
|
||||||
items(
|
items(
|
||||||
items = sources,
|
items = sources,
|
||||||
key = { "source-filter-${it.key()}" },
|
key = { "source-filter-${it.key()}" },
|
||||||
contentType = { "source-filter-item" },
|
contentType = { "source-filter-item" },
|
||||||
) { source ->
|
) { source ->
|
||||||
SourcesFilterItem(
|
SourcesFilterItem(
|
||||||
modifier = Modifier.animateItemPlacement(),
|
modifier = Modifier.animateItemPlacement(),
|
||||||
source = source,
|
source = source,
|
||||||
enabled = "${source.id}" !in state.disabledSources,
|
enabled = "${source.id}" !in state.disabledSources,
|
||||||
onClickItem = onClickSource,
|
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(),
|
||||||
|
@ -66,7 +67,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.
|
||||||
|
|
Reference in a new issue