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

@@ -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()