From 405a75438a61770a12292cc87c0fa36e16668124 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 4 Jun 2023 16:59:21 -0400 Subject: [PATCH] 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. --- .../java/eu/kanade/domain/DomainModule.kt | 4 +-- .../library/LibrarySettingsDialog.kt | 14 ++++---- .../library/components/LibraryContent.kt | 4 +-- .../library/components/LibraryPager.kt | 4 +-- .../ui/library/LibraryScreenModel.kt | 5 +++ .../ui/library/LibrarySettingsScreenModel.kt | 12 +++---- .../kanade/tachiyomi/ui/library/LibraryTab.kt | 3 +- .../interactor/CreateCategoryWithName.kt | 4 +-- .../category/interactor/ResetCategoryFlags.kt | 3 +- .../category/interactor/SetDisplayMode.kt | 13 +++++++ .../interactor/SetDisplayModeForCategory.kt | 34 ------------------- .../interactor/SetSortModeForCategory.kt | 12 +++---- .../library/model/LibraryDisplayMode.kt | 26 +++----------- i18n/src/main/res/values/strings.xml | 2 +- 14 files changed, 50 insertions(+), 90 deletions(-) create mode 100644 domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayMode.kt delete mode 100644 domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 67ae1c68d..f3aa29464 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -31,7 +31,7 @@ import tachiyomi.domain.category.interactor.GetCategories import tachiyomi.domain.category.interactor.RenameCategory import tachiyomi.domain.category.interactor.ReorderCategory 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.SetSortModeForCategory import tachiyomi.domain.category.interactor.UpdateCategory @@ -82,7 +82,7 @@ class DomainModule : InjektModule { addSingletonFactory { CategoryRepositoryImpl(get()) } addFactory { GetCategories(get()) } addFactory { ResetCategoryFlags(get(), get()) } - addFactory { SetDisplayModeForCategory(get(), get()) } + addFactory { SetDisplayMode(get()) } addFactory { SetSortModeForCategory(get(), get()) } addFactory { CreateCategoryWithName(get(), get()) } addFactory { RenameCategory(get()) } diff --git a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt index b3a7c9af6..7d570a459 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt @@ -29,7 +29,6 @@ import eu.kanade.tachiyomi.ui.library.LibrarySettingsScreenModel import tachiyomi.domain.category.model.Category import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibrarySort -import tachiyomi.domain.library.model.display import tachiyomi.domain.library.model.sort import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.manga.model.TriStateFilter @@ -43,7 +42,7 @@ import tachiyomi.presentation.core.components.SortItem fun LibrarySettingsDialog( onDismissRequest: () -> Unit, screenModel: LibrarySettingsScreenModel, - category: Category, + category: Category?, ) { TabbedDialog( onDismissRequest = onDismissRequest, @@ -67,7 +66,6 @@ fun LibrarySettingsDialog( screenModel = screenModel, ) 2 -> DisplayPage( - category = category, screenModel = screenModel, ) } @@ -146,7 +144,7 @@ private fun ColumnScope.FilterPage( @Composable private fun ColumnScope.SortPage( - category: Category, + category: Category?, screenModel: LibrarySettingsScreenModel, ) { val sortingMode = category.sort.type @@ -179,10 +177,10 @@ private fun ColumnScope.SortPage( @Composable private fun ColumnScope.DisplayPage( - category: Category, screenModel: LibrarySettingsScreenModel, ) { HeadingItem(R.string.action_display_mode) + val displayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState() listOf( R.string.action_display_grid to LibraryDisplayMode.CompactGrid, R.string.action_display_comfortable_grid to LibraryDisplayMode.ComfortableGrid, @@ -191,12 +189,12 @@ private fun ColumnScope.DisplayPage( ).map { (titleRes, mode) -> RadioItem( label = stringResource(titleRes), - selected = category.display == mode, - onClick = { screenModel.setDisplayMode(category, mode) }, + selected = displayMode == mode, + onClick = { screenModel.setDisplayMode(mode) }, ) } - if (category.display != LibraryDisplayMode.List) { + if (displayMode != LibraryDisplayMode.List) { Row( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt index f4bb3908d..61da10345 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt @@ -42,7 +42,7 @@ fun LibraryContent( onRefresh: (Category?) -> Boolean, onGlobalSearchClicked: () -> Unit, getNumberOfMangaForCategory: (Category) -> Int?, - getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, + getDisplayMode: (Int) -> PreferenceMutableState, getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: (Int) -> List, ) { @@ -102,7 +102,7 @@ fun LibraryContent( selectedManga = selection, searchQuery = searchQuery, onGlobalSearchClicked = onGlobalSearchClicked, - getDisplayModeForPage = getDisplayModeForPage, + getDisplayMode = getDisplayMode, getColumnsForOrientation = getColumnsForOrientation, getLibraryForPage = getLibraryForPage, onClickManga = onClickManga, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt index 7c32ee09b..ace52a11c 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryPager.kt @@ -34,7 +34,7 @@ fun LibraryPager( selectedManga: List, searchQuery: String?, onGlobalSearchClicked: () -> Unit, - getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode, + getDisplayMode: (Int) -> PreferenceMutableState, getColumnsForOrientation: (Boolean) -> PreferenceMutableState, getLibraryForPage: (Int) -> List, onClickManga: (LibraryManga) -> Unit, @@ -62,7 +62,7 @@ fun LibraryPager( return@HorizontalPager } - val displayMode = getDisplayModeForPage(page) + val displayMode by getDisplayMode(page) val columns by if (displayMode != LibraryDisplayMode.List) { val configuration = LocalConfiguration.current val isLandscape = configuration.orientation == Configuration.ORIENTATION_LANDSCAPE diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt index e5411fd84..cbc7bfbea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt @@ -49,6 +49,7 @@ import tachiyomi.domain.category.model.Category import tachiyomi.domain.chapter.interactor.GetChapterByMangaId import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.history.interactor.GetNextChapters +import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.library.model.LibrarySort import tachiyomi.domain.library.model.sort @@ -517,6 +518,10 @@ class LibraryScreenModel( } } + fun getDisplayMode(): PreferenceMutableState { + return libraryPreferences.libraryDisplayMode().asState(coroutineScope) + } + fun getColumnsPreferenceForCurrentOrientation(isLandscape: Boolean): PreferenceMutableState { return (if (isLandscape) libraryPreferences.landscapeColumns() else libraryPreferences.portraitColumns()).asState(coroutineScope) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt index 673be7934..78badbede 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsScreenModel.kt @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.util.preference.toggle import tachiyomi.core.preference.Preference import tachiyomi.core.preference.getAndSet 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.model.Category import tachiyomi.domain.library.model.LibraryDisplayMode @@ -21,7 +21,7 @@ import uy.kohesive.injekt.api.get class LibrarySettingsScreenModel( val preferences: BasePreferences = 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 trackManager: TrackManager = Injekt.get(), ) : ScreenModel { @@ -43,13 +43,11 @@ class LibrarySettingsScreenModel( toggleFilter { libraryPreferences.filterTracking(id) } } - fun setDisplayMode(category: Category, mode: LibraryDisplayMode) { - coroutineScope.launchIO { - setDisplayModeForCategory.await(category, mode) - } + fun setDisplayMode(mode: LibraryDisplayMode) { + setDisplayMode.await(mode) } - fun setSort(category: Category, mode: LibrarySort.Type, direction: LibrarySort.Direction) { + fun setSort(category: Category?, mode: LibrarySort.Type, direction: LibrarySort.Direction) { coroutineScope.launchIO { setSortModeForCategory.await(category, mode, direction) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt index 1324c9133..c3a11d034 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt @@ -50,7 +50,6 @@ import kotlinx.coroutines.launch import tachiyomi.core.util.lang.launchIO import tachiyomi.domain.category.model.Category import tachiyomi.domain.library.model.LibraryManga -import tachiyomi.domain.library.model.display import tachiyomi.domain.manga.model.Manga import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.screens.EmptyScreen @@ -196,7 +195,7 @@ object LibraryTab : Tab { navigator.push(GlobalSearchScreen(screenModel.state.value.searchQuery ?: "")) }, getNumberOfMangaForCategory = { state.getMangaCountForCategory(it) }, - getDisplayModeForPage = { state.categories[it].display }, + getDisplayMode = { screenModel.getDisplayMode() }, getColumnsForOrientation = { screenModel.getColumnsPreferenceForCurrentOrientation(it) }, ) { state.getLibraryItemsByPage(it) } } diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/CreateCategoryWithName.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/CreateCategoryWithName.kt index a9f215590..3674b797d 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/CreateCategoryWithName.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/CreateCategoryWithName.kt @@ -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 { diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/ResetCategoryFlags.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/ResetCategoryFlags.kt index 6508d9131..a8014186c 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/ResetCategoryFlags.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/ResetCategoryFlags.kt @@ -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) } } diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayMode.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayMode.kt new file mode 100644 index 000000000..9ef5ca942 --- /dev/null +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayMode.kt @@ -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) + } +} diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt deleted file mode 100644 index ed6c89c17..000000000 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt +++ /dev/null @@ -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) - } -} diff --git a/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt b/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt index 5502073e1..bca8ca062 100644 --- a/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt +++ b/domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt @@ -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) } } diff --git a/domain/src/main/java/tachiyomi/domain/library/model/LibraryDisplayMode.kt b/domain/src/main/java/tachiyomi/domain/library/model/LibraryDisplayMode.kt index 968efb940..c7d2866a5 100644 --- a/domain/src/main/java/tachiyomi/domain/library/model/LibraryDisplayMode.kt +++ b/domain/src/main/java/tachiyomi/domain/library/model/LibraryDisplayMode.kt @@ -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) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index ddeab2a1c..5bdf16566 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -281,7 +281,7 @@ Default category Always ask - Per-category settings for sort and display + Per-category settings for sort %d category %d categories