Reword download chapter number sorting options

This commit is contained in:
arkon 2021-01-23 13:19:57 -05:00
parent a083e1f71a
commit e288bf902b
3 changed files with 20 additions and 25 deletions

View File

@ -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 <R : Comparable<R>> 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.
*

View File

@ -26,11 +26,11 @@
app:showAsAction="never">
<menu>
<item
android:id="@+id/bigest"
android:title="@string/action_bigest" />
android:id="@+id/asc"
android:title="@string/action_asc" />
<item
android:id="@+id/smallest"
android:title="@string/action_smallest" />
android:id="@+id/desc"
android:title="@string/action_desc" />
</menu>
</item>
</menu>

View File

@ -107,8 +107,8 @@
<string name="action_order_by_chapter_number">By chapter number</string>
<string name="action_newest">Newest</string>
<string name="action_oldest">Oldest</string>
<string name="action_bigest">Bigest</string>
<string name="action_smallest">Smallest</string>
<string name="action_asc">Ascending</string>
<string name="action_desc">Descending</string>
<string name="action_move_to_top">Move to top</string>
<string name="action_move_to_bottom">Move to bottom</string>
<string name="action_install">Install</string>