Browse Source

Move chapter name cleaning logic to holder (fixes #6955)

arkon 3 years ago
parent
commit
65a8b63b3b

+ 1 - 1
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

+ 0 - 46
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt

@@ -431,17 +431,6 @@ 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.
      */
@@ -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()

+ 45 - 1
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()