From 5b2e937d5fdeadc8a9a994b99b3f6b7a277f2513 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Feb 2023 16:47:29 -0500 Subject: [PATCH] Minor refactoring --- .../java/eu/kanade/core/preference/CheckboxState.kt | 10 ++++++++++ .../{prefs => preference}/PreferenceMutableState.kt | 2 +- .../main/java/eu/kanade/core/prefs/CheckboxState.kt | 12 ------------ .../eu/kanade/data/source/SourceRepositoryImpl.kt | 9 +++++---- .../domain/source/interactor/GetRemoteManga.kt | 2 +- .../domain/source/model/SourcePagingSourceType.kt | 6 ------ .../domain/source/repository/SourceRepository.kt | 2 +- .../kanade/presentation/browse/BrowseSourceScreen.kt | 2 +- .../presentation/category/ChangeCategoryDialog.kt | 4 ++-- .../library/components/LibraryContent.kt | 2 +- .../presentation/library/components/LibraryPager.kt | 2 +- .../browse/source/browse/BrowseSourceScreenModel.kt | 2 +- .../tachiyomi/ui/library/LibraryScreenModel.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt | 2 +- .../main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt | 2 +- .../tachiyomi/ui/updates/UpdatesScreenModel.kt | 2 +- .../tachiyomi}/data/source/SourcePagingSource.kt | 6 ++++-- 17 files changed, 33 insertions(+), 38 deletions(-) create mode 100644 app/src/main/java/eu/kanade/core/preference/CheckboxState.kt rename app/src/main/java/eu/kanade/core/{prefs => preference}/PreferenceMutableState.kt (96%) delete mode 100644 app/src/main/java/eu/kanade/core/prefs/CheckboxState.kt delete mode 100644 app/src/main/java/eu/kanade/domain/source/model/SourcePagingSourceType.kt rename {app/src/main/java/eu/kanade => data/src/main/java/tachiyomi}/data/source/SourcePagingSource.kt (94%) diff --git a/app/src/main/java/eu/kanade/core/preference/CheckboxState.kt b/app/src/main/java/eu/kanade/core/preference/CheckboxState.kt new file mode 100644 index 000000000..12635d04f --- /dev/null +++ b/app/src/main/java/eu/kanade/core/preference/CheckboxState.kt @@ -0,0 +1,10 @@ +package eu.kanade.core.preference + +import androidx.compose.ui.state.ToggleableState +import tachiyomi.core.preference.CheckboxState + +fun CheckboxState.TriState.asToggleableState() = when (this) { + is CheckboxState.TriState.Exclude -> ToggleableState.Indeterminate + is CheckboxState.TriState.Include -> ToggleableState.On + is CheckboxState.TriState.None -> ToggleableState.Off +} diff --git a/app/src/main/java/eu/kanade/core/prefs/PreferenceMutableState.kt b/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt similarity index 96% rename from app/src/main/java/eu/kanade/core/prefs/PreferenceMutableState.kt rename to app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt index c33b24091..2c641ccc0 100644 --- a/app/src/main/java/eu/kanade/core/prefs/PreferenceMutableState.kt +++ b/app/src/main/java/eu/kanade/core/preference/PreferenceMutableState.kt @@ -1,4 +1,4 @@ -package eu.kanade.core.prefs +package eu.kanade.core.preference import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf diff --git a/app/src/main/java/eu/kanade/core/prefs/CheckboxState.kt b/app/src/main/java/eu/kanade/core/prefs/CheckboxState.kt deleted file mode 100644 index c3b54ecab..000000000 --- a/app/src/main/java/eu/kanade/core/prefs/CheckboxState.kt +++ /dev/null @@ -1,12 +0,0 @@ -package eu.kanade.core.prefs - -import androidx.compose.ui.state.ToggleableState -import tachiyomi.core.preference.CheckboxState - -fun CheckboxState.TriState.asState(): ToggleableState { - return when (this) { - is CheckboxState.TriState.Exclude -> ToggleableState.Indeterminate - is CheckboxState.TriState.Include -> ToggleableState.On - is CheckboxState.TriState.None -> ToggleableState.Off - } -} diff --git a/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt b/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt index 9ac162e1b..e5b2285c6 100644 --- a/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt +++ b/app/src/main/java/eu/kanade/data/source/SourceRepositoryImpl.kt @@ -1,6 +1,5 @@ package eu.kanade.data.source -import eu.kanade.domain.source.model.SourcePagingSourceType import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.SourceManager @@ -8,6 +7,10 @@ import eu.kanade.tachiyomi.source.model.FilterList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import tachiyomi.data.DatabaseHandler +import tachiyomi.data.source.SourceLatestPagingSource +import tachiyomi.data.source.SourcePagingSourceType +import tachiyomi.data.source.SourcePopularPagingSource +import tachiyomi.data.source.SourceSearchPagingSource import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.model.SourceWithCount import tachiyomi.source.local.LocalSource @@ -35,9 +38,7 @@ class SourceRepositoryImpl( sourceIdsWithCount .filterNot { it.source == LocalSource.ID } .map { (sourceId, count) -> - val source = sourceManager.getOrStub(sourceId).run { - sourceMapper(this) - } + val source = sourceMapper(sourceManager.getOrStub(sourceId)) source to count } } diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetRemoteManga.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetRemoteManga.kt index 0fefeeee6..3a2574b81 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetRemoteManga.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetRemoteManga.kt @@ -1,8 +1,8 @@ package eu.kanade.domain.source.interactor -import eu.kanade.domain.source.model.SourcePagingSourceType import eu.kanade.domain.source.repository.SourceRepository import eu.kanade.tachiyomi.source.model.FilterList +import tachiyomi.data.source.SourcePagingSourceType class GetRemoteManga( private val repository: SourceRepository, diff --git a/app/src/main/java/eu/kanade/domain/source/model/SourcePagingSourceType.kt b/app/src/main/java/eu/kanade/domain/source/model/SourcePagingSourceType.kt deleted file mode 100644 index 456f65f7c..000000000 --- a/app/src/main/java/eu/kanade/domain/source/model/SourcePagingSourceType.kt +++ /dev/null @@ -1,6 +0,0 @@ -package eu.kanade.domain.source.model - -import androidx.paging.PagingSource -import eu.kanade.tachiyomi.source.model.SManga - -typealias SourcePagingSourceType = PagingSource diff --git a/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt b/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt index 5b6c2b215..0783815bb 100644 --- a/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt +++ b/app/src/main/java/eu/kanade/domain/source/repository/SourceRepository.kt @@ -1,8 +1,8 @@ package eu.kanade.domain.source.repository -import eu.kanade.domain.source.model.SourcePagingSourceType import eu.kanade.tachiyomi.source.model.FilterList import kotlinx.coroutines.flow.Flow +import tachiyomi.data.source.SourcePagingSourceType import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.model.SourceWithCount diff --git a/app/src/main/java/eu/kanade/presentation/browse/BrowseSourceScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/BrowseSourceScreen.kt index a27bf3d09..4ec361735 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/BrowseSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/BrowseSourceScreen.kt @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.paging.LoadState import androidx.paging.compose.LazyPagingItems -import eu.kanade.data.source.NoResultsException import eu.kanade.presentation.browse.components.BrowseSourceComfortableGrid import eu.kanade.presentation.browse.components.BrowseSourceCompactGrid import eu.kanade.presentation.browse.components.BrowseSourceList @@ -25,6 +24,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import kotlinx.coroutines.flow.StateFlow +import tachiyomi.data.source.NoResultsException import tachiyomi.domain.library.model.LibraryDisplayMode import tachiyomi.domain.manga.model.Manga import tachiyomi.presentation.core.components.material.Scaffold diff --git a/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt b/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt index 91b75cf4b..68f073f9e 100644 --- a/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt @@ -21,7 +21,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.asToggleableState import eu.kanade.tachiyomi.R import tachiyomi.core.preference.CheckboxState import tachiyomi.domain.category.model.Category @@ -110,7 +110,7 @@ fun ChangeCategoryDialog( when (checkbox) { is CheckboxState.TriState -> { TriStateCheckbox( - state = checkbox.asState(), + state = checkbox.asToggleableState(), onClick = { onChange(checkbox) }, ) } 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 3b451f36f..706deeb06 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 @@ -14,7 +14,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLayoutDirection -import eu.kanade.core.prefs.PreferenceMutableState +import eu.kanade.core.preference.PreferenceMutableState import eu.kanade.tachiyomi.ui.library.LibraryItem import kotlinx.coroutines.delay import kotlinx.coroutines.launch 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 6c9fc418b..c3bba5f47 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 @@ -16,7 +16,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.unit.dp -import eu.kanade.core.prefs.PreferenceMutableState +import eu.kanade.core.preference.PreferenceMutableState import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.library.LibraryItem import tachiyomi.domain.library.model.LibraryDisplayMode diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index 7f7df1b05..95010c4ec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -13,7 +13,7 @@ import androidx.paging.filter import androidx.paging.map import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.asState import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.library.service.LibraryPreferences 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 8955b891f..1dbc928e6 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 @@ -7,8 +7,8 @@ import androidx.compose.ui.util.fastAny import androidx.compose.ui.util.fastMap import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope -import eu.kanade.core.prefs.PreferenceMutableState -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.PreferenceMutableState +import eu.kanade.core.preference.asState import eu.kanade.core.util.fastDistinctBy import eu.kanade.core.util.fastFilter import eu.kanade.core.util.fastFilterNot diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 0ae05e24a..1b3469be6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -8,7 +8,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.asState import eu.kanade.core.util.addOrRemove import eu.kanade.domain.chapter.interactor.SetMangaDefaultChapterFlags import eu.kanade.domain.chapter.interactor.SetReadStatus diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt index 0ad008f67..d91d49da3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt @@ -17,7 +17,7 @@ import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow import cafe.adriel.voyager.navigator.tab.LocalTabNavigator import cafe.adriel.voyager.navigator.tab.TabOptions -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.asState import eu.kanade.domain.base.BasePreferences import eu.kanade.presentation.more.MoreScreen import eu.kanade.presentation.util.Tab diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt index 5815a585a..7a44527c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/updates/UpdatesScreenModel.kt @@ -8,7 +8,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.coroutineScope -import eu.kanade.core.prefs.asState +import eu.kanade.core.preference.asState import eu.kanade.core.util.addOrRemove import eu.kanade.core.util.insertSeparators import eu.kanade.domain.chapter.interactor.SetReadStatus diff --git a/app/src/main/java/eu/kanade/data/source/SourcePagingSource.kt b/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt similarity index 94% rename from app/src/main/java/eu/kanade/data/source/SourcePagingSource.kt rename to data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt index c5b724be7..8b4fb0341 100644 --- a/app/src/main/java/eu/kanade/data/source/SourcePagingSource.kt +++ b/data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt @@ -1,7 +1,7 @@ -package eu.kanade.data.source +package tachiyomi.data.source +import androidx.paging.PagingSource import androidx.paging.PagingState -import eu.kanade.domain.source.model.SourcePagingSourceType import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage @@ -9,6 +9,8 @@ import eu.kanade.tachiyomi.source.model.SManga import tachiyomi.core.util.lang.awaitSingle import tachiyomi.core.util.lang.withIOContext +typealias SourcePagingSourceType = PagingSource + abstract class SourcePagingSource( protected val source: CatalogueSource, ) : SourcePagingSourceType() {