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

@ -31,7 +31,7 @@ import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.category.interactor.RenameCategory import tachiyomi.domain.category.interactor.RenameCategory
import tachiyomi.domain.category.interactor.ReorderCategory import tachiyomi.domain.category.interactor.ReorderCategory
import tachiyomi.domain.category.interactor.ResetCategoryFlags import tachiyomi.domain.category.interactor.ResetCategoryFlags
import tachiyomi.domain.category.interactor.SetDisplayModeForCategory import tachiyomi.domain.category.interactor.SetDisplayMode
import tachiyomi.domain.category.interactor.SetMangaCategories import tachiyomi.domain.category.interactor.SetMangaCategories
import tachiyomi.domain.category.interactor.SetSortModeForCategory import tachiyomi.domain.category.interactor.SetSortModeForCategory
import tachiyomi.domain.category.interactor.UpdateCategory import tachiyomi.domain.category.interactor.UpdateCategory
@ -82,7 +82,7 @@ class DomainModule : InjektModule {
addSingletonFactory<CategoryRepository> { CategoryRepositoryImpl(get()) } addSingletonFactory<CategoryRepository> { CategoryRepositoryImpl(get()) }
addFactory { GetCategories(get()) } addFactory { GetCategories(get()) }
addFactory { ResetCategoryFlags(get(), get()) } addFactory { ResetCategoryFlags(get(), get()) }
addFactory { SetDisplayModeForCategory(get(), get()) } addFactory { SetDisplayMode(get()) }
addFactory { SetSortModeForCategory(get(), get()) } addFactory { SetSortModeForCategory(get(), get()) }
addFactory { CreateCategoryWithName(get(), get()) } addFactory { CreateCategoryWithName(get(), get()) }
addFactory { RenameCategory(get()) } addFactory { RenameCategory(get()) }

View File

@ -29,7 +29,6 @@ import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel
import tachiyomi.domain.category.model.Category import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibrarySort import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.display
import tachiyomi.domain.library.model.sort import tachiyomi.domain.library.model.sort
import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.model.TriStateFilter import tachiyomi.domain.manga.model.TriStateFilter
@ -43,7 +42,7 @@ import tachiyomi.presentation.core.components.SortItem
fun LibrarySettingsDialog( fun LibrarySettingsDialog(
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
screenModel: LibrarySettingsScreenModel, screenModel: LibrarySettingsScreenModel,
category: Category, category: Category?,
) { ) {
TabbedDialog( TabbedDialog(
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
@ -67,7 +66,6 @@ fun LibrarySettingsDialog(
screenModel = screenModel, screenModel = screenModel,
) )
2 -> DisplayPage( 2 -> DisplayPage(
category = category,
screenModel = screenModel, screenModel = screenModel,
) )
} }
@ -146,7 +144,7 @@ private fun ColumnScope.FilterPage(
@Composable @Composable
private fun ColumnScope.SortPage( private fun ColumnScope.SortPage(
category: Category, category: Category?,
screenModel: LibrarySettingsScreenModel, screenModel: LibrarySettingsScreenModel,
) { ) {
val sortingMode = category.sort.type val sortingMode = category.sort.type
@ -179,10 +177,10 @@ private fun ColumnScope.SortPage(
@Composable @Composable
private fun ColumnScope.DisplayPage( private fun ColumnScope.DisplayPage(
category: Category,
screenModel: LibrarySettingsScreenModel, screenModel: LibrarySettingsScreenModel,
) { ) {
HeadingItem(R.string.action_display_mode) HeadingItem(R.string.action_display_mode)
val displayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState()
listOf( listOf(
R.string.action_display_grid to LibraryDisplayMode.CompactGrid, R.string.action_display_grid to LibraryDisplayMode.CompactGrid,
R.string.action_display_comfortable_grid to LibraryDisplayMode.ComfortableGrid, R.string.action_display_comfortable_grid to LibraryDisplayMode.ComfortableGrid,
@ -191,12 +189,12 @@ private fun ColumnScope.DisplayPage(
).map { (titleRes, mode) -> ).map { (titleRes, mode) ->
RadioItem( RadioItem(
label = stringResource(titleRes), label = stringResource(titleRes),
selected = category.display == mode, selected = displayMode == mode,
onClick = { screenModel.setDisplayMode(category, mode) }, onClick = { screenModel.setDisplayMode(mode) },
) )
} }
if (category.display != LibraryDisplayMode.List) { if (displayMode != LibraryDisplayMode.List) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()

View File

@ -42,7 +42,7 @@ fun LibraryContent(
onRefresh: (Category?) -> Boolean, onRefresh: (Category?) -> Boolean,
onGlobalSearchClicked: () -> Unit, onGlobalSearchClicked: () -> Unit,
getNumberOfMangaForCategory: (Category) -> Int?, getNumberOfMangaForCategory: (Category) -> Int?,
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, getDisplayMode: (Int) -> PreferenceMutableState<LibraryDisplayMode>,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>, getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: (Int) -> List<LibraryItem>, getLibraryForPage: (Int) -> List<LibraryItem>,
) { ) {
@ -102,7 +102,7 @@ fun LibraryContent(
selectedManga = selection, selectedManga = selection,
searchQuery = searchQuery, searchQuery = searchQuery,
onGlobalSearchClicked = onGlobalSearchClicked, onGlobalSearchClicked = onGlobalSearchClicked,
getDisplayModeForPage = getDisplayModeForPage, getDisplayMode = getDisplayMode,
getColumnsForOrientation = getColumnsForOrientation, getColumnsForOrientation = getColumnsForOrientation,
getLibraryForPage = getLibraryForPage, getLibraryForPage = getLibraryForPage,
onClickManga = onClickManga, onClickManga = onClickManga,

View File

@ -34,7 +34,7 @@ fun LibraryPager(
selectedManga: List<LibraryManga>, selectedManga: List<LibraryManga>,
searchQuery: String?, searchQuery: String?,
onGlobalSearchClicked: () -> Unit, onGlobalSearchClicked: () -> Unit,
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, getDisplayMode: (Int) -> PreferenceMutableState<LibraryDisplayMode>,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>, getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: (Int) -> List<LibraryItem>, getLibraryForPage: (Int) -> List<LibraryItem>,
onClickManga: (LibraryManga) -> Unit, onClickManga: (LibraryManga) -> Unit,
@ -62,7 +62,7 @@ fun LibraryPager(
return@HorizontalPager return@HorizontalPager
} }
val displayMode = getDisplayModeForPage(page) val displayMode by getDisplayMode(page)
val columns by if (displayMode != LibraryDisplayMode.List) { val columns by if (displayMode != LibraryDisplayMode.List) {
val configuration = LocalConfiguration.current val configuration = LocalConfiguration.current
val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE

View File

@ -49,6 +49,7 @@ import tachiyomi.domain.category.model.Category
import tachiyomi.domain.chapter.interactor.GetChapterByMangaId import tachiyomi.domain.chapter.interactor.GetChapterByMangaId
import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.history.interactor.GetNextChapters import tachiyomi.domain.history.interactor.GetNextChapters
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.library.model.LibrarySort import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.model.sort import tachiyomi.domain.library.model.sort
@ -517,6 +518,10 @@ class LibraryScreenModel(
} }
} }
fun getDisplayMode(): PreferenceMutableState<LibraryDisplayMode> {
return libraryPreferences.libraryDisplayMode().asState(coroutineScope)
}
fun getColumnsPreferenceForCurrentOrientation(isLandscape: Boolean): PreferenceMutableState<Int> { fun getColumnsPreferenceForCurrentOrientation(isLandscape: Boolean): PreferenceMutableState<Int> {
return (if (isLandscape) libraryPreferences.landscapeColumns() else libraryPreferences.portraitColumns()).asState(coroutineScope) return (if (isLandscape) libraryPreferences.landscapeColumns() else libraryPreferences.portraitColumns()).asState(coroutineScope)
} }

View File

@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.util.preference.toggle
import tachiyomi.core.preference.Preference import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.getAndSet import tachiyomi.core.preference.getAndSet
import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.interactor.SetDisplayModeForCategory import tachiyomi.domain.category.interactor.SetDisplayMode
import tachiyomi.domain.category.interactor.SetSortModeForCategory import tachiyomi.domain.category.interactor.SetSortModeForCategory
import tachiyomi.domain.category.model.Category import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibraryDisplayMode
@ -21,7 +21,7 @@ import uy.kohesive.injekt.api.get
class LibrarySettingsScreenModel( class LibrarySettingsScreenModel(
val preferences: BasePreferences = Injekt.get(), val preferences: BasePreferences = Injekt.get(),
val libraryPreferences: LibraryPreferences = Injekt.get(), val libraryPreferences: LibraryPreferences = Injekt.get(),
private val setDisplayModeForCategory: SetDisplayModeForCategory = Injekt.get(), private val setDisplayMode: SetDisplayMode = Injekt.get(),
private val setSortModeForCategory: SetSortModeForCategory = Injekt.get(), private val setSortModeForCategory: SetSortModeForCategory = Injekt.get(),
private val trackManager: TrackManager = Injekt.get(), private val trackManager: TrackManager = Injekt.get(),
) : ScreenModel { ) : ScreenModel {
@ -43,13 +43,11 @@ class LibrarySettingsScreenModel(
toggleFilter { libraryPreferences.filterTracking(id) } toggleFilter { libraryPreferences.filterTracking(id) }
} }
fun setDisplayMode(category: Category, mode: LibraryDisplayMode) { fun setDisplayMode(mode: LibraryDisplayMode) {
coroutineScope.launchIO { setDisplayMode.await(mode)
setDisplayModeForCategory.await(category, mode)
}
} }
fun setSort(category: Category, mode: LibrarySort.Type, direction: LibrarySort.Direction) { fun setSort(category: Category?, mode: LibrarySort.Type, direction: LibrarySort.Direction) {
coroutineScope.launchIO { coroutineScope.launchIO {
setSortModeForCategory.await(category, mode, direction) setSortModeForCategory.await(category, mode, direction)
} }

View File

@ -50,7 +50,6 @@ import kotlinx.coroutines.launch
import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.model.Category import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.library.model.LibraryManga
import tachiyomi.domain.library.model.display
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.screens.EmptyScreen import tachiyomi.presentation.core.screens.EmptyScreen
@ -196,7 +195,7 @@ object LibraryTab : Tab {
navigator.push(GlobalSearchScreen(screenModel.state.value.searchQuery ?: "")) navigator.push(GlobalSearchScreen(screenModel.state.value.searchQuery ?: ""))
}, },
getNumberOfMangaForCategory = { state.getMangaCountForCategory(it) }, getNumberOfMangaForCategory = { state.getMangaCountForCategory(it) },
getDisplayModeForPage = { state.categories[it].display }, getDisplayMode = { screenModel.getDisplayMode() },
getColumnsForOrientation = { screenModel.getColumnsPreferenceForCurrentOrientation(it) }, getColumnsForOrientation = { screenModel.getColumnsPreferenceForCurrentOrientation(it) },
) { state.getLibraryItemsByPage(it) } ) { state.getLibraryItemsByPage(it) }
} }

View File

@ -15,9 +15,7 @@ class CreateCategoryWithName(
private val initialFlags: Long private val initialFlags: Long
get() { get() {
val sort = preferences.librarySortingMode().get() val sort = preferences.librarySortingMode().get()
return preferences.libraryDisplayMode().get().flag or return sort.type.flag or sort.direction.flag
sort.type.flag or
sort.direction.flag
} }
suspend fun await(name: String): Result = withNonCancellableContext { suspend fun await(name: String): Result = withNonCancellableContext {

View File

@ -10,8 +10,7 @@ class ResetCategoryFlags(
) { ) {
suspend fun await() { suspend fun await() {
val display = preferences.libraryDisplayMode().get()
val sort = preferences.librarySortingMode().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, 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) {
val category = categoryRepository.get(categoryId) ?: return val category = categoryId?.let { categoryRepository.get(it) }
val flags = category.flags + type + direction val flags = (category?.flags ?: 0) + type + direction
if (preferences.categorizedDisplaySettings().get()) { if (category != null && preferences.categorizedDisplaySettings().get()) {
categoryRepository.updatePartial( categoryRepository.updatePartial(
CategoryUpdate( CategoryUpdate(
id = category.id, id = category.id,
@ -28,7 +28,7 @@ class SetSortModeForCategory(
} }
} }
suspend fun await(category: Category, type: LibrarySort.Type, direction: LibrarySort.Direction) { suspend fun await(category: Category?, type: LibrarySort.Type, direction: LibrarySort.Direction) {
await(category.id, type, direction) await(category?.id, type, direction)
} }
} }

View File

@ -1,17 +1,11 @@
package tachiyomi.domain.library.model package tachiyomi.domain.library.model
import tachiyomi.domain.category.model.Category sealed class LibraryDisplayMode {
sealed class LibraryDisplayMode( object CompactGrid : LibraryDisplayMode()
override val flag: Long, object ComfortableGrid : LibraryDisplayMode()
) : FlagWithMask { object List : LibraryDisplayMode()
object CoverOnlyGrid : LibraryDisplayMode()
override val mask: Long = 0b00000011L
object CompactGrid : LibraryDisplayMode(0b00000000)
object ComfortableGrid : LibraryDisplayMode(0b00000001)
object List : LibraryDisplayMode(0b00000010)
object CoverOnlyGrid : LibraryDisplayMode(0b00000011)
object Serializer { object Serializer {
fun deserialize(serialized: String): LibraryDisplayMode { fun deserialize(serialized: String): LibraryDisplayMode {
@ -27,13 +21,6 @@ sealed class LibraryDisplayMode(
val values by lazy { setOf(CompactGrid, ComfortableGrid, List, CoverOnlyGrid) } val values by lazy { setOf(CompactGrid, ComfortableGrid, List, CoverOnlyGrid) }
val default = CompactGrid 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 { fun deserialize(serialized: String): LibraryDisplayMode {
return when (serialized) { return when (serialized) {
"COMFORTABLE_GRID" -> ComfortableGrid "COMFORTABLE_GRID" -> ComfortableGrid
@ -54,6 +41,3 @@ sealed class LibraryDisplayMode(
} }
} }
} }
val Category?.display: LibraryDisplayMode
get() = LibraryDisplayMode.valueOf(this?.flags)

View File

@ -281,7 +281,7 @@
<string name="default_category">Default category</string> <string name="default_category">Default category</string>
<string name="default_category_summary">Always ask</string> <string name="default_category_summary">Always ask</string>
<string name="categorized_display_settings">Per-category settings for sort and display</string> <string name="categorized_display_settings">Per-category settings for sort</string>
<plurals name="num_categories"> <plurals name="num_categories">
<item quantity="one">%d category</item> <item quantity="one">%d category</item>
<item quantity="other">%d categories</item> <item quantity="other">%d categories</item>