Always remove manga title from if it prefixes chapter names (related to #6913)

This commit is contained in:
arkon 2022-04-15 15:52:48 -04:00
parent 0b2794e843
commit 89decf3474
4 changed files with 51 additions and 40 deletions

View file

@ -159,8 +159,10 @@ open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
// Override the value passed as X-Requested-With in WebView requests
val stackTrace = Looper.getMainLooper().thread.stackTrace
val chromiumElement = stackTrace.find {
it.className.equals("org.chromium.base.BuildInfo",
ignoreCase = true)
it.className.equals(
"org.chromium.base.BuildInfo",
ignoreCase = true,
)
}
if (chromiumElement?.methodName.equals("getAll", ignoreCase = true)) {
return WebViewUtil.SPOOF_PACKAGE_NAME

View file

@ -218,7 +218,6 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
}
}
name = getCleanChapterTitle(name)
ChapterRecognition.parseChapterNumber(this, sManga)
}
}
@ -234,13 +233,6 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
override suspend fun getPageList(chapter: ChapterInfo) = throw Exception("Unused")
/**
* Trim whitespace/delimiter characters from chapter names.
*/
private fun getCleanChapterTitle(chapterName: String): String {
return chapterName.trim(*WHITESPACE_CHARS.toCharArray(), '-', '_', ',', ':')
}
private fun isSupportedFile(extension: String): Boolean {
return extension.lowercase() in SUPPORTED_ARCHIVE_TYPES
}
@ -326,32 +318,3 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
}
private val SUPPORTED_ARCHIVE_TYPES = listOf("zip", "cbz", "rar", "cbr", "epub")
private val WHITESPACE_CHARS = arrayOf(
' ',
'\u0009',
'\u000A',
'\u000B',
'\u000C',
'\u000D',
'\u0020',
'\u0085',
'\u00A0',
'\u1680',
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2007',
'\u2008',
'\u2009',
'\u200A',
'\u2028',
'\u2029',
'\u202F',
'\u205F',
'\u3000',
)

View file

@ -901,7 +901,7 @@ class MangaController :
chaptersHeader.setNumChapters(chapters.size)
val adapter = chaptersAdapter ?: return
adapter.updateDataSet(chapters)
adapter.updateDataSet(presenter.cleanChapterNames(chapters))
if (selectedChapters.isNotEmpty()) {
adapter.clearSelection() // we need to start from a clean state, index may have changed

View file

@ -431,6 +431,17 @@ class MangaPresenter(
}
}
fun cleanChapterNames(chapters: List<ChapterItem>): List<ChapterItem> {
chapters.forEach {
it.name = it.name
.trim()
.removePrefix(manga.title)
.trim(*CHAPTER_TRIM_CHARS)
}
return chapters
}
/**
* Updates the UI after applying the filters.
*/
@ -852,3 +863,38 @@ class MangaPresenter(
// Track sheet - end
}
private val CHAPTER_TRIM_CHARS = arrayOf(
// Whitespace
' ',
'\u0009',
'\u000A',
'\u000B',
'\u000C',
'\u000D',
'\u0020',
'\u0085',
'\u00A0',
'\u1680',
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2007',
'\u2008',
'\u2009',
'\u200A',
'\u2028',
'\u2029',
'\u202F',
'\u205F',
'\u3000',
// Separators
'-',
'_',
',',
':',
).toCharArray()