mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 06:37:48 +01:00
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:
parent
39e4568460
commit
405a75438a
14 changed files with 50 additions and 90 deletions
|
@ -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()) }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -281,7 +281,7 @@
|
|||
|
||||
<string name="default_category">Default category</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">
|
||||
<item quantity="one">%d category</item>
|
||||
<item quantity="other">%d categories</item>
|
||||
|
|
Loading…
Reference in a new issue