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 fac8963516..944bc73865 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 b400bb8501..4cc4d43df2 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 cb021c9eb3..783d33e07b 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