From f91e66269fcd500797540a7858331f33783e20d5 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 8 Feb 2020 20:47:19 -0800 Subject: [PATCH] Added snack messages to show category is already in queue Also removed the weird enabling logic of the swipe refresh for categories --- .../data/library/LibraryUpdateService.kt | 13 +++++++++++- .../ui/library/LibraryCategoryView.kt | 21 +++++++++---------- app/src/main/res/values/strings.xml | 4 +++- 3 files changed, 25 insertions(+), 13 deletions(-) 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 7b01ebcec9..8631f15f0c 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 @@ -131,6 +131,10 @@ class LibraryUpdateService( private val mangaToUpdate = mutableListOf() + private val categoryIds = mutableSetOf() + + fun categoryInQueue(id: Int?) = categoryIds.contains(id) + /** * Key that defines what should be updated. */ @@ -158,7 +162,10 @@ class LibraryUpdateService( if (!isRunning(context)) { val intent = Intent(context, LibraryUpdateService::class.java).apply { putExtra(KEY_TARGET, target) - category?.let { putExtra(KEY_CATEGORY, it.id) } + category?.id?.let { id -> + putExtra(KEY_CATEGORY, id) + categoryIds.add(id) + } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { context.startService(intent) @@ -168,6 +175,7 @@ class LibraryUpdateService( } else { if (target == Target.CHAPTERS) category?.id?.let { + categoryIds.add(it) val preferences: PreferencesHelper = Injekt.get() val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault() addManga(getMangaToUpdate(it, target).sortedWith( @@ -206,6 +214,7 @@ class LibraryUpdateService( db.getLibraryMangas().executeAsBlocking().filter { it.category == categoryId } else { val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt) + categoryIds.addAll(categoriesToUpdate) if (categoriesToUpdate.isNotEmpty()) db.getLibraryMangas().executeAsBlocking() .filter { it.category in categoriesToUpdate } @@ -250,6 +259,7 @@ class LibraryUpdateService( override fun onDestroy() { subscription?.unsubscribe() mangaToUpdate.clear() + categoryIds.clear() if (wakeLock.isHeld) { wakeLock.release() } @@ -315,6 +325,7 @@ class LibraryUpdateService( job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) { updateChaptersJob() mangaToUpdate.clear() + categoryIds.clear() stopSelf(startId) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 32a48d92dc..305e42addf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -97,15 +97,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att swipe_refresh.addView(recycler) adapter.fastScroller = fast_scroller - recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { - override fun onScrollStateChanged(recycler: RecyclerView, newState: Int) { - // Disable swipe refresh when view is not at the top - val firstPos = (recycler.layoutManager as LinearLayoutManager) - .findFirstCompletelyVisibleItemPosition() - swipe_refresh.isEnabled = firstPos <= 0 && !preferences.hideCategories() - .getOrDefault() - } - }) fast_scroller.addOnScrollStateChangeListener { controller.lockFilterBar(it) } @@ -120,9 +111,17 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att // Double the distance required to trigger sync swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt()) swipe_refresh.setOnRefreshListener { - LibraryUpdateService.start(context, category) + val inQueue = LibraryUpdateService.categoryInQueue(category.id) controller.snack?.dismiss() - controller.snack = swipe_refresh.snack(R.string.updating_category) + controller.snack = swipe_refresh.snack( + resources.getString( + when { + inQueue -> R.string.category_already_in_queue + LibraryUpdateService.isRunning(context) -> R.string.adding_category_to_queue + else -> R.string.updating_category_x + }, category.name)) + if (!inQueue) + LibraryUpdateService.start(context, category) swipe_refresh.isRefreshing = false } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd40329347..e84d5bf8f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -374,7 +374,9 @@ Updating library - Updating category + Updating %1$s + Adding %1$s to update queue + %1$s is already in queue Local Remove from library?