From 0e3176a77c925bb7f9d9f87bf68476563f9b9e9e Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 18 Sep 2022 22:38:44 -0400 Subject: [PATCH] Clean up UpdatesController - Move loading state into scaffold (closes #7704) - Move logic into presenter - Make some composables private --- .../browse/ExtensionDetailsScreen.kt | 2 +- .../browse/ExtensionFilterScreen.kt | 4 +- .../presentation/browse/ExtensionsScreen.kt | 14 +- .../presentation/browse/MigrateMangaScreen.kt | 4 +- .../browse/MigrateSourceScreen.kt | 4 +- .../browse/SourcesFilterScreen.kt | 6 +- .../presentation/browse/SourcesScreen.kt | 10 +- .../presentation/updates/UpdatesScreen.kt | 155 ++++++++++-------- .../presentation/webview/WebViewScreen.kt | 4 +- .../tachiyomi/ui/library/LibraryController.kt | 5 +- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../ui/recent/updates/UpdatesController.kt | 69 ++------ .../ui/recent/updates/UpdatesPresenter.kt | 33 +++- .../tachiyomi/ui/webview/WebViewActivity.kt | 2 +- 14 files changed, 159 insertions(+), 155 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt index 0cf5e57d2..ca063b2e0 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionDetailsScreen.kt @@ -406,7 +406,7 @@ private fun SourceSwitchPreference( } @Composable -fun NsfwWarningDialog( +private fun NsfwWarningDialog( onClickConfirm: () -> Unit, ) { AlertDialog( diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionFilterScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionFilterScreen.kt index 8d85d7fdf..c913dc3fe 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionFilterScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionFilterScreen.kt @@ -61,7 +61,7 @@ fun ExtensionFilterScreen( } @Composable -fun SourceFilterContent( +private fun SourceFilterContent( contentPadding: PaddingValues, state: ExtensionFilterState, onClickLang: (String) -> Unit, @@ -83,7 +83,7 @@ fun SourceFilterContent( } @Composable -fun ExtensionFilterItem( +private fun ExtensionFilterItem( modifier: Modifier, lang: String, enabled: Boolean, diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt index 5f4f314f9..936f57b29 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt @@ -91,7 +91,7 @@ fun ExtensionScreen( } @Composable -fun ExtensionContent( +private fun ExtensionContent( state: ExtensionsState, onLongClickItem: (Extension) -> Unit, onClickItemCancel: (Extension) -> Unit, @@ -201,7 +201,7 @@ fun ExtensionContent( } @Composable -fun ExtensionItem( +private fun ExtensionItem( modifier: Modifier = Modifier, item: ExtensionUiModel.Item, onClickItem: (Extension) -> Unit, @@ -238,7 +238,7 @@ fun ExtensionItem( } @Composable -fun ExtensionItemContent( +private fun ExtensionItemContent( extension: Extension, modifier: Modifier = Modifier, ) { @@ -294,7 +294,7 @@ fun ExtensionItemContent( } @Composable -fun ExtensionItemActions( +private fun ExtensionItemActions( extension: Extension, installStep: InstallStep, modifier: Modifier = Modifier, @@ -348,7 +348,7 @@ fun ExtensionItemActions( } @Composable -fun ExtensionHeader( +private fun ExtensionHeader( @StringRes textRes: Int, modifier: Modifier = Modifier, action: @Composable RowScope.() -> Unit = {}, @@ -361,7 +361,7 @@ fun ExtensionHeader( } @Composable -fun ExtensionHeader( +private fun ExtensionHeader( text: String, modifier: Modifier = Modifier, action: @Composable RowScope.() -> Unit = {}, @@ -382,7 +382,7 @@ fun ExtensionHeader( } @Composable -fun ExtensionTrustDialog( +private fun ExtensionTrustDialog( onClickConfirm: () -> Unit, onClickDismiss: () -> Unit, onDismissRequest: () -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateMangaScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateMangaScreen.kt index 7dbf09899..d4025571f 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateMangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateMangaScreen.kt @@ -62,7 +62,7 @@ fun MigrateMangaScreen( } @Composable -fun MigrateMangaContent( +private fun MigrateMangaContent( contentPadding: PaddingValues, state: MigrateMangaState, onClickItem: (Manga) -> Unit, @@ -82,7 +82,7 @@ fun MigrateMangaContent( } @Composable -fun MigrateMangaItem( +private fun MigrateMangaItem( modifier: Modifier = Modifier, manga: Manga, onClickItem: (Manga) -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt index be6fd1cfd..9b14dc70e 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSourceScreen.kt @@ -70,7 +70,7 @@ fun MigrateSourceScreen( } @Composable -fun MigrateSourceList( +private fun MigrateSourceList( list: List>, onClickItem: (Source) -> Unit, onLongClickItem: (Source) -> Unit, @@ -126,7 +126,7 @@ fun MigrateSourceList( } @Composable -fun MigrateSourceItem( +private fun MigrateSourceItem( modifier: Modifier = Modifier, source: Source, count: Long, diff --git a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt index 7940b47a9..56e1c3d66 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesFilterScreen.kt @@ -66,7 +66,7 @@ fun SourcesFilterScreen( } @Composable -fun SourcesFilterContent( +private fun SourcesFilterContent( contentPadding: PaddingValues, state: SourcesFilterState, onClickLang: (String) -> Unit, @@ -111,7 +111,7 @@ fun SourcesFilterContent( } @Composable -fun SourcesFilterHeader( +private fun SourcesFilterHeader( modifier: Modifier, language: String, enabled: Boolean, @@ -128,7 +128,7 @@ fun SourcesFilterHeader( } @Composable -fun SourcesFilterItem( +private fun SourcesFilterItem( modifier: Modifier, source: Source, enabled: Boolean, 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 0720594c9..94b7b45b5 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/SourcesScreen.kt @@ -75,7 +75,7 @@ fun SourcesScreen( } @Composable -fun SourceList( +private fun SourceList( state: SourcesState, onClickItem: (Source, String) -> Unit, onClickDisable: (Source) -> Unit, @@ -135,7 +135,7 @@ fun SourceList( } @Composable -fun SourceHeader( +private fun SourceHeader( modifier: Modifier = Modifier, language: String, ) { @@ -149,7 +149,7 @@ fun SourceHeader( } @Composable -fun SourceItem( +private fun SourceItem( modifier: Modifier = Modifier, source: Source, onClickItem: (Source, String) -> Unit, @@ -181,7 +181,7 @@ fun SourceItem( } @Composable -fun SourcePinButton( +private fun SourcePinButton( isPinned: Boolean, onClick: () -> Unit, ) { @@ -197,7 +197,7 @@ fun SourcePinButton( } @Composable -fun SourceOptionsDialog( +private fun SourceOptionsDialog( source: Source, onClickPin: () -> Unit, onClickDisable: () -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt index e22589fe1..1ec5c15d1 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -30,6 +30,7 @@ import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.ChapterDownloadAction import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.LazyColumn +import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.components.MangaBottomActionMenu import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.SwipeRefreshIndicator @@ -55,10 +56,7 @@ fun UpdateScreen( presenter: UpdatesPresenter, onClickCover: (UpdatesItem) -> Unit, onBackClicked: () -> Unit, - onDownloadChapter: (List, ChapterDownloadAction) -> Unit, ) { - val updatesListState = rememberLazyListState() - val internalOnBackPressed = { if (presenter.selectionMode) { presenter.toggleAllSelection(false) @@ -69,7 +67,6 @@ fun UpdateScreen( BackHandler(onBack = internalOnBackPressed) val context = LocalContext.current - val onUpdateLibrary = { val started = LibraryUpdateService.start(context) context.toast(if (started) R.string.updating_library else R.string.update_already_running) @@ -92,7 +89,7 @@ fun UpdateScreen( bottomBar = { UpdatesBottomBar( selected = presenter.selected, - onDownloadChapter = onDownloadChapter, + onDownloadChapter = presenter::downloadChapters, onMultiBookmarkClicked = presenter::bookmarkUpdates, onMultiMarkAsReadClicked = presenter::markUpdatesRead, onMultiDeleteClicked = { @@ -102,69 +99,93 @@ fun UpdateScreen( ) }, ) { contentPadding -> - // During selection mode bottom nav is not visible - val contentPaddingWithNavBar = contentPadding + - if (presenter.selectionMode) { - PaddingValues() - } else { - bottomNavPaddingValues - } - - val scope = rememberCoroutineScope() - var isRefreshing by remember { mutableStateOf(false) } - - SwipeRefresh( - state = rememberSwipeRefreshState(isRefreshing = isRefreshing), - onRefresh = { - val started = onUpdateLibrary() - if (!started) return@SwipeRefresh - scope.launch { - // Fake refresh status but hide it after a second as it's a long running task - isRefreshing = true - delay(1000) - isRefreshing = false - } - }, - swipeEnabled = presenter.selectionMode.not(), - indicatorPadding = contentPaddingWithNavBar, - indicator = { s, trigger -> - SwipeRefreshIndicator( - state = s, - refreshTriggerDistance = trigger, + when { + presenter.isLoading -> LoadingScreen() + presenter.uiModels.isEmpty() -> EmptyScreen(textResource = R.string.information_no_recent) + else -> { + UpdateScreenContent( + presenter = presenter, + contentPadding = contentPadding, + onUpdateLibrary = onUpdateLibrary, + onClickCover = onClickCover, ) - }, - ) { - if (presenter.uiModels.isEmpty()) { - EmptyScreen(textResource = R.string.information_no_recent) - } else { - VerticalFastScroller( - listState = updatesListState, - topContentPadding = contentPaddingWithNavBar.calculateTopPadding(), - endContentPadding = contentPaddingWithNavBar.calculateEndPadding(LocalLayoutDirection.current), - ) { - LazyColumn( - modifier = Modifier.fillMaxHeight(), - state = updatesListState, - contentPadding = contentPaddingWithNavBar, - ) { - if (presenter.lastUpdated > 0L) { - updatesLastUpdatedItem(presenter.lastUpdated) - } + } + } + } +} - updatesUiItems( - uiModels = presenter.uiModels, - selectionMode = presenter.selectionMode, - onUpdateSelected = presenter::toggleSelection, - onClickCover = onClickCover, - onClickUpdate = { - val intent = ReaderActivity.newIntent(context, it.update.mangaId, it.update.chapterId) - context.startActivity(intent) - }, - onDownloadChapter = onDownloadChapter, - relativeTime = presenter.relativeTime, - dateFormat = presenter.dateFormat, - ) +@Composable +private fun UpdateScreenContent( + presenter: UpdatesPresenter, + contentPadding: PaddingValues, + onUpdateLibrary: () -> Boolean, + onClickCover: (UpdatesItem) -> Unit, +) { + val context = LocalContext.current + val updatesListState = rememberLazyListState() + + // During selection mode bottom nav is not visible + val contentPaddingWithNavBar = contentPadding + + if (presenter.selectionMode) { + PaddingValues() + } else { + bottomNavPaddingValues + } + + val scope = rememberCoroutineScope() + var isRefreshing by remember { mutableStateOf(false) } + + SwipeRefresh( + state = rememberSwipeRefreshState(isRefreshing = isRefreshing), + onRefresh = { + val started = onUpdateLibrary() + if (!started) return@SwipeRefresh + scope.launch { + // Fake refresh status but hide it after a second as it's a long running task + isRefreshing = true + delay(1000) + isRefreshing = false + } + }, + swipeEnabled = presenter.selectionMode.not(), + indicatorPadding = contentPaddingWithNavBar, + indicator = { s, trigger -> + SwipeRefreshIndicator( + state = s, + refreshTriggerDistance = trigger, + ) + }, + ) { + if (presenter.uiModels.isEmpty()) { + EmptyScreen(textResource = R.string.information_no_recent) + } else { + VerticalFastScroller( + listState = updatesListState, + topContentPadding = contentPaddingWithNavBar.calculateTopPadding(), + endContentPadding = contentPaddingWithNavBar.calculateEndPadding(LocalLayoutDirection.current), + ) { + LazyColumn( + modifier = Modifier.fillMaxHeight(), + state = updatesListState, + contentPadding = contentPaddingWithNavBar, + ) { + if (presenter.lastUpdated > 0L) { + updatesLastUpdatedItem(presenter.lastUpdated) } + + updatesUiItems( + uiModels = presenter.uiModels, + selectionMode = presenter.selectionMode, + onUpdateSelected = presenter::toggleSelection, + onClickCover = onClickCover, + onClickUpdate = { + val intent = ReaderActivity.newIntent(context, it.update.mangaId, it.update.chapterId) + context.startActivity(intent) + }, + onDownloadChapter = presenter::downloadChapters, + relativeTime = presenter.relativeTime, + dateFormat = presenter.dateFormat, + ) } } } @@ -193,7 +214,7 @@ fun UpdateScreen( } @Composable -fun UpdatesAppBar( +private fun UpdatesAppBar( modifier: Modifier = Modifier, incognitoMode: Boolean, downloadedOnlyMode: Boolean, @@ -239,7 +260,7 @@ fun UpdatesAppBar( } @Composable -fun UpdatesBottomBar( +private fun UpdatesBottomBar( selected: List, onDownloadChapter: (List, ChapterDownloadAction) -> Unit, onMultiBookmarkClicked: (List, bookmark: Boolean) -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/webview/WebViewScreen.kt b/app/src/main/java/eu/kanade/presentation/webview/WebViewScreen.kt index 297e4223e..5569440cd 100644 --- a/app/src/main/java/eu/kanade/presentation/webview/WebViewScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/webview/WebViewScreen.kt @@ -30,7 +30,7 @@ import eu.kanade.tachiyomi.util.system.setDefaultSettings @Composable fun WebViewScreen( - onUp: () -> Unit, + onNavigateUp: () -> Unit, initialTitle: String?, url: String, headers: Map = emptyMap(), @@ -47,7 +47,7 @@ fun WebViewScreen( AppBar( title = state.pageTitle ?: initialTitle, subtitle = state.content.getCurrentUrl(), - navigateUp = onUp, + navigateUp = onNavigateUp, navigationIcon = Icons.Default.Close, actions = { AppBarActions( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 95be196e8..f044c188a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -95,14 +95,13 @@ class LibraryController( } LaunchedEffect(presenter.selectionMode) { - val activity = (activity as? MainActivity) ?: return@LaunchedEffect // Could perhaps be removed when navigation is in a Compose world if (router.backstackSize == 1) { - activity.showBottomNav(presenter.selectionMode.not()) + (activity as? MainActivity)?.showBottomNav(presenter.selectionMode.not()) } } LaunchedEffect(presenter.isLoading) { - if (presenter.isLoading.not()) { + if (!presenter.isLoading) { (activity as? MainActivity)?.ready = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index b7cf7c2a3..c8e4f7e4a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -195,7 +195,7 @@ class MangaController : FullComposeController { } } - // Let compose view handle this + // Let Compose view handle this override fun handleBack(): Boolean { val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false return if (dispatcher.hasEnabledCallbacks()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 4322a9175..3928eab70 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -1,24 +1,15 @@ package eu.kanade.tachiyomi.ui.recent.updates import androidx.activity.OnBackPressedDispatcherOwner -import androidx.compose.animation.Crossfade import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import eu.kanade.presentation.components.ChapterDownloadAction -import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.updates.UpdateScreen -import eu.kanade.tachiyomi.data.download.DownloadService -import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.base.controller.FullComposeController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController -import kotlinx.coroutines.launch -/** - * Fragment that shows recent chapters. - */ class UpdatesController : FullComposeController(), RootController { @@ -27,32 +18,26 @@ class UpdatesController : @Composable override fun ComposeContent() { - Crossfade(targetState = presenter.isLoading) { isLoading -> - if (isLoading) { - LoadingScreen() - } else { - UpdateScreen( - presenter = presenter, - onClickCover = { item -> - router.pushController(MangaController(item.update.mangaId)) - }, - onBackClicked = this::onBackClicked, - onDownloadChapter = this::downloadChapters, - ) - } - } + UpdateScreen( + presenter = presenter, + onClickCover = { item -> + router.pushController(MangaController(item.update.mangaId)) + }, + onBackClicked = { + (activity as? MainActivity)?.moveToStartScreen() + }, + ) LaunchedEffect(presenter.selectionMode) { - val activity = (activity as? MainActivity) ?: return@LaunchedEffect - activity.showBottomNav(presenter.selectionMode.not()) + (activity as? MainActivity)?.showBottomNav(presenter.selectionMode.not()) } LaunchedEffect(presenter.isLoading) { - if (presenter.isLoading.not()) { + if (!presenter.isLoading) { (activity as? MainActivity)?.ready = true } } } - // Let compose view handle this + // Let Compose view handle this override fun handleBack(): Boolean { val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false return if (dispatcher.hasEnabledCallbacks()) { @@ -62,34 +47,4 @@ class UpdatesController : false } } - - private fun onBackClicked() { - (activity as? MainActivity)?.moveToStartScreen() - } - - private fun downloadChapters(items: List, action: ChapterDownloadAction) { - if (items.isEmpty()) return - viewScope.launch { - when (action) { - ChapterDownloadAction.START -> { - presenter.downloadChapters(items) - if (items.any { it.downloadStateProvider() == Download.State.ERROR }) { - DownloadService.start(activity!!) - } - } - ChapterDownloadAction.START_NOW -> { - val chapterId = items.singleOrNull()?.update?.chapterId ?: return@launch - presenter.startDownloadingNow(chapterId) - } - ChapterDownloadAction.CANCEL -> { - val chapterId = items.singleOrNull()?.update?.chapterId ?: return@launch - presenter.cancelDownload(chapterId) - } - ChapterDownloadAction.DELETE -> { - presenter.deleteChapters(items) - } - } - presenter.toggleAllSelection(false) - } - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index 172388d43..098a82b10 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -13,10 +13,12 @@ import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.updates.interactor.GetUpdates import eu.kanade.domain.updates.model.UpdatesWithRelations +import eu.kanade.presentation.components.ChapterDownloadAction import eu.kanade.presentation.updates.UpdatesState import eu.kanade.presentation.updates.UpdatesStateImpl import eu.kanade.presentation.updates.UpdatesUiModel import eu.kanade.tachiyomi.data.download.DownloadManager +import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.SourceManager @@ -33,6 +35,7 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.receiveAsFlow +import kotlinx.coroutines.launch import logcat.LogPriority import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -178,11 +181,37 @@ class UpdatesPresenter( } } - fun startDownloadingNow(chapterId: Long) { + fun downloadChapters(items: List, action: ChapterDownloadAction) { + if (items.isEmpty()) return + presenterScope.launch { + when (action) { + ChapterDownloadAction.START -> { + downloadChapters(items) + if (items.any { it.downloadStateProvider() == Download.State.ERROR }) { + DownloadService.start(view!!.activity!!) + } + } + ChapterDownloadAction.START_NOW -> { + val chapterId = items.singleOrNull()?.update?.chapterId ?: return@launch + startDownloadingNow(chapterId) + } + ChapterDownloadAction.CANCEL -> { + val chapterId = items.singleOrNull()?.update?.chapterId ?: return@launch + cancelDownload(chapterId) + } + ChapterDownloadAction.DELETE -> { + deleteChapters(items) + } + } + toggleAllSelection(false) + } + } + + private fun startDownloadingNow(chapterId: Long) { downloadManager.startDownloadNow(chapterId) } - fun cancelDownload(chapterId: Long) { + private fun cancelDownload(chapterId: Long) { val activeDownload = downloadManager.queue.find { chapterId == it.chapter.id } ?: return downloadManager.deletePendingDownload(activeDownload) updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED }) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index 571587e03..282b5d27d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -45,7 +45,7 @@ class WebViewActivity : BaseActivity() { setComposeContent { WebViewScreen( - onUp = { finish() }, + onNavigateUp = { finish() }, initialTitle = intent.extras?.getString(TITLE_KEY), url = url, headers = headers,