From e288bf902bf1ee9694edbc8b2c8e0bbd4d2ba602 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 23 Jan 2021 13:19:57 -0500 Subject: [PATCH] Reword download chapter number sorting options --- .../ui/download/DownloadController.kt | 33 ++++++++----------- app/src/main/res/menu/download_queue.xml | 8 ++--- app/src/main/res/values/strings.xml | 4 +-- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index fac896351..944bc7386 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -147,31 +147,26 @@ class DownloadController : presenter.clearQueue() } R.id.newest, R.id.oldest -> { - val adapter = adapter ?: return false - val items = adapter.currentItems.sortedBy { it.download.chapter.date_upload } - .toMutableList() - if (item.itemId == R.id.newest) { - items.reverse() - } - adapter.updateDataSet(items) - val downloads = items.mapNotNull { it.download } - presenter.reorder(downloads) + reorderQueue({ it.download.chapter.date_upload }, item.itemId == R.id.newest) } - R.id.bigest, R.id.smallest -> { - val adapter = adapter ?: return false - val items = adapter.currentItems.sortedBy { it.download.chapter.chapter_number } - .toMutableList() - if (item.itemId == R.id.bigest) { - items.reverse() - } - adapter.updateDataSet(items) - val downloads = items.mapNotNull { it.download } - presenter.reorder(downloads) + R.id.asc, R.id.desc -> { + reorderQueue({ it.download.chapter.chapter_number }, item.itemId == R.id.desc) } } return super.onOptionsItemSelected(item) } + private fun > reorderQueue(selector: (DownloadItem) -> R, reverse: Boolean = false) { + val adapter = adapter ?: return + val items = adapter.currentItems.sortedBy(selector).toMutableList() + if (reverse) { + items.reverse() + } + adapter.updateDataSet(items) + val downloads = items.mapNotNull { it.download } + presenter.reorder(downloads) + } + /** * Called when the status of a download changes. * diff --git a/app/src/main/res/menu/download_queue.xml b/app/src/main/res/menu/download_queue.xml index b400bb850..4cc4d43df 100644 --- a/app/src/main/res/menu/download_queue.xml +++ b/app/src/main/res/menu/download_queue.xml @@ -26,11 +26,11 @@ app:showAsAction="never"> + android:id="@+id/asc" + android:title="@string/action_asc" /> + android:id="@+id/desc" + android:title="@string/action_desc" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cb021c9eb..783d33e07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,8 +107,8 @@ By chapter number Newest Oldest - Bigest - Smallest + Ascending + Descending Move to top Move to bottom Install