Remove per-category display mode
There seems to be little value in this feature, and juggling flag masks is annoying. Per-category sorting is still a thing, but could be refactored away from the flag in the feature. (cherry picked from commit 405a75438a61770a12292cc87c0fa36e16668124) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt # domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt # domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt
This commit is contained in:
@@ -15,9 +15,7 @@ class CreateCategoryWithName(
|
||||
private val initialFlags: Long
|
||||
get() {
|
||||
val sort = preferences.librarySortingMode().get()
|
||||
return preferences.libraryDisplayMode().get().flag or
|
||||
sort.type.flag or
|
||||
sort.direction.flag
|
||||
return sort.type.flag or sort.direction.flag
|
||||
}
|
||||
|
||||
suspend fun await(name: String): Result = withNonCancellableContext {
|
||||
|
||||
@@ -10,8 +10,7 @@ class ResetCategoryFlags(
|
||||
) {
|
||||
|
||||
suspend fun await() {
|
||||
val display = preferences.libraryDisplayMode().get()
|
||||
val sort = preferences.librarySortingMode().get()
|
||||
categoryRepository.updateAllFlags(display + sort.type + sort.direction)
|
||||
categoryRepository.updateAllFlags(sort.type + sort.direction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class SetDisplayMode(
|
||||
private val preferences: LibraryPreferences,
|
||||
) {
|
||||
|
||||
fun await(display: LibraryDisplayMode) {
|
||||
preferences.libraryDisplayMode().set(display)
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package tachiyomi.domain.category.interactor
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
import tachiyomi.domain.category.model.CategoryUpdate
|
||||
import tachiyomi.domain.category.repository.CategoryRepository
|
||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||
import tachiyomi.domain.library.model.LibraryGroup
|
||||
import tachiyomi.domain.library.model.plus
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
|
||||
class SetDisplayModeForCategory(
|
||||
private val preferences: LibraryPreferences,
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(categoryId: Long, display: LibraryDisplayMode) {
|
||||
// SY -->
|
||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
||||
preferences.libraryDisplayMode().set(display)
|
||||
return
|
||||
}
|
||||
// SY <--
|
||||
val category = categoryRepository.get(categoryId) ?: return
|
||||
val flags = category.flags + display
|
||||
if (preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
id = category.id,
|
||||
flags = flags,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
preferences.libraryDisplayMode().set(display)
|
||||
categoryRepository.updateAllFlags(flags)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, display: LibraryDisplayMode) {
|
||||
await(category.id, display)
|
||||
}
|
||||
}
|
||||
@@ -13,16 +13,16 @@ class SetSortModeForCategory(
|
||||
private val categoryRepository: CategoryRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(categoryId: Long, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
// SY -->
|
||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
||||
preferences.librarySortingMode().set(LibrarySort(type, direction))
|
||||
return
|
||||
}
|
||||
// SY <--
|
||||
val category = categoryRepository.get(categoryId) ?: return
|
||||
val flags = category.flags + type + direction
|
||||
if (preferences.categorizedDisplaySettings().get()) {
|
||||
val category = categoryId?.let { categoryRepository.get(it) }
|
||||
val flags = (category?.flags ?: 0) + type + direction
|
||||
if (category != null && preferences.categorizedDisplaySettings().get()) {
|
||||
categoryRepository.updatePartial(
|
||||
CategoryUpdate(
|
||||
id = category.id,
|
||||
@@ -35,7 +35,7 @@ class SetSortModeForCategory(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun await(category: Category, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
await(category.id, type, direction)
|
||||
suspend fun await(category: Category?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
|
||||
await(category?.id, type, direction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
package tachiyomi.domain.library.model
|
||||
|
||||
import tachiyomi.domain.category.model.Category
|
||||
sealed class LibraryDisplayMode {
|
||||
|
||||
sealed class LibraryDisplayMode(
|
||||
override val flag: Long,
|
||||
) : FlagWithMask {
|
||||
|
||||
override val mask: Long = 0b00000011L
|
||||
|
||||
object CompactGrid : LibraryDisplayMode(0b00000000)
|
||||
object ComfortableGrid : LibraryDisplayMode(0b00000001)
|
||||
object List : LibraryDisplayMode(0b00000010)
|
||||
object CoverOnlyGrid : LibraryDisplayMode(0b00000011)
|
||||
object CompactGrid : LibraryDisplayMode()
|
||||
object ComfortableGrid : LibraryDisplayMode()
|
||||
object List : LibraryDisplayMode()
|
||||
object CoverOnlyGrid : LibraryDisplayMode()
|
||||
|
||||
object Serializer {
|
||||
fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
@@ -27,13 +21,6 @@ sealed class LibraryDisplayMode(
|
||||
val values by lazy { setOf(CompactGrid, ComfortableGrid, List, CoverOnlyGrid) }
|
||||
val default = CompactGrid
|
||||
|
||||
fun valueOf(flag: Long?): LibraryDisplayMode {
|
||||
if (flag == null) return default
|
||||
return values
|
||||
.find { mode -> mode.flag == flag and mode.mask }
|
||||
?: default
|
||||
}
|
||||
|
||||
fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
return when (serialized) {
|
||||
"COMFORTABLE_GRID" -> ComfortableGrid
|
||||
@@ -54,6 +41,3 @@ sealed class LibraryDisplayMode(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Category?.display: LibraryDisplayMode
|
||||
get() = LibraryDisplayMode.valueOf(this?.flags)
|
||||
|
||||
Reference in New Issue
Block a user