From 7ec5a51eb858c0f585bfe1a2662cf203495d40ef Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 20 Mar 2023 08:41:44 -0400 Subject: [PATCH] Move isLocal extension functions to LocalSource --- .../kanade/domain/source/interactor/GetEnabledSources.kt | 4 ++-- .../source/interactor/GetSourcesWithFavoriteCount.kt | 4 ++-- .../java/eu/kanade/presentation/browse/SourcesScreen.kt | 4 ++-- .../kanade/presentation/browse/components/BrowseIcons.kt | 4 ++-- .../eu/kanade/tachiyomi/source/AndroidSourceManager.kt | 1 + .../kotlin/tachiyomi/source/local/LocalSource.kt | 7 +++++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt index a595e0c0f9..046d5055d0 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetEnabledSources.kt @@ -8,7 +8,7 @@ import tachiyomi.domain.source.model.Pin import tachiyomi.domain.source.model.Pins import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.repository.SourceRepository -import tachiyomi.source.local.LocalSource +import tachiyomi.source.local.isLocal class GetEnabledSources( private val repository: SourceRepository, @@ -24,7 +24,7 @@ class GetEnabledSources( repository.getSources(), ) { pinnedSourceIds, enabledLanguages, disabledSources, lastUsedSource, sources -> sources - .filter { it.lang in enabledLanguages || it.id == LocalSource.ID } + .filter { it.lang in enabledLanguages || it.isLocal() } .filterNot { it.id.toString() in disabledSources } .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }) .flatMap { diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt index 0083f0a6cd..8ca143cc13 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetSourcesWithFavoriteCount.kt @@ -5,7 +5,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import tachiyomi.domain.source.model.Source import tachiyomi.domain.source.repository.SourceRepository -import tachiyomi.source.local.LocalSource +import tachiyomi.source.local.isLocal import java.text.Collator import java.util.Collections import java.util.Locale @@ -22,7 +22,7 @@ class GetSourcesWithFavoriteCount( repository.getSourcesWithFavoriteCount(), ) { direction, mode, list -> list - .filterNot { it.first.id == LocalSource.ID } + .filterNot { it.first.isLocal() } .sortedWith(sortFn(direction, mode)) } } diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt index 5c0dd1042a..2258682931 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt @@ -35,7 +35,7 @@ import tachiyomi.presentation.core.screens.EmptyScreen import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.presentation.core.theme.header import tachiyomi.presentation.core.util.plus -import tachiyomi.source.local.LocalSource +import tachiyomi.source.local.isLocal @Composable fun SourcesScreen( @@ -175,7 +175,7 @@ fun SourceOptionsDialog( .fillMaxWidth() .padding(vertical = 16.dp), ) - if (source.id != LocalSource.ID) { + if (source.isLocal()) { Text( text = stringResource(R.string.action_disable), modifier = Modifier diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt index 035656f60a..08cb517e5a 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseIcons.kt @@ -33,7 +33,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.model.Extension import tachiyomi.core.util.lang.withIOContext import tachiyomi.domain.source.model.Source -import tachiyomi.source.local.LocalSource +import tachiyomi.source.local.isLocal private val defaultModifier = Modifier .height(40.dp) @@ -62,7 +62,7 @@ fun SourceIcon( modifier = modifier.then(defaultModifier), ) } - source.id == LocalSource.ID -> { + source.isLocal() -> { Image( painter = painterResource(R.mipmap.ic_local_source), contentDescription = null, diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt b/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt index 26fa9f28ec..ade85146b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/AndroidSourceManager.kt @@ -28,6 +28,7 @@ class AndroidSourceManager( private val extensionManager: ExtensionManager, private val sourceRepository: SourceDataRepository, ) : SourceManager { + private val downloadManager: DownloadManager by injectLazy() private val scope = CoroutineScope(Job() + Dispatchers.IO) diff --git a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt index 320caeb8d4..7683bf3b7b 100644 --- a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt @@ -38,9 +38,10 @@ import java.io.File import java.io.FileInputStream import java.io.InputStream import java.nio.charset.StandardCharsets -import java.util.concurrent.TimeUnit import java.util.zip.ZipFile +import kotlin.time.Duration.Companion.days import com.github.junrar.Archive as JunrarArchive +import tachiyomi.domain.source.model.Source as DomainSource actual class LocalSource( private val context: Context, @@ -348,10 +349,12 @@ actual class LocalSource( const val ID = 0L const val HELP_URL = "https://tachiyomi.org/help/guides/local-manga/" - private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS) + private val LATEST_THRESHOLD = 7.days.inWholeMilliseconds } } fun Manga.isLocal(): Boolean = source == LocalSource.ID fun Source.isLocal(): Boolean = id == LocalSource.ID + +fun DomainSource.isLocal(): Boolean = id == LocalSource.ID