Fix notification and add visual cues when triggering a second update (#7783)

(cherry picked from commit 1f34f5277c9500e6a3a8069738a0eeeaf8c49ef5)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt
#	app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt
This commit is contained in:
stevenyomi 2022-08-18 21:01:10 +08:00 committed by Jobobby04
parent 5c2d07d14d
commit 128a868ffb
6 changed files with 36 additions and 37 deletions

View File

@ -36,7 +36,7 @@ fun LibraryScreen(
onClickSelectAll: () -> Unit,
onClickInvertSelection: () -> Unit,
onClickFilter: () -> Unit,
onClickRefresh: (Category?) -> Unit,
onClickRefresh: (Category?) -> Boolean,
// SY -->
onClickCleanTitles: () -> Unit,
onClickMigrate: () -> Unit,

View File

@ -45,7 +45,7 @@ fun LibraryContent(
onChangeCurrentPage: (Int) -> Unit,
onMangaClicked: (Long) -> Unit,
onToggleSelection: (LibraryManga) -> Unit,
onRefresh: (Category?) -> Unit,
onRefresh: (Category?) -> Boolean,
onGlobalSearchClicked: () -> Unit,
getNumberOfMangaForCategory: @Composable (Long) -> State<Int?>,
getDisplayModeForPage: @Composable (Int) -> State<DisplayModeSetting>,
@ -99,7 +99,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

View File

@ -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

View File

@ -193,22 +193,19 @@ class LibraryUpdateService(
* @return true if service newly started, false otherwise
*/
fun start(context: Context, category: Category? = null, target: Target = Target.CHAPTERS /* SY --> */, group: Int = LibraryGroup.BY_DEFAULT, groupExtra: String? = null /* SY <-- */): Boolean {
return if (!isRunning(context)) {
val intent = Intent(context, LibraryUpdateService::class.java).apply {
putExtra(KEY_TARGET, target)
category?.let { putExtra(KEY_CATEGORY, it.id) }
// SY -->
putExtra(KEY_GROUP, group)
groupExtra?.let { putExtra(KEY_GROUP_EXTRA, it) }
// SY <--
}
ContextCompat.startForegroundService(context, intent)
if (isRunning(context)) return false
true
} else {
instance?.addMangaToQueue(category?.id ?: -1, group, groupExtra)
false
val intent = Intent(context, LibraryUpdateService::class.java).apply {
putExtra(KEY_TARGET, target)
category?.let { putExtra(KEY_CATEGORY, it.id) }
// SY -->
putExtra(KEY_GROUP, group)
groupExtra?.let { putExtra(KEY_GROUP_EXTRA, it) }
// SY <--
}
ContextCompat.startForegroundService(context, intent)
return true
}
/**

View File

@ -93,21 +93,20 @@ class LibraryController(
onClickRefresh = {
// SY -->
val groupType = presenter.groupType
if (
LibraryUpdateService.start(
context = context,
category = if (groupType == LibraryGroup.BY_DEFAULT) it else null,
group = groupType,
groupExtra = when (groupType) {
LibraryGroup.BY_DEFAULT -> null
LibraryGroup.BY_SOURCE, LibraryGroup.BY_STATUS, LibraryGroup.BY_TRACK_STATUS -> it?.id?.toString()
else -> null
},
)
) {
// SY <--
context.toast(R.string.updating_library)
}
// SY -->
val started = LibraryUpdateService.start(
context = context,
category = if (groupType == LibraryGroup.BY_DEFAULT) it else null,
group = groupType,
groupExtra = when (groupType) {
LibraryGroup.BY_DEFAULT -> null
LibraryGroup.BY_SOURCE, LibraryGroup.BY_STATUS, LibraryGroup.BY_TRACK_STATUS -> it?.id?.toString()
else -> null
},
)
// SY <--
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) },

View File

@ -729,6 +729,7 @@
<!-- Updates fragment -->
<string name="updating_library">Updating library</string>
<string name="update_already_running">An update is already running</string>
<string name="cant_open_last_read_chapter">Unable to open last read chapter</string>
<!-- History fragment -->