Move SettingsItems composables to presentation-core

This commit is contained in:
arkon
2023-07-10 17:25:52 -04:00
parent efabe801be
commit 87bdee5990
16 changed files with 238 additions and 250 deletions

View File

@@ -16,17 +16,17 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import eu.kanade.presentation.components.AdaptiveSheet
import eu.kanade.presentation.components.SelectItem
import eu.kanade.presentation.components.TriStateItem
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import tachiyomi.domain.manga.model.TriStateFilter
import tachiyomi.core.preference.TriState
import tachiyomi.presentation.core.components.CheckboxItem
import tachiyomi.presentation.core.components.CollapsibleBox
import tachiyomi.presentation.core.components.HeadingItem
import tachiyomi.presentation.core.components.SelectItem
import tachiyomi.presentation.core.components.SortItem
import tachiyomi.presentation.core.components.TextItem
import tachiyomi.presentation.core.components.TriStateItem
import tachiyomi.presentation.core.components.material.Button
import tachiyomi.presentation.core.components.material.Divider
@@ -164,19 +164,19 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit) {
}
}
private fun Int.toTriStateFilter(): TriStateFilter {
private fun Int.toTriStateFilter(): TriState {
return when (this) {
Filter.TriState.STATE_IGNORE -> TriStateFilter.DISABLED
Filter.TriState.STATE_INCLUDE -> TriStateFilter.ENABLED_IS
Filter.TriState.STATE_EXCLUDE -> TriStateFilter.ENABLED_NOT
Filter.TriState.STATE_IGNORE -> TriState.DISABLED
Filter.TriState.STATE_INCLUDE -> TriState.ENABLED_IS
Filter.TriState.STATE_EXCLUDE -> TriState.ENABLED_NOT
else -> throw IllegalStateException("Unknown TriState state: $this")
}
}
private fun TriStateFilter.toTriStateInt(): Int {
private fun TriState.toTriStateInt(): Int {
return when (this) {
TriStateFilter.DISABLED -> Filter.TriState.STATE_IGNORE
TriStateFilter.ENABLED_IS -> Filter.TriState.STATE_INCLUDE
TriStateFilter.ENABLED_NOT -> Filter.TriState.STATE_EXCLUDE
TriState.DISABLED -> Filter.TriState.STATE_IGNORE
TriState.ENABLED_IS -> Filter.TriState.STATE_INCLUDE
TriState.ENABLED_NOT -> Filter.TriState.STATE_EXCLUDE
}
}

View File

@@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import tachiyomi.core.preference.CheckboxState
import tachiyomi.core.preference.TriState
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.lang.withIOContext
@@ -57,7 +58,6 @@ import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.interactor.GetLibraryManga
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.MangaUpdate
import tachiyomi.domain.manga.model.TriStateFilter
import tachiyomi.domain.manga.model.applyFilter
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.domain.track.interactor.GetTracksPerManga
@@ -153,7 +153,7 @@ class LibraryScreenModel(
prefs.filterBookmarked,
prefs.filterCompleted,
) + trackFilter.values
).any { it != TriStateFilter.DISABLED }
).any { it != TriState.DISABLED }
}
.distinctUntilChanged()
.onEach {
@@ -169,12 +169,12 @@ class LibraryScreenModel(
*/
private suspend fun LibraryMap.applyFilters(
trackMap: Map<Long, List<Long>>,
loggedInTrackServices: Map<Long, TriStateFilter>,
loggedInTrackServices: Map<Long, TriState>,
): LibraryMap {
val prefs = getLibraryItemPreferencesFlow().first()
val downloadedOnly = prefs.globalFilterDownloaded
val filterDownloaded =
if (downloadedOnly) TriStateFilter.ENABLED_IS else prefs.filterDownloaded
if (downloadedOnly) TriState.ENABLED_IS else prefs.filterDownloaded
val filterUnread = prefs.filterUnread
val filterStarted = prefs.filterStarted
val filterBookmarked = prefs.filterBookmarked
@@ -182,8 +182,8 @@ class LibraryScreenModel(
val isNotLoggedInAnyTrack = loggedInTrackServices.isEmpty()
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateFilter.ENABLED_NOT) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateFilter.ENABLED_IS) it.key else null }
val excludedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_NOT) it.key else null }
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriState.ENABLED_IS) it.key else null }
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
val filterFnDownloaded: (LibraryItem) -> Boolean = {
@@ -308,11 +308,11 @@ class LibraryScreenModel(
localBadge = it[1] as Boolean,
languageBadge = it[2] as Boolean,
globalFilterDownloaded = it[3] as Boolean,
filterDownloaded = it[4] as TriStateFilter,
filterUnread = it[5] as TriStateFilter,
filterStarted = it[6] as TriStateFilter,
filterBookmarked = it[7] as TriStateFilter,
filterCompleted = it[8] as TriStateFilter,
filterDownloaded = it[4] as TriState,
filterUnread = it[5] as TriState,
filterStarted = it[6] as TriState,
filterBookmarked = it[7] as TriState,
filterCompleted = it[8] as TriState,
)
},
)
@@ -365,7 +365,7 @@ class LibraryScreenModel(
*
* @return map of track id with the filter value
*/
private fun getTrackingFilterFlow(): Flow<Map<Long, TriStateFilter>> {
private fun getTrackingFilterFlow(): Flow<Map<Long, TriState>> {
val loggedServices = trackManager.services.filter { it.isLogged }
return if (loggedServices.isNotEmpty()) {
val prefFlows = loggedServices
@@ -670,11 +670,11 @@ class LibraryScreenModel(
val languageBadge: Boolean,
val globalFilterDownloaded: Boolean,
val filterDownloaded: TriStateFilter,
val filterUnread: TriStateFilter,
val filterStarted: TriStateFilter,
val filterBookmarked: TriStateFilter,
val filterCompleted: TriStateFilter,
val filterDownloaded: TriState,
val filterUnread: TriState,
val filterStarted: TriState,
val filterBookmarked: TriState,
val filterCompleted: TriState,
)
@Immutable

View File

@@ -6,6 +6,7 @@ import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.util.preference.toggle
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.TriState
import tachiyomi.core.preference.getAndSet
import tachiyomi.core.util.lang.launchIO
import tachiyomi.domain.category.interactor.SetDisplayMode
@@ -14,7 +15,6 @@ import tachiyomi.domain.category.model.Category
import tachiyomi.domain.library.model.LibraryDisplayMode
import tachiyomi.domain.library.model.LibrarySort
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.model.TriStateFilter
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -33,7 +33,7 @@ class LibrarySettingsScreenModel(
preference(libraryPreferences).toggle()
}
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriStateFilter>) {
fun toggleFilter(preference: (LibraryPreferences) -> Preference<TriState>) {
preference(libraryPreferences).getAndSet {
it.next()
}

View File

@@ -46,6 +46,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import logcat.LogPriority
import tachiyomi.core.preference.CheckboxState
import tachiyomi.core.preference.TriState
import tachiyomi.core.preference.mapAsCheckboxState
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
@@ -67,7 +68,6 @@ import tachiyomi.domain.manga.interactor.GetDuplicateLibraryManga
import tachiyomi.domain.manga.interactor.GetMangaWithChapters
import tachiyomi.domain.manga.interactor.SetMangaChapterFlags
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.model.TriStateFilter
import tachiyomi.domain.manga.model.applyFilter
import tachiyomi.domain.source.service.SourceManager
import tachiyomi.domain.track.interactor.GetTracks
@@ -743,13 +743,13 @@ class MangaInfoScreenModel(
* Sets the read filter and requests an UI update.
* @param state whether to display only unread chapters or all chapters.
*/
fun setUnreadFilter(state: TriStateFilter) {
fun setUnreadFilter(state: TriState) {
val manga = successState?.manga ?: return
val flag = when (state) {
TriStateFilter.DISABLED -> Manga.SHOW_ALL
TriStateFilter.ENABLED_IS -> Manga.CHAPTER_SHOW_UNREAD
TriStateFilter.ENABLED_NOT -> Manga.CHAPTER_SHOW_READ
TriState.DISABLED -> Manga.SHOW_ALL
TriState.ENABLED_IS -> Manga.CHAPTER_SHOW_UNREAD
TriState.ENABLED_NOT -> Manga.CHAPTER_SHOW_READ
}
coroutineScope.launchNonCancellable {
setMangaChapterFlags.awaitSetUnreadFilter(manga, flag)
@@ -760,13 +760,13 @@ class MangaInfoScreenModel(
* Sets the download filter and requests an UI update.
* @param state whether to display only downloaded chapters or all chapters.
*/
fun setDownloadedFilter(state: TriStateFilter) {
fun setDownloadedFilter(state: TriState) {
val manga = successState?.manga ?: return
val flag = when (state) {
TriStateFilter.DISABLED -> Manga.SHOW_ALL
TriStateFilter.ENABLED_IS -> Manga.CHAPTER_SHOW_DOWNLOADED
TriStateFilter.ENABLED_NOT -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
TriState.DISABLED -> Manga.SHOW_ALL
TriState.ENABLED_IS -> Manga.CHAPTER_SHOW_DOWNLOADED
TriState.ENABLED_NOT -> Manga.CHAPTER_SHOW_NOT_DOWNLOADED
}
coroutineScope.launchNonCancellable {
@@ -778,13 +778,13 @@ class MangaInfoScreenModel(
* Sets the bookmark filter and requests an UI update.
* @param state whether to display only bookmarked chapters or all chapters.
*/
fun setBookmarkedFilter(state: TriStateFilter) {
fun setBookmarkedFilter(state: TriState) {
val manga = successState?.manga ?: return
val flag = when (state) {
TriStateFilter.DISABLED -> Manga.SHOW_ALL
TriStateFilter.ENABLED_IS -> Manga.CHAPTER_SHOW_BOOKMARKED
TriStateFilter.ENABLED_NOT -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
TriState.DISABLED -> Manga.SHOW_ALL
TriState.ENABLED_IS -> Manga.CHAPTER_SHOW_BOOKMARKED
TriState.ENABLED_NOT -> Manga.CHAPTER_SHOW_NOT_BOOKMARKED
}
coroutineScope.launchNonCancellable {