From 7f90ad78479b90864d0bd5148497371e31e614dc Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 26 Jan 2018 08:32:34 -0500 Subject: [PATCH] Fix chapter recognition regex and detail number (#1213) * Update basic filter for sources that include space between numbers Wasnts matching on vol. 1 ch. 10 previously so mangadex last chapter was showing volume number. * Don't show last chapter number when there are 0 chapters or chapters with no numbers. This prevents one shots from showing with -1 as last chapter and instead just leaves it blank * added else to be Unknown instead of blank * removed empty line added test case * switched to null safe ?. * Revert "switched to null safe ?." This reverts commit 97a9300d1bedc8e01efb439c180eced8eaa1da5b. undo * switched to null safe ?. --- .../ui/manga/info/MangaInfoController.kt | 25 +++++++++++-------- .../tachiyomi/util/ChapterRecognition.kt | 2 +- .../data/database/ChapterRecognitionTest.kt | 11 ++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 1963305960..507eaffb3c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -7,7 +7,6 @@ import android.content.ClipboardManager import android.content.Context import android.content.Intent import android.graphics.Bitmap -import android.graphics.Color import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build @@ -91,7 +90,7 @@ class MangaInfoController : NucleusController(), // Set SwipeRefresh to refresh manga data. swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() } - manga_full_title.longClicks().subscribeUntilDestroy{ + manga_full_title.longClicks().subscribeUntilDestroy { copyToClipboard(view.context.getString(R.string.title), manga_full_title.text.toString()) } @@ -191,14 +190,14 @@ class MangaInfoController : NucleusController(), } // If manga source is known update source TextView. - manga_source.text = if(source == null) { + manga_source.text = if (source == null) { view.context.getString(R.string.unknown) } else { source.toString() } // Update genres list - if(manga.genre.isNullOrBlank().not()){ + if (manga.genre.isNullOrBlank().not()) { manga_genres_tags.setTags(manga.genre?.split(", ")) } @@ -249,10 +248,14 @@ class MangaInfoController : NucleusController(), * @param count number of chapters. */ fun setChapterCount(count: Float) { - manga_chapters?.text = DecimalFormat("#.#").format(count) + if (count > 0f) { + manga_chapters?.text = DecimalFormat("#.#").format(count) + } else { + manga_chapters?.text = resources?.getString(R.string.unknown) + } } - fun setLastUpdateDate(date: Date){ + fun setLastUpdateDate(date: Date) { manga_last_update?.text = DateFormat.getDateInstance(DateFormat.SHORT).format(date) } @@ -381,7 +384,7 @@ class MangaInfoController : NucleusController(), } } activity?.toast(activity?.getString(R.string.manga_added_library)) - }else{ + } else { activity?.toast(activity?.getString(R.string.manga_removed_library)) } } @@ -465,8 +468,8 @@ class MangaInfoController : NucleusController(), * @param label Label to show to the user describing the content * @param content the actual text to copy to the board */ - private fun copyToClipboard(label: String, content: String){ - if(content.isBlank()) return + private fun copyToClipboard(label: String, content: String) { + if (content.isBlank()) return val activity = activity ?: return val view = view ?: return @@ -474,7 +477,7 @@ class MangaInfoController : NucleusController(), val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager clipboard.primaryClip = ClipData.newPlainText(label, content) - activity.toast( view.context.getString(R.string.copied_to_clipboard, content.truncateCenter(20)), + activity.toast(view.context.getString(R.string.copied_to_clipboard, content.truncateCenter(20)), Toast.LENGTH_SHORT) } @@ -483,7 +486,7 @@ class MangaInfoController : NucleusController(), * * @param query the search query to pass to the search controller */ - fun performGlobalSearch(query: String){ + fun performGlobalSearch(query: String) { val router = parentController?.router ?: return router.pushController(CatalogueSearchController(query).withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt index 9c5b495037..9ee6774a76 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.kt @@ -11,7 +11,7 @@ object ChapterRecognition { * All cases with Ch.xx * Mokushiroku Alice Vol.1 Ch. 4: Misrepresentation -R> 4 */ - private val basic = Regex("""(?<=ch\.)([0-9]+)(\.[0-9]+)?(\.?[a-z]+)?""") + private val basic = Regex("""(?<=ch\.) *([0-9]+)(\.[0-9]+)?(\.?[a-z]+)?""") /** * Regex used when only one number occurrence diff --git a/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt b/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt index e5e4516bb1..ee8c1f33a4 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt +++ b/app/src/test/java/eu/kanade/tachiyomi/data/database/ChapterRecognitionTest.kt @@ -58,6 +58,17 @@ class ChapterRecognitionTest { assertThat(chapter.chapter_number).isEqualTo(4f) } + /** + * Ch. xx base case but space after period + */ + @Test fun ChCaseBase2() { + createManga("Mokushiroku Alice") + + createChapter("Mokushiroku Alice Vol. 1 Ch. 4: Misrepresentation") + ChapterRecognition.parseChapterNumber(chapter, manga) + assertThat(chapter.chapter_number).isEqualTo(4f) + } + /** * Ch.xx.x base case */