diff --git a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt index 451468eda..cd2d2c5bf 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt @@ -35,7 +35,7 @@ fun LibraryScreen( onClickSelectAll: () -> Unit, onClickInvertSelection: () -> Unit, onClickFilter: () -> Unit, - onClickRefresh: (Category?) -> Unit, + onClickRefresh: (Category?) -> Boolean, ) { val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) val insets = WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal) 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 436d0d335..01ffa141c 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 @@ -42,7 +42,7 @@ fun LibraryContent( onChangeCurrentPage: (Int) -> Unit, onMangaClicked: (Long) -> Unit, onToggleSelection: (LibraryManga) -> Unit, - onRefresh: (Category?) -> Unit, + onRefresh: (Category?) -> Boolean, onGlobalSearchClicked: () -> Unit, getNumberOfMangaForCategory: @Composable (Long) -> State, getDisplayModeForPage: @Composable (Int) -> State, @@ -84,7 +84,8 @@ fun LibraryContent( SwipeRefresh( state = rememberSwipeRefreshState(isRefreshing = isRefreshing), onRefresh = { - onRefresh(categories[currentPage()]) + val started = onRefresh(categories[currentPage()]) + if (!started) return@SwipeRefresh scope.launch { // Fake refresh status but hide it after a second as it's a long running task isRefreshing = true 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 18a2e3bb1..310687e89 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -83,9 +83,9 @@ fun UpdateScreen( val context = LocalContext.current val onUpdateLibrary = { - if (LibraryUpdateService.start(context)) { - context.toast(R.string.updating_library) - } + val started = LibraryUpdateService.start(context) + context.toast(if (started) R.string.updating_library else R.string.update_already_running) + started } val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) @@ -97,7 +97,7 @@ fun UpdateScreen( UpdatesAppBar( incognitoMode = presenter.isIncognitoMode, downloadedOnlyMode = presenter.isDownloadOnly, - onUpdateLibrary = onUpdateLibrary, + onUpdateLibrary = { onUpdateLibrary() }, actionModeCounter = presenter.selected.size, onSelectAll = { presenter.toggleAllSelection(true) }, onInvertSelection = { presenter.invertSelection() }, @@ -132,7 +132,8 @@ fun UpdateScreen( SwipeRefresh( state = rememberSwipeRefreshState(isRefreshing = isRefreshing), onRefresh = { - onUpdateLibrary() + 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 4966fe243..849d5ab5f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -154,18 +154,15 @@ class LibraryUpdateService( * @return true if service newly started, false otherwise */ fun start(context: Context, category: Category? = null, target: Target = Target.CHAPTERS): Boolean { - return if (!isRunning(context)) { - val intent = Intent(context, LibraryUpdateService::class.java).apply { - putExtra(KEY_TARGET, target) - category?.let { putExtra(KEY_CATEGORY, it.id) } - } - ContextCompat.startForegroundService(context, intent) + if (isRunning(context)) return false - true - } else { - instance?.addMangaToQueue(category?.id ?: -1) - false + val intent = Intent(context, LibraryUpdateService::class.java).apply { + putExtra(KEY_TARGET, target) + category?.let { putExtra(KEY_CATEGORY, it.id) } } + ContextCompat.startForegroundService(context, intent) + + return true } /** 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 d02a51b31..4edd4eb9b 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 @@ -57,9 +57,9 @@ class LibraryController( onDeleteClicked = ::showDeleteMangaDialog, onClickFilter = ::showSettingsSheet, onClickRefresh = { - if (LibraryUpdateService.start(context, it)) { - context.toast(R.string.updating_library) - } + val started = LibraryUpdateService.start(context, it) + context.toast(if (started) R.string.updating_library else R.string.update_already_running) + started }, onClickInvertSelection = { presenter.invertSelection(presenter.activeCategory) }, onClickSelectAll = { presenter.selectAll(presenter.activeCategory) }, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e65e818f0..cf6914ca5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -729,6 +729,7 @@ Updating library + An update is already running Unable to open last read chapter