Sort chapters by upload date (#3180)

* Added sorting by upload date

Spanish 'strings' contains the proper translation for the new feature.

* Added missing sorting cases handling

Previous commit missed some cases resulting in errors at runtime

* Implemented review changes

Shorter UI text and >= date comparison instead of >
This commit is contained in:
arkon 2020-05-17 10:18:49 -04:00 committed by GitHub
commit 102a372df9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 5 deletions

View File

@ -78,7 +78,8 @@ interface Manga : SManga {
const val SORTING_SOURCE = 0x00000000 const val SORTING_SOURCE = 0x00000000
const val SORTING_NUMBER = 0x00000100 const val SORTING_NUMBER = 0x00000100
const val SORTING_MASK = 0x00000100 const val SORTING_UPLOAD_DATE = 0x00000200
const val SORTING_MASK = 0x00000300
const val DISPLAY_NAME = 0x00000000 const val DISPLAY_NAME = 0x00000000
const val DISPLAY_NUMBER = 0x00100000 const val DISPLAY_NUMBER = 0x00100000

View File

@ -196,11 +196,13 @@ class ChaptersController :
} }
// Sorting mode submenu // Sorting mode submenu
if (presenter.manga.sorting == Manga.SORTING_SOURCE) { val sortingItem = when (presenter.manga.sorting) {
menu.findItem(R.id.sort_by_source).isChecked = true Manga.SORTING_SOURCE -> R.id.sort_by_source
} else { Manga.SORTING_NUMBER -> R.id.sort_by_number
menu.findItem(R.id.sort_by_number).isChecked = true Manga.SORTING_UPLOAD_DATE -> R.id.sort_by_upload_date
else -> throw NotImplementedError("Unimplemented sorting method")
} }
menu.findItem(sortingItem).isChecked = true
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -222,6 +224,10 @@ class ChaptersController :
item.isChecked = true item.isChecked = true
presenter.setSorting(Manga.SORTING_NUMBER) presenter.setSorting(Manga.SORTING_NUMBER)
} }
R.id.sort_by_upload_date -> {
item.isChecked = true
presenter.setSorting(Manga.SORTING_UPLOAD_DATE)
}
R.id.download_next, R.id.download_next_5, R.id.download_next_10, R.id.download_next, R.id.download_next_5, R.id.download_next_10,
R.id.download_custom, R.id.download_unread, R.id.download_all R.id.download_custom, R.id.download_unread, R.id.download_all

View File

@ -203,6 +203,10 @@ class ChaptersPresenter(
true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) } true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) }
false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) }
} }
Manga.SORTING_UPLOAD_DATE -> when (sortDescending()) {
true -> { c1, c2 -> c2.date_upload.compareTo(c1.date_upload) }
false -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) }
}
else -> throw NotImplementedError("Unimplemented sorting method") else -> throw NotImplementedError("Unimplemented sorting method")
} }
return observable.toSortedList(sortFunction) return observable.toSortedList(sortFunction)

View File

@ -35,3 +35,12 @@ class ChapterLoadByNumber {
return chapters.sortedBy { it.chapter_number } return chapters.sortedBy { it.chapter_number }
} }
} }
/**
* Load strategy using the chapter upload date. This ordering ignores scanlators
*/
class ChapterLoadByUploadDate() {
fun get(allChapters: List<Chapter>): List<Chapter> {
return allChapters.sortedBy { it.date_upload }
}
}

View File

@ -129,6 +129,7 @@ class ReaderPresenter(
when (manga.sorting) { when (manga.sorting) {
Manga.SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader) Manga.SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader)
Manga.SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter) Manga.SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter)
Manga.SORTING_UPLOAD_DATE -> ChapterLoadByUploadDate().get(chaptersForReader)
else -> error("Unknown sorting method") else -> error("Unknown sorting method")
}.map(::ReaderChapter) }.map(::ReaderChapter)
} }

View File

@ -98,6 +98,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
val sortFunction: (Chapter, Chapter) -> Int = when (manga.sorting) { val sortFunction: (Chapter, Chapter) -> Int = when (manga.sorting) {
Manga.SORTING_SOURCE -> { c1, c2 -> c2.source_order.compareTo(c1.source_order) } Manga.SORTING_SOURCE -> { c1, c2 -> c2.source_order.compareTo(c1.source_order) }
Manga.SORTING_NUMBER -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } Manga.SORTING_NUMBER -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) }
Manga.SORTING_UPLOAD_DATE -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) }
else -> throw NotImplementedError("Unknown sorting method") else -> throw NotImplementedError("Unknown sorting method")
} }
@ -117,6 +118,10 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
it.chapter_number <= chapterNumber + 1 it.chapter_number <= chapterNumber + 1
} }
} }
Manga.SORTING_UPLOAD_DATE -> {
chapters.drop(currChapterIndex + 1)
.firstOrNull { it.date_upload >= chapter.date_upload}
}
else -> throw NotImplementedError("Unknown sorting method") else -> throw NotImplementedError("Unknown sorting method")
} }
} }

View File

@ -64,6 +64,9 @@
<item <item
android:id="@+id/sort_by_number" android:id="@+id/sort_by_number"
android:title="@string/sort_by_number" /> android:title="@string/sort_by_number" />
<item
android:id="@+id/sort_by_upload_date"
android:title="@string/sort_by_upload_date" />
</group> </group>
</menu> </menu>
</item> </item>

View File

@ -183,6 +183,7 @@
<string name="sorting_mode">Ordenado de capítulos</string> <string name="sorting_mode">Ordenado de capítulos</string>
<string name="sort_by_source">Por fuente</string> <string name="sort_by_source">Por fuente</string>
<string name="sort_by_number">Por número de capítulo</string> <string name="sort_by_number">Por número de capítulo</string>
<string name="sort_by_upload_date">Por fecha de carga</string>
<string name="manga_download">Descargar</string> <string name="manga_download">Descargar</string>
<string name="download_1">Siguiente capítulo</string> <string name="download_1">Siguiente capítulo</string>
<string name="download_5">Siguientes 5 capítulos</string> <string name="download_5">Siguientes 5 capítulos</string>

View File

@ -479,6 +479,7 @@
<string name="sorting_mode">Sorting mode</string> <string name="sorting_mode">Sorting mode</string>
<string name="sort_by_source">By source</string> <string name="sort_by_source">By source</string>
<string name="sort_by_number">By chapter number</string> <string name="sort_by_number">By chapter number</string>
<string name="sort_by_upload_date">By upload date</string>
<string name="manga_download">Download</string> <string name="manga_download">Download</string>
<string name="custom_download">Download custom amount</string> <string name="custom_download">Download custom amount</string>
<string name="download_1">Next chapter</string> <string name="download_1">Next chapter</string>