From 65a8b63b3b91dbe65fc7c0f034a7bf1453c28754 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 18 Apr 2022 09:26:35 -0400 Subject: [PATCH] Move chapter name cleaning logic to holder (fixes #6955) --- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../tachiyomi/ui/manga/MangaPresenter.kt | 46 ------------------- .../ui/manga/chapter/ChapterHolder.kt | 46 ++++++++++++++++++- 3 files changed, 46 insertions(+), 48 deletions(-) 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 b69b62bdd8..c381f1194b 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(presenter.cleanChapterNames(chapters)) + adapter.updateDataSet(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 b20cdf1dd3..e65a18311c 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,17 +431,6 @@ 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. */ @@ -863,38 +852,3 @@ 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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index 4a4c746729..1e40d00c58 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -6,6 +6,7 @@ import androidx.core.text.buildSpannedString import androidx.core.text.color import androidx.core.view.isVisible import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.databinding.ChaptersItemBinding import eu.kanade.tachiyomi.source.LocalSource @@ -34,7 +35,7 @@ class ChapterHolder( val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) itemView.context.getString(R.string.display_mode_chapter, number) } - else -> chapter.name + else -> cleanChapterName(chapter, manga) } // Set correct text color @@ -80,4 +81,47 @@ class ChapterHolder( binding.download.isVisible = item.manga.source != LocalSource.ID binding.download.setState(item.status, item.progress) } + + private fun cleanChapterName(chapter: Chapter, manga: Manga): String { + return chapter.name + .trim() + .removePrefix(manga.title) + .trim(*CHAPTER_TRIM_CHARS) + } } + +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()