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 ?.
This commit is contained in:
Carlos 2018-01-26 08:32:34 -05:00 committed by Bram van de Kerkhof
parent 1292c0ecea
commit 7f90ad7847
3 changed files with 26 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
@ -249,7 +248,11 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
* @param count number of chapters. * @param count number of chapters.
*/ */
fun setChapterCount(count: Float) { fun setChapterCount(count: Float) {
if (count > 0f) {
manga_chapters?.text = DecimalFormat("#.#").format(count) manga_chapters?.text = DecimalFormat("#.#").format(count)
} else {
manga_chapters?.text = resources?.getString(R.string.unknown)
}
} }
fun setLastUpdateDate(date: Date) { fun setLastUpdateDate(date: Date) {

View File

@ -11,7 +11,7 @@ object ChapterRecognition {
* All cases with Ch.xx * All cases with Ch.xx
* Mokushiroku Alice Vol.1 Ch. 4: Misrepresentation -R> 4 * 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 * Regex used when only one number occurrence

View File

@ -58,6 +58,17 @@ class ChapterRecognitionTest {
assertThat(chapter.chapter_number).isEqualTo(4f) 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 * Ch.xx.x base case
*/ */