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. (cherry picked from commit 405a75438a61770a12292cc87c0fa36e16668124) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt # domain/src/main/java/tachiyomi/domain/category/interactor/SetDisplayModeForCategory.kt # domain/src/main/java/tachiyomi/domain/category/interactor/SetSortModeForCategory.kt
This commit is contained in:
parent
ff9b7a1325
commit
23170b6f03
@ -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()) }
|
||||||
|
@ -34,7 +34,6 @@ import tachiyomi.domain.category.model.Category
|
|||||||
import tachiyomi.domain.library.model.LibraryDisplayMode
|
import tachiyomi.domain.library.model.LibraryDisplayMode
|
||||||
import tachiyomi.domain.library.model.LibraryGroup
|
import tachiyomi.domain.library.model.LibraryGroup
|
||||||
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
|
||||||
@ -49,7 +48,7 @@ import tachiyomi.presentation.core.components.SortItem
|
|||||||
fun LibrarySettingsDialog(
|
fun LibrarySettingsDialog(
|
||||||
onDismissRequest: () -> Unit,
|
onDismissRequest: () -> Unit,
|
||||||
screenModel: LibrarySettingsScreenModel,
|
screenModel: LibrarySettingsScreenModel,
|
||||||
category: Category,
|
category: Category?,
|
||||||
// SY -->
|
// SY -->
|
||||||
hasCategories: Boolean,
|
hasCategories: Boolean,
|
||||||
// SY <--
|
// SY <--
|
||||||
@ -79,7 +78,6 @@ fun LibrarySettingsDialog(
|
|||||||
screenModel = screenModel,
|
screenModel = screenModel,
|
||||||
)
|
)
|
||||||
2 -> DisplayPage(
|
2 -> DisplayPage(
|
||||||
category = category,
|
|
||||||
screenModel = screenModel,
|
screenModel = screenModel,
|
||||||
)
|
)
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -172,7 +170,7 @@ private fun ColumnScope.FilterPage(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColumnScope.SortPage(
|
private fun ColumnScope.SortPage(
|
||||||
category: Category,
|
category: Category?,
|
||||||
screenModel: LibrarySettingsScreenModel,
|
screenModel: LibrarySettingsScreenModel,
|
||||||
) {
|
) {
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -225,7 +223,6 @@ private fun ColumnScope.SortPage(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ColumnScope.DisplayPage(
|
private fun ColumnScope.DisplayPage(
|
||||||
category: Category,
|
|
||||||
screenModel: LibrarySettingsScreenModel,
|
screenModel: LibrarySettingsScreenModel,
|
||||||
) {
|
) {
|
||||||
// SY -->
|
// SY -->
|
||||||
@ -233,6 +230,7 @@ private fun ColumnScope.DisplayPage(
|
|||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
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,
|
||||||
@ -241,18 +239,12 @@ private fun ColumnScope.DisplayPage(
|
|||||||
).map { (titleRes, mode) ->
|
).map { (titleRes, mode) ->
|
||||||
RadioItem(
|
RadioItem(
|
||||||
label = stringResource(titleRes),
|
label = stringResource(titleRes),
|
||||||
// SY -->
|
selected = displayMode == mode,
|
||||||
selected = if (screenModel.grouping == LibraryGroup.BY_DEFAULT) {
|
onClick = { screenModel.setDisplayMode(mode) },
|
||||||
category.display
|
|
||||||
} else {
|
|
||||||
globalDisplayMode
|
|
||||||
} == mode,
|
|
||||||
// SY <--
|
|
||||||
onClick = { screenModel.setDisplayMode(category, mode) },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category.display != LibraryDisplayMode.List) {
|
if (displayMode != LibraryDisplayMode.List) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
@ -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>,
|
||||||
) {
|
) {
|
||||||
@ -104,7 +104,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,
|
||||||
|
@ -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
|
||||||
|
@ -165,20 +165,19 @@ class LibraryScreenModel(
|
|||||||
combine(
|
combine(
|
||||||
getTrackingFilterFlow(),
|
getTrackingFilterFlow(),
|
||||||
downloadCache.changes,
|
downloadCache.changes,
|
||||||
) { a, b -> a to b },
|
::Pair,
|
||||||
|
),
|
||||||
// SY -->
|
// SY -->
|
||||||
combine(
|
combine(
|
||||||
state.map { it.groupType }.distinctUntilChanged(),
|
state.map { it.groupType }.distinctUntilChanged(),
|
||||||
libraryPreferences.libraryDisplayMode().changes(),
|
|
||||||
libraryPreferences.librarySortingMode().changes(),
|
libraryPreferences.librarySortingMode().changes(),
|
||||||
) { a, b, c ->
|
::Pair,
|
||||||
Triple(a, b, c)
|
),
|
||||||
},
|
|
||||||
// SY <--
|
// SY <--
|
||||||
) { searchQuery, library, tracks, (loggedInTrackServices, _), (groupType, displayMode, sort) ->
|
) { searchQuery, library, tracks, (loggedInTrackServices, _), (groupType, sort) ->
|
||||||
library
|
library
|
||||||
// SY -->
|
// SY -->
|
||||||
.applyGrouping(groupType, displayMode)
|
.applyGrouping(groupType)
|
||||||
// SY <--
|
// SY <--
|
||||||
.applyFilters(tracks, loggedInTrackServices)
|
.applyFilters(tracks, loggedInTrackServices)
|
||||||
.applySort(/* SY --> */sort.takeIf { groupType != LibraryGroup.BY_DEFAULT } /* SY <-- */)
|
.applySort(/* SY --> */sort.takeIf { groupType != LibraryGroup.BY_DEFAULT } /* SY <-- */)
|
||||||
@ -523,7 +522,7 @@ class LibraryScreenModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
private fun LibraryMap.applyGrouping(groupType: Int, displayMode: LibraryDisplayMode): LibraryMap {
|
private fun LibraryMap.applyGrouping(groupType: Int): LibraryMap {
|
||||||
val items = when (groupType) {
|
val items = when (groupType) {
|
||||||
LibraryGroup.BY_DEFAULT -> this
|
LibraryGroup.BY_DEFAULT -> this
|
||||||
LibraryGroup.UNGROUPED -> {
|
LibraryGroup.UNGROUPED -> {
|
||||||
@ -532,7 +531,7 @@ class LibraryScreenModel(
|
|||||||
0,
|
0,
|
||||||
preferences.context.getString(R.string.ungrouped),
|
preferences.context.getString(R.string.ungrouped),
|
||||||
0,
|
0,
|
||||||
displayMode.flag,
|
0,
|
||||||
) to
|
) to
|
||||||
values.flatten().distinctBy { it.libraryManga.manga.id },
|
values.flatten().distinctBy { it.libraryManga.manga.id },
|
||||||
)
|
)
|
||||||
@ -541,7 +540,6 @@ class LibraryScreenModel(
|
|||||||
getGroupedMangaItems(
|
getGroupedMangaItems(
|
||||||
groupType = groupType,
|
groupType = groupType,
|
||||||
libraryManga = this.values.flatten().distinctBy { it.libraryManga.manga.id },
|
libraryManga = this.values.flatten().distinctBy { it.libraryManga.manga.id },
|
||||||
displayMode = displayMode,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -787,6 +785,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)
|
||||||
}
|
}
|
||||||
@ -1118,7 +1120,6 @@ class LibraryScreenModel(
|
|||||||
private fun getGroupedMangaItems(
|
private fun getGroupedMangaItems(
|
||||||
groupType: Int,
|
groupType: Int,
|
||||||
libraryManga: List<LibraryItem>,
|
libraryManga: List<LibraryItem>,
|
||||||
displayMode: LibraryDisplayMode,
|
|
||||||
): LibraryMap {
|
): LibraryMap {
|
||||||
val context = preferences.context
|
val context = preferences.context
|
||||||
return when (groupType) {
|
return when (groupType) {
|
||||||
@ -1138,7 +1139,7 @@ class LibraryScreenModel(
|
|||||||
.let { it ?: TrackStatus.OTHER }
|
.let { it ?: TrackStatus.OTHER }
|
||||||
.let { context.getString(it.res) },
|
.let { context.getString(it.res) },
|
||||||
order = TrackStatus.values().indexOfFirst { it.int == id }.takeUnless { it == -1 }?.toLong() ?: TrackStatus.OTHER.ordinal.toLong(),
|
order = TrackStatus.values().indexOfFirst { it.int == id }.takeUnless { it == -1 }?.toLong() ?: TrackStatus.OTHER.ordinal.toLong(),
|
||||||
flags = displayMode.flag,
|
flags = 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1163,7 +1164,7 @@ class LibraryScreenModel(
|
|||||||
source.name.ifBlank { source.id.toString() }
|
source.name.ifBlank { source.id.toString() }
|
||||||
},
|
},
|
||||||
order = sources.indexOf(it.key).takeUnless { it == -1 }?.toLong() ?: Long.MAX_VALUE,
|
order = sources.indexOf(it.key).takeUnless { it == -1 }?.toLong() ?: Long.MAX_VALUE,
|
||||||
flags = displayMode.flag,
|
flags = 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1191,7 +1192,7 @@ class LibraryScreenModel(
|
|||||||
SManga.COMPLETED.toLong() -> 6
|
SManga.COMPLETED.toLong() -> 6
|
||||||
else -> 7
|
else -> 7
|
||||||
},
|
},
|
||||||
flags = displayMode.flag,
|
flags = 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,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
|
||||||
@ -23,7 +23,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 {
|
||||||
@ -49,13 +49,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)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ import tachiyomi.domain.UnsortedPreferences
|
|||||||
import tachiyomi.domain.category.model.Category
|
import tachiyomi.domain.category.model.Category
|
||||||
import tachiyomi.domain.library.model.LibraryGroup
|
import tachiyomi.domain.library.model.LibraryGroup
|
||||||
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
|
||||||
@ -242,7 +241,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.coerceAtMost(state.categories.lastIndex)].display },
|
getDisplayMode = { screenModel.getDisplayMode() },
|
||||||
getColumnsForOrientation = { screenModel.getColumnsPreferenceForCurrentOrientation(it) },
|
getColumnsForOrientation = { screenModel.getColumnsPreferenceForCurrentOrientation(it) },
|
||||||
) { state.getLibraryItemsByPage(it) }
|
) { state.getLibraryItemsByPage(it) }
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,41 +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.LibraryGroup
|
|
||||||
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) {
|
|
||||||
// SY -->
|
|
||||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
|
||||||
preferences.libraryDisplayMode().set(display)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// SY <--
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,16 +13,16 @@ 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) {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
if (preferences.groupLibraryBy().get() != LibraryGroup.BY_DEFAULT) {
|
||||||
preferences.librarySortingMode().set(LibrarySort(type, direction))
|
preferences.librarySortingMode().set(LibrarySort(type, direction))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
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,
|
||||||
@ -35,7 +35,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user