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.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<CategoryRepository> { 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()) }

View File

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

View File

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

View File

@ -34,7 +34,7 @@ fun LibraryPager(
selectedManga: List<LibraryManga>,
searchQuery: String?,
onGlobalSearchClicked: () -> Unit,
getDisplayModeForPage: @Composable (Int) -> LibraryDisplayMode,
getDisplayMode: (Int) -> PreferenceMutableState<LibraryDisplayMode>,
getColumnsForOrientation: (Boolean) -> PreferenceMutableState<Int>,
getLibraryForPage: (Int) -> List<LibraryItem>,
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

View File

@ -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<LibraryDisplayMode> {
return libraryPreferences.libraryDisplayMode().asState(coroutineScope)
}
fun getColumnsPreferenceForCurrentOrientation(isLandscape: Boolean): PreferenceMutableState<Int> {
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.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)
}

View File

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