From a73c847e3f1281205d9779b7081c6a36c05502e0 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 9 Apr 2020 00:50:22 -0400 Subject: [PATCH] Added Remove Downloads to manga details Collasaping downloads if theres no downloads when its not in view --- .../ui/manga/MangaDetailsController.kt | 28 ++++++++++++++++++- .../ui/manga/MangaDetailsPresenter.kt | 1 + .../tachiyomi/ui/recents/RecentsController.kt | 8 +++--- app/src/main/res/menu/manga_details.xml | 19 ++++++++++++- app/src/main/res/menu/manga_info.xml | 27 ------------------ app/src/main/res/values/strings.xml | 7 +++++ 6 files changed, 57 insertions(+), 33 deletions(-) delete mode 100644 app/src/main/res/menu/manga_info.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index f8f39d5cc0..ed0671216d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -690,6 +690,9 @@ class MangaDetailsController : BaseController, presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_unread).isVisible = !presenter.allUnread() && !presenter.isLockedFromSearch + menu.findItem(R.id.action_remove_downloads).isVisible = !presenter.isLockedFromSearch + menu.findItem(R.id.remove_non_bookmarked).isVisible = + presenter.hasBookmark() && !presenter.isLockedFromSearch menu.findItem(R.id.action_mark_all_as_unread).isVisible = presenter.isTracked() val iconPrimary = view?.context?.getResourceColor(android.R.attr.textColorPrimary) ?: Color.BLACK @@ -748,7 +751,6 @@ class MangaDetailsController : BaseController, } } R.id.action_open_in_web_view -> openInWebView() - R.id.action_share -> prepareToShareManga() R.id.action_add_to_home_screen -> addToHomeScreen() R.id.action_refresh_tracking -> presenter.refreshTrackers() R.id.action_mark_all_as_read -> { @@ -757,6 +759,7 @@ class MangaDetailsController : BaseController, markAsRead(presenter.chapters) }.negativeButton(android.R.string.cancel).show() } + R.id.remove_all, R.id.remove_read, R.id.remove_non_bookmarked -> massDeleteChapters(item.itemId) R.id.action_mark_all_as_unread -> markAsUnread(presenter.chapters) R.id.download_next, R.id.download_next_5, R.id.download_custom, R.id.download_unread, R.id.download_all -> downloadChapters( item.itemId @@ -825,6 +828,29 @@ class MangaDetailsController : BaseController, startActivity(intent) } + private fun massDeleteChapters(choice: Int) { + val chaptersToDelete = when (choice) { + R.id.remove_all -> presenter.chapters + R.id.remove_non_bookmarked -> presenter.chapters.filter { !it.bookmark } + R.id.remove_read -> presenter.chapters.filter { it.read } + else -> emptyList() + }.filter { it.isDownloaded } + if (chaptersToDelete.isNotEmpty()) { + massDeleteChapters(chaptersToDelete) + } + } + + private fun massDeleteChapters(chapters: List) { + val context = view?.context ?: return + MaterialDialog(context).message( + text = context.resources.getQuantityString( + R.plurals.remove_n_chapters, chapters.size, chapters.size + ) + ).positiveButton(R.string.remove) { + presenter.deleteChapters(chapters) + }.negativeButton(android.R.string.cancel).show() + } + private fun downloadChapters(choice: Int) { val chaptersToDownload = when (choice) { R.id.download_next -> presenter.getUnreadChaptersSorted().take(1) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index a9cdcbbdce..a2e43149fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -320,6 +320,7 @@ class MangaDetailsPresenter( } fun allUnread(): Boolean = chapters.none { it.read } + fun hasBookmark(): Boolean = chapters.any { it.bookmark } fun getUnreadChaptersSorted() = chapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name } 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 6e18381dce..be55d41004 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 @@ -349,6 +349,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), if (type.isEnter) { view?.applyWindowInsetsForRootController(activity!!.bottom_nav) if (type == ControllerChangeType.POP_ENTER) presenter.onCreate() + dl_bottom_sheet.dismiss() setHasOptionsMenu(true) } else { if (type == ControllerChangeType.POP_EXIT) presenter.onDestroy() @@ -362,10 +363,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), } override fun toggleSheet() { - if (dl_bottom_sheet.sheetBehavior?.isHideable == false) { - if (showingDownloads) dl_bottom_sheet.dismiss() - else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED - } + if (showingDownloads) dl_bottom_sheet.dismiss() + else if (dl_bottom_sheet.sheetBehavior?.isHideable == false) dl_bottom_sheet.sheetBehavior?.state = + BottomSheetBehavior.STATE_EXPANDED } override fun expandSearch() { diff --git a/app/src/main/res/menu/manga_details.xml b/app/src/main/res/menu/manga_details.xml index 82b90797d7..9c146dcd0e 100644 --- a/app/src/main/res/menu/manga_details.xml +++ b/app/src/main/res/menu/manga_details.xml @@ -48,8 +48,25 @@ android:id="@+id/action_refresh_tracking" android:icon="@drawable/ic_refresh_white_24dp" android:title="@string/refresh_tracking" - app:showAsAction="never" /> + app:showAsAction="never" /> + + + + + + + - - - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 357661ddb0..7b36ba9422 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,6 +48,10 @@ Marked as read Marked as unread Removed bookmark + + Remove %1$d downloaded chapter? + Remove %1$d downloaded chapters? + %1$d chapter %1$d chapters @@ -335,6 +339,8 @@ Custom range All chapters All unread chapters + All read chapters + All but bookmarked chapters Add %1$s to library? Show All Show bookmarked chapters @@ -527,6 +533,7 @@ Download Start downloading now Remove download + Remove downloads Downloading (%1$d/%2$d) Invalid download location Download paused