From 89decf34746eaace93b186f7dc41baa6e42a96f0 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 15 Apr 2022 15:52:48 -0400 Subject: [PATCH] Always remove manga title from if it prefixes chapter names (related to #6913) --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 6 ++- .../eu/kanade/tachiyomi/source/LocalSource.kt | 37 --------------- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../tachiyomi/ui/manga/MangaPresenter.kt | 46 +++++++++++++++++++ 4 files changed, 51 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 377a841774..f4ea91d016 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 128f3d2b3f..6404ec1353 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -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', -) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index c381f1194b..b69b62bdd8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index e65a18311c..b20cdf1dd3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -431,6 +431,17 @@ class MangaPresenter( } } + fun cleanChapterNames(chapters: List): List { + 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()