From 2e4af90b63464535711573914545afd6fba05f98 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 30 Apr 2020 00:29:39 -0400 Subject: [PATCH] Readded refresh button for single category libraries Long pressing the library icon now updates the ui on library and recents --- .../data/library/LibraryUpdateService.kt | 18 ++++++++++-------- .../tachiyomi/ui/library/LibraryHeaderItem.kt | 2 +- .../tachiyomi/ui/recents/RecentsController.kt | 2 +- .../tachiyomi/ui/recents/RecentsPresenter.kt | 9 +++++++-- 4 files changed, 19 insertions(+), 12 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 b46ba1f262..b86b388d19 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 @@ -241,13 +241,14 @@ class LibraryUpdateService( } else { val categoriesToUpdate = preferences.libraryUpdateCategories().getOrDefault().map(String::toInt) - categoryIds.addAll(categoriesToUpdate) - if (categoriesToUpdate.isNotEmpty()) + if (categoriesToUpdate.isNotEmpty()) { + categoryIds.addAll(categoriesToUpdate) db.getLibraryMangas().executeAsBlocking() - .filter { it.category in categoriesToUpdate } - .distinctBy { it.id } - else + .filter { it.category in categoriesToUpdate }.distinctBy { it.id } + } else { + categoryIds.addAll(db.getCategories().executeAsBlocking().mapNotNull { it.id } + 0) db.getLibraryMangas().executeAsBlocking().distinctBy { it.id } + } } if (target == Target.CHAPTERS && preferences.updateOnlyNonCompleted()) { listToUpdate = listToUpdate.filter { it.status != SManga.COMPLETED } @@ -339,12 +340,13 @@ class LibraryUpdateService( Timber.e(exception) stopSelf(startId) } - if (target == Target.CHAPTERS) { - job = GlobalScope.launch(handler) { + job = if (target == Target.CHAPTERS) { + listener?.onUpdateManga(LibraryManga()) + GlobalScope.launch(handler) { updateChaptersJob(mangaToAdd) } } else { - job = GlobalScope.launch(handler) { + GlobalScope.launch(handler) { updateTrackings(mangaToAdd) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt index b94fb85742..045f5eef50 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt @@ -154,7 +154,7 @@ class LibraryHeaderItem( else -> { catProgress.gone() checkboxImage.gone() - updateButton.visInvisIf(!(category.isFirst == true && category.isLast == true)) + updateButton.visInvisIf(category.id ?: 0 > -1) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 2ce9f77cb4..b9d9126cf1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -204,7 +204,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) } - fun reEnableSwipe() { + fun setRefreshing(refresh: Boolean) { swipe_refresh.isRefreshing = false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index 58f39ff26b..96be9624d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -242,8 +242,13 @@ class RecentsPresenter( } override fun onUpdateManga(manga: LibraryManga) { - if (manga.id == null) scope.launch(Dispatchers.Main) { controller.reEnableSwipe() } - else getRecents() + if (manga.id == null && !LibraryUpdateService.isRunning()) { + scope.launch(Dispatchers.Main) { controller.setRefreshing(false) } + } else if (manga.id == null) { + scope.launch(Dispatchers.Main) { controller.setRefreshing(true) } + } else { + getRecents() + } } /**