From c39a1b7867976bddc85d3bfbffeeb717b8bf4501 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 31 Aug 2022 14:43:58 -0400 Subject: [PATCH] Minor cleanup --- .../TabbedScreen.kt} | 17 ++++++----------- .../tachiyomi/data/download/DownloadCache.kt | 2 +- .../tachiyomi/data/download/DownloadManager.kt | 14 +++++--------- .../tachiyomi/data/download/Downloader.kt | 11 +++++------ .../tachiyomi/ui/browse/BrowseController.kt | 8 +++++--- .../ui/browse/extension/ExtensionsTab.kt | 8 ++++---- .../migration/sources/MigrateSourcesTab.kt | 6 +++--- .../tachiyomi/ui/browse/source/SourcesTab.kt | 4 ++-- 8 files changed, 31 insertions(+), 39 deletions(-) rename app/src/main/java/eu/kanade/presentation/{browse/BrowseScreen.kt => components/TabbedScreen.kt} (84%) diff --git a/app/src/main/java/eu/kanade/presentation/browse/BrowseScreen.kt b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt similarity index 84% rename from app/src/main/java/eu/kanade/presentation/browse/BrowseScreen.kt rename to app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt index 4860ac7419..09997eef8c 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/BrowseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/components/TabbedScreen.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.browse +package eu.kanade.presentation.components import androidx.annotation.StringRes import androidx.compose.foundation.layout.Column @@ -15,18 +15,13 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.google.accompanist.pager.HorizontalPager import com.google.accompanist.pager.rememberPagerState -import eu.kanade.presentation.components.AppBar -import eu.kanade.presentation.components.AppBarActions -import eu.kanade.presentation.components.Scaffold -import eu.kanade.presentation.components.TabIndicator -import eu.kanade.presentation.components.TabText -import eu.kanade.tachiyomi.R import kotlinx.coroutines.launch @Composable -fun BrowseScreen( +fun TabbedScreen( + @StringRes titleRes: Int, + tabs: List, startIndex: Int? = null, - tabs: List, ) { val scope = rememberCoroutineScope() val state = rememberPagerState() @@ -41,7 +36,7 @@ fun BrowseScreen( modifier = Modifier.statusBarsPadding(), topBar = { AppBar( - title = stringResource(R.string.browse), + title = stringResource(titleRes), actions = { AppBarActions(tabs[state.currentPage].actions) }, @@ -76,7 +71,7 @@ fun BrowseScreen( } } -data class BrowseTab( +data class TabContent( @StringRes val titleRes: Int, val badgeNumber: Int? = null, val actions: List = emptyList(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index d96bfe05ad..b303c03f32 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit class DownloadCache( private val context: Context, private val provider: DownloadProvider, - private val sourceManager: SourceManager, + private val sourceManager: SourceManager = Injekt.get(), private val preferences: PreferencesHelper = Injekt.get(), ) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index e7ebc6e503..b30933c23f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -20,7 +20,6 @@ import logcat.LogPriority import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy /** * This class is used to manage chapter downloads in the application. It must be instantiated once @@ -32,11 +31,10 @@ import uy.kohesive.injekt.injectLazy class DownloadManager( private val context: Context, private val getCategories: GetCategories = Injekt.get(), + private val sourceManager: SourceManager = Injekt.get(), + private val preferences: PreferencesHelper = Injekt.get(), ) { - private val sourceManager: SourceManager by injectLazy() - private val preferences: PreferencesHelper by injectLazy() - /** * Downloads provider, used to retrieve the folders where the chapters are or should be stored. */ @@ -45,12 +43,12 @@ class DownloadManager( /** * Cache of downloaded chapters. */ - private val cache = DownloadCache(context, provider, sourceManager) + private val cache = DownloadCache(context, provider) /** * Downloader whose only task is to download chapters. */ - private val downloader = Downloader(context, provider, cache, sourceManager) + private val downloader = Downloader(context, provider, cache) /** * Queue to delay the deletion of a list of chapters until triggered. @@ -112,7 +110,7 @@ class DownloadManager( download?.let { queue.remove(it) } queue.add(0, toAdd) reorderQueue(queue) - if (isPaused()) { + if (downloader.isPaused()) { if (DownloadService.isRunning(context)) { downloader.start() } else { @@ -121,8 +119,6 @@ class DownloadManager( } } - fun isPaused() = downloader.isPaused() - /** * Reorders the download queue. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index d54b4b8774..d4f45a61b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -34,7 +34,8 @@ import rx.Observable import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import rx.subscriptions.CompositeSubscription -import uy.kohesive.injekt.injectLazy +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.io.BufferedOutputStream import java.io.File import java.util.zip.CRC32 @@ -59,13 +60,11 @@ class Downloader( private val context: Context, private val provider: DownloadProvider, private val cache: DownloadCache, - private val sourceManager: SourceManager, + private val sourceManager: SourceManager = Injekt.get(), + private val chapterCache: ChapterCache = Injekt.get(), + private val preferences: PreferencesHelper = Injekt.get(), ) { - private val chapterCache: ChapterCache by injectLazy() - - private val preferences: PreferencesHelper by injectLazy() - /** * Store for persisting downloads across restarts. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index ecd0035620..60bc43ad2d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -6,7 +6,8 @@ import android.view.View import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.core.os.bundleOf -import eu.kanade.presentation.browse.BrowseScreen +import eu.kanade.presentation.components.TabbedScreen +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.FullComposeController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe @@ -30,13 +31,14 @@ class BrowseController : FullComposeController, RootController @Composable override fun ComposeContent() { - BrowseScreen( - startIndex = 1.takeIf { toExtensions }, + TabbedScreen( + titleRes = R.string.browse, tabs = listOf( sourcesTab(router, presenter.sourcesPresenter), extensionsTab(router, presenter.extensionsPresenter), migrateSourcesTab(router, presenter.migrationSourcesPresenter), ), + startIndex = 1.takeIf { toExtensions }, ) LaunchedEffect(Unit) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsTab.kt index 0812964605..64a15d5ba1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsTab.kt @@ -1,14 +1,14 @@ package eu.kanade.tachiyomi.ui.browse.extension import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.Search +import androidx.compose.material.icons.outlined.Translate import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.bluelinelabs.conductor.Router -import eu.kanade.presentation.browse.BrowseTab import eu.kanade.presentation.browse.ExtensionScreen import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.TabContent import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.base.controller.pushController @@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsControlle fun extensionsTab( router: Router?, presenter: ExtensionsPresenter, -) = BrowseTab( +) = TabContent( titleRes = R.string.label_extensions, badgeNumber = presenter.updates.takeIf { it > 0 }, actions = listOf( @@ -33,7 +33,7 @@ fun extensionsTab( AppBar.Action( title = stringResource(R.string.action_filter), - icon = Icons.Outlined.FilterList, + icon = Icons.Outlined.Translate, onClick = { router?.pushController(ExtensionFilterController()) }, ), ), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourcesTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourcesTab.kt index 123144c6d6..903197508f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourcesTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrateSourcesTab.kt @@ -6,9 +6,9 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import com.bluelinelabs.conductor.Router -import eu.kanade.presentation.browse.BrowseTab import eu.kanade.presentation.browse.MigrateSourceScreen import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.TabContent import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrationMangaController @@ -17,10 +17,10 @@ import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrationMangaController fun migrateSourcesTab( router: Router?, presenter: MigrationSourcesPresenter, -): BrowseTab { +): TabContent { val uriHandler = LocalUriHandler.current - return BrowseTab( + return TabContent( titleRes = R.string.label_migration, actions = listOf( AppBar.Action( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesTab.kt index 1ffefc3b6d..bf2503fad2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesTab.kt @@ -6,9 +6,9 @@ import androidx.compose.material.icons.outlined.TravelExplore import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.bluelinelabs.conductor.Router -import eu.kanade.presentation.browse.BrowseTab import eu.kanade.presentation.browse.SourcesScreen import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.TabContent import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController @@ -19,7 +19,7 @@ import eu.kanade.tachiyomi.ui.browse.source.latest.LatestUpdatesController fun sourcesTab( router: Router?, presenter: SourcesPresenter, -) = BrowseTab( +) = TabContent( titleRes = R.string.label_sources, actions = listOf( AppBar.Action(