From ee8c71c14a37390c815bda7a71d851856ea237a6 Mon Sep 17 00:00:00 2001 From: Lautaro Martin Emanuel Date: Thu, 14 May 2020 23:38:19 -0300 Subject: [PATCH 1/3] Added sorting by upload date Spanish 'strings' contains the proper translation for the new feature. --- .../kanade/tachiyomi/data/database/models/Manga.kt | 3 ++- .../ui/manga/chapter/ChaptersController.kt | 14 ++++++++++---- .../ui/manga/chapter/ChaptersPresenter.kt | 4 ++++ app/src/main/res/menu/chapters.xml | 3 +++ app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index 69c9cc6b6e..fe3c074d5e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -78,7 +78,8 @@ interface Manga : SManga { const val SORTING_SOURCE = 0x00000000 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_NUMBER = 0x00100000 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 59e64f6951..b2aa4ba3c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -196,11 +196,13 @@ class ChaptersController : } // Sorting mode submenu - if (presenter.manga.sorting == Manga.SORTING_SOURCE) { - menu.findItem(R.id.sort_by_source).isChecked = true - } else { - menu.findItem(R.id.sort_by_number).isChecked = true + val sortingItem = when (presenter.manga.sorting) { + Manga.SORTING_SOURCE -> R.id.sort_by_source + Manga.SORTING_NUMBER -> R.id.sort_by_number + 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 { @@ -222,6 +224,10 @@ class ChaptersController : item.isChecked = true 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_custom, R.id.download_unread, R.id.download_all diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index e108a8eb73..1434e3d56a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -203,6 +203,10 @@ class ChaptersPresenter( true -> { c1, c2 -> c2.chapter_number.compareTo(c1.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") } return observable.toSortedList(sortFunction) diff --git a/app/src/main/res/menu/chapters.xml b/app/src/main/res/menu/chapters.xml index 13ae70dc31..e4d16d4071 100644 --- a/app/src/main/res/menu/chapters.xml +++ b/app/src/main/res/menu/chapters.xml @@ -64,6 +64,9 @@ + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f69266a231..330af7f1eb 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -183,6 +183,7 @@ Ordenado de capítulos Por fuente Por número de capítulo + Por fecha de carga Descargar Siguiente capítulo Siguientes 5 capítulos diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 788a8bcec2..ef12c49dfd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -473,6 +473,7 @@ Sorting mode By source By chapter number + By chapter upload date Download Download custom amount Next chapter From 9e830f1c55a9514462290868864b84194aef7b15 Mon Sep 17 00:00:00 2001 From: Lautaro Martin Emanuel Date: Fri, 15 May 2020 01:10:02 -0300 Subject: [PATCH 2/3] Added missing sorting cases handling Previous commit missed some cases resulting in errors at runtime --- .../eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt | 9 +++++++++ .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 1 + .../tachiyomi/ui/recent/history/HistoryPresenter.kt | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt index b07c803f23..f637e5b09f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ChapterLoadStrategy.kt @@ -35,3 +35,12 @@ class ChapterLoadByNumber { return chapters.sortedBy { it.chapter_number } } } + +/** + * Load strategy using the chapter upload date. This ordering ignores scanlators + */ +class ChapterLoadByUploadDate() { + fun get(allChapters: List): List { + return allChapters.sortedBy { it.date_upload } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 329a62a44e..77a435b4eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -129,6 +129,7 @@ class ReaderPresenter( when (manga.sorting) { Manga.SORTING_SOURCE -> ChapterLoadBySource().get(chaptersForReader) Manga.SORTING_NUMBER -> ChapterLoadByNumber().get(chaptersForReader, selectedChapter) + Manga.SORTING_UPLOAD_DATE -> ChapterLoadByUploadDate().get(chaptersForReader) else -> error("Unknown sorting method") }.map(::ReaderChapter) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index 911b6fabd4..3ae47d2e7f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -98,6 +98,7 @@ class HistoryPresenter : BasePresenter() { val sortFunction: (Chapter, Chapter) -> Int = when (manga.sorting) { 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_UPLOAD_DATE -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) } else -> throw NotImplementedError("Unknown sorting method") } @@ -117,6 +118,12 @@ class HistoryPresenter : BasePresenter() { it.chapter_number <= chapterNumber + 1 } } + Manga.SORTING_UPLOAD_DATE -> { + val dateUpload = chapter.date_upload + ((currChapterIndex + 1) until chapters.size) + .map { chapters[it] } + .firstOrNull { it.date_upload > dateUpload } + } else -> throw NotImplementedError("Unknown sorting method") } } From 6ba052d2aff8023f4e6bdfc79eb8c0662b27fdf5 Mon Sep 17 00:00:00 2001 From: Lautaro Martin Emanuel Date: Sat, 16 May 2020 18:54:47 -0300 Subject: [PATCH 3/3] Implemented review changes Shorter UI text and >= date comparison instead of > --- .../kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt | 6 ++---- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index 3ae47d2e7f..984c3c6a27 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -119,10 +119,8 @@ class HistoryPresenter : BasePresenter() { } } Manga.SORTING_UPLOAD_DATE -> { - val dateUpload = chapter.date_upload - ((currChapterIndex + 1) until chapters.size) - .map { chapters[it] } - .firstOrNull { it.date_upload > dateUpload } + chapters.drop(currChapterIndex + 1) + .firstOrNull { it.date_upload >= chapter.date_upload} } else -> throw NotImplementedError("Unknown sorting method") } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef12c49dfd..f401c17823 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -473,7 +473,7 @@ Sorting mode By source By chapter number - By chapter upload date + By upload date Download Download custom amount Next chapter