mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-27 16:26:29 +03:00
LibrarySettingsSheet: Fix race condition when applying sort mode (#7805)
Also fix sort direction can't be changed for default category
This commit is contained in:
parent
58e6479438
commit
763288ab13
4 changed files with 14 additions and 46 deletions
|
@ -12,24 +12,6 @@ class SetSortModeForCategory(
|
|||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(category: Category, sortDirectionSetting: SortDirectionSetting) {
|
||||
val sort = if (preferences.categorizedDisplaySettings().get()) {
|
||||
SortModeSetting.fromFlag(category.flags)
|
||||
} else {
|
||||
preferences.librarySortingMode().get()
|
||||
}
|
||||
await(category, sort, sortDirectionSetting)
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, sortModeSetting: SortModeSetting) {
|
||||
val direction = if (preferences.categorizedDisplaySettings().get()) {
|
||||
SortDirectionSetting.fromFlag(category.flags)
|
||||
} else {
|
||||
preferences.librarySortingAscending().get()
|
||||
}
|
||||
await(category, sortModeSetting, direction)
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, sortModeSetting: SortModeSetting, sortDirectionSetting: SortDirectionSetting) {
|
||||
var flags = category.flags and SortModeSetting.MASK.inv() or (sortModeSetting.flag and SortModeSetting.MASK)
|
||||
flags = flags and SortDirectionSetting.MASK.inv() or (sortDirectionSetting.flag and SortDirectionSetting.MASK)
|
||||
|
|
|
@ -338,7 +338,7 @@ class LibraryPresenter(
|
|||
}
|
||||
|
||||
val sortDirections = categories.associate { category ->
|
||||
category.id to SortDirectionSetting.get(preferences, category)
|
||||
category.id to SortDirectionSetting.get(category)
|
||||
}
|
||||
|
||||
val locale = Locale.getDefault()
|
||||
|
|
|
@ -203,7 +203,7 @@ class LibrarySettingsSheet(
|
|||
|
||||
override fun initModels() {
|
||||
val sorting = SortModeSetting.get(preferences, currentCategory)
|
||||
val order = if (SortDirectionSetting.get(preferences, currentCategory) == SortDirectionSetting.ASCENDING) {
|
||||
val order = if (SortDirectionSetting.get(currentCategory) == SortDirectionSetting.ASCENDING) {
|
||||
Item.MultiSort.SORT_ASC
|
||||
} else {
|
||||
Item.MultiSort.SORT_DESC
|
||||
|
@ -242,27 +242,13 @@ class LibrarySettingsSheet(
|
|||
else -> throw Exception("Unknown state")
|
||||
}
|
||||
|
||||
setSortModePreference(item)
|
||||
|
||||
setSortDirectionPreference(item)
|
||||
setSortPreference(item)
|
||||
|
||||
item.group.items.forEach { adapter.notifyItemChanged(it) }
|
||||
}
|
||||
|
||||
private fun setSortDirectionPreference(item: Item.MultiStateGroup) {
|
||||
val flag = if (item.state == Item.MultiSort.SORT_ASC) {
|
||||
SortDirectionSetting.ASCENDING
|
||||
} else {
|
||||
SortDirectionSetting.DESCENDING
|
||||
}
|
||||
|
||||
sheetScope.launchIO {
|
||||
setSortModeForCategory.await(currentCategory!!, flag)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setSortModePreference(item: Item) {
|
||||
val flag = when (item) {
|
||||
private fun setSortPreference(item: Item.MultiStateGroup) {
|
||||
val mode = when (item) {
|
||||
alphabetically -> SortModeSetting.ALPHABETICAL
|
||||
lastRead -> SortModeSetting.LAST_READ
|
||||
lastChecked -> SortModeSetting.LAST_MANGA_UPDATE
|
||||
|
@ -273,9 +259,14 @@ class LibrarySettingsSheet(
|
|||
dateAdded -> SortModeSetting.DATE_ADDED
|
||||
else -> throw NotImplementedError("Unknown display mode")
|
||||
}
|
||||
val direction = if (item.state == Item.MultiSort.SORT_ASC) {
|
||||
SortDirectionSetting.ASCENDING
|
||||
} else {
|
||||
SortDirectionSetting.DESCENDING
|
||||
}
|
||||
|
||||
sheetScope.launchIO {
|
||||
setSortModeForCategory.await(currentCategory!!, flag)
|
||||
setSortModeForCategory.await(currentCategory!!, mode, direction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package eu.kanade.tachiyomi.ui.library.setting
|
||||
|
||||
import eu.kanade.domain.category.model.Category
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
||||
enum class SortDirectionSetting(val flag: Long) {
|
||||
ASCENDING(0b01000000),
|
||||
|
@ -10,16 +9,12 @@ enum class SortDirectionSetting(val flag: Long) {
|
|||
companion object {
|
||||
const val MASK = 0b01000000L
|
||||
|
||||
fun fromFlag(flag: Long?): SortDirectionSetting {
|
||||
private fun fromFlag(flag: Long?): SortDirectionSetting {
|
||||
return values().find { mode -> mode.flag == flag } ?: ASCENDING
|
||||
}
|
||||
|
||||
fun get(preferences: PreferencesHelper, category: Category?): SortDirectionSetting {
|
||||
return if (preferences.categorizedDisplaySettings().get() && category != null && category.id != 0L) {
|
||||
fromFlag(category.sortDirection)
|
||||
} else {
|
||||
preferences.librarySortingAscending().get()
|
||||
}
|
||||
fun get(category: Category?): SortDirectionSetting {
|
||||
return fromFlag(category?.sortDirection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue