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.
This commit is contained in:
arkon
2023-06-04 16:59:21 -04:00
parent 39e4568460
commit 405a75438a
14 changed files with 50 additions and 90 deletions

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -1,34 +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.plus
import tachiyomi.domain.library.service.LibraryPreferences
class SetDisplayModeForCategory(
private val preferences: LibraryPreferences,
private val categoryRepository: CategoryRepository,
) {
suspend fun await(categoryId: Long, display: LibraryDisplayMode) {
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)
}
}

View File

@@ -12,10 +12,10 @@ class SetSortModeForCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(categoryId: Long, type: LibrarySort.Type, direction: LibrarySort.Direction) {
val category = categoryRepository.get(categoryId) ?: return
val flags = category.flags + type + direction
if (preferences.categorizedDisplaySettings().get()) {
suspend fun await(categoryId: Long?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
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,
@@ -28,7 +28,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)
}
}

View File

@@ -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)