Added Remove Downloads to manga details

Collasaping downloads if theres no downloads when its not in view
This commit is contained in:
Jay 2020-04-09 00:50:22 -04:00
parent 05428b308f
commit a73c847e3f
6 changed files with 57 additions and 33 deletions

View File

@ -690,6 +690,9 @@ class MangaDetailsController : BaseController,
presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch presenter.getNextUnreadChapter() != null && !presenter.isLockedFromSearch
menu.findItem(R.id.action_mark_all_as_unread).isVisible = menu.findItem(R.id.action_mark_all_as_unread).isVisible =
!presenter.allUnread() && !presenter.isLockedFromSearch !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() menu.findItem(R.id.action_mark_all_as_unread).isVisible = presenter.isTracked()
val iconPrimary = view?.context?.getResourceColor(android.R.attr.textColorPrimary) val iconPrimary = view?.context?.getResourceColor(android.R.attr.textColorPrimary)
?: Color.BLACK ?: Color.BLACK
@ -748,7 +751,6 @@ class MangaDetailsController : BaseController,
} }
} }
R.id.action_open_in_web_view -> openInWebView() R.id.action_open_in_web_view -> openInWebView()
R.id.action_share -> prepareToShareManga()
R.id.action_add_to_home_screen -> addToHomeScreen() R.id.action_add_to_home_screen -> addToHomeScreen()
R.id.action_refresh_tracking -> presenter.refreshTrackers() R.id.action_refresh_tracking -> presenter.refreshTrackers()
R.id.action_mark_all_as_read -> { R.id.action_mark_all_as_read -> {
@ -757,6 +759,7 @@ class MangaDetailsController : BaseController,
markAsRead(presenter.chapters) markAsRead(presenter.chapters)
}.negativeButton(android.R.string.cancel).show() }.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.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( R.id.download_next, R.id.download_next_5, R.id.download_custom, R.id.download_unread, R.id.download_all -> downloadChapters(
item.itemId item.itemId
@ -825,6 +828,29 @@ class MangaDetailsController : BaseController,
startActivity(intent) 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<ChapterItem>) {
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) { private fun downloadChapters(choice: Int) {
val chaptersToDownload = when (choice) { val chaptersToDownload = when (choice) {
R.id.download_next -> presenter.getUnreadChaptersSorted().take(1) R.id.download_next -> presenter.getUnreadChaptersSorted().take(1)

View File

@ -320,6 +320,7 @@ class MangaDetailsPresenter(
} }
fun allUnread(): Boolean = chapters.none { it.read } fun allUnread(): Boolean = chapters.none { it.read }
fun hasBookmark(): Boolean = chapters.any { it.bookmark }
fun getUnreadChaptersSorted() = fun getUnreadChaptersSorted() =
chapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name } chapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name }

View File

@ -349,6 +349,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
if (type.isEnter) { if (type.isEnter) {
view?.applyWindowInsetsForRootController(activity!!.bottom_nav) view?.applyWindowInsetsForRootController(activity!!.bottom_nav)
if (type == ControllerChangeType.POP_ENTER) presenter.onCreate() if (type == ControllerChangeType.POP_ENTER) presenter.onCreate()
dl_bottom_sheet.dismiss()
setHasOptionsMenu(true) setHasOptionsMenu(true)
} else { } else {
if (type == ControllerChangeType.POP_EXIT) presenter.onDestroy() if (type == ControllerChangeType.POP_EXIT) presenter.onDestroy()
@ -362,10 +363,9 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
} }
override fun toggleSheet() { override fun toggleSheet() {
if (dl_bottom_sheet.sheetBehavior?.isHideable == false) { if (showingDownloads) dl_bottom_sheet.dismiss()
if (showingDownloads) dl_bottom_sheet.dismiss() else if (dl_bottom_sheet.sheetBehavior?.isHideable == false) dl_bottom_sheet.sheetBehavior?.state =
else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED BottomSheetBehavior.STATE_EXPANDED
}
} }
override fun expandSearch() { override fun expandSearch() {

View File

@ -48,8 +48,25 @@
android:id="@+id/action_refresh_tracking" android:id="@+id/action_refresh_tracking"
android:icon="@drawable/ic_refresh_white_24dp" android:icon="@drawable/ic_refresh_white_24dp"
android:title="@string/refresh_tracking" android:title="@string/refresh_tracking"
app:showAsAction="never" />
app:showAsAction="never" />
<item
android:id="@+id/action_remove_downloads"
android:icon="@drawable/ic_file_download_white_24dp"
android:title="@string/remove_downloads"
app:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/remove_all"
android:title="@string/all_chapters" />
<item
android:id="@+id/remove_non_bookmarked"
android:title="@string/all_but_bookmarked_chapters" />
<item
android:id="@+id/remove_read"
android:title="@string/all_read_chapters" />
</menu>
</item>
<item <item
android:id="@+id/action_edit" android:id="@+id/action_edit"
android:icon="@drawable/ic_edit_white_24dp" android:icon="@drawable/ic_edit_white_24dp"

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_edit"
android:icon="@drawable/ic_edit_white_24dp"
android:title="@string/edit"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_share_white_24dp"
android:title="@string/share"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_open_in_web_view"
android:title="@string/open_in_web_view"
app:showAsAction="never" />
<item
android:id="@+id/action_add_to_home_screen"
android:title="@string/add_to_home_screen"
app:showAsAction="never" />
</menu>

View File

@ -48,6 +48,10 @@
<string name="marked_as_read">Marked as read</string> <string name="marked_as_read">Marked as read</string>
<string name="marked_as_unread">Marked as unread</string> <string name="marked_as_unread">Marked as unread</string>
<string name="removed_bookmark">Removed bookmark</string> <string name="removed_bookmark">Removed bookmark</string>
<plurals name="remove_n_chapters">
<item quantity="one">Remove %1$d downloaded chapter?</item>
<item quantity="other">Remove %1$d downloaded chapters?</item>
</plurals>
<plurals name="chapters"> <plurals name="chapters">
<item quantity="one">%1$d chapter</item> <item quantity="one">%1$d chapter</item>
<item quantity="other">%1$d chapters</item> <item quantity="other">%1$d chapters</item>
@ -335,6 +339,8 @@
<string name="custom_range">Custom range</string> <string name="custom_range">Custom range</string>
<string name="all_chapters">All chapters</string> <string name="all_chapters">All chapters</string>
<string name="all_unread_chapters">All unread chapters</string> <string name="all_unread_chapters">All unread chapters</string>
<string name="all_read_chapters">All read chapters</string>
<string name="all_but_bookmarked_chapters">All but bookmarked chapters</string>
<string name="add_x_to_library">Add %1$s to library?</string> <string name="add_x_to_library">Add %1$s to library?</string>
<string name="show_all">Show All</string> <string name="show_all">Show All</string>
<string name="show_bookmarked_chapters">Show bookmarked chapters</string> <string name="show_bookmarked_chapters">Show bookmarked chapters</string>
@ -527,6 +533,7 @@
<string name="download">Download</string> <string name="download">Download</string>
<string name="start_downloading_now">Start downloading now</string> <string name="start_downloading_now">Start downloading now</string>
<string name="remove_download">Remove download</string> <string name="remove_download">Remove download</string>
<string name="remove_downloads">Remove downloads</string>
<string name="downloading_progress">Downloading (%1$d/%2$d)</string> <string name="downloading_progress">Downloading (%1$d/%2$d)</string>
<string name="invalid_download_location">Invalid download location</string> <string name="invalid_download_location">Invalid download location</string>
<string name="download_paused">Download paused</string> <string name="download_paused">Download paused</string>