From ff4a217730217ce5720f7a81017054ddfa917928 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Fri, 2 Sep 2022 20:07:50 +0600 Subject: [PATCH] Cleanup chapter name when syncing chapter with source (#7910) --- .../kanade/data/chapter/CleanupChapterName.kt | 47 +++++++++++++++++++ .../interactor/SyncChaptersWithSource.kt | 2 + 2 files changed, 49 insertions(+) create mode 100644 app/src/main/java/eu/kanade/data/chapter/CleanupChapterName.kt diff --git a/app/src/main/java/eu/kanade/data/chapter/CleanupChapterName.kt b/app/src/main/java/eu/kanade/data/chapter/CleanupChapterName.kt new file mode 100644 index 000000000..12ce6b298 --- /dev/null +++ b/app/src/main/java/eu/kanade/data/chapter/CleanupChapterName.kt @@ -0,0 +1,47 @@ +package eu.kanade.data.chapter + +object CleanupChapterName { + + fun await(chapterName: String, mangaTitle: String): String { + return chapterName + .trim() + .removePrefix(mangaTitle) + .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() +} diff --git a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt index 9bd7ccdc1..c61585faa 100644 --- a/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt +++ b/app/src/main/java/eu/kanade/domain/chapter/interactor/SyncChaptersWithSource.kt @@ -1,5 +1,6 @@ package eu.kanade.domain.chapter.interactor +import eu.kanade.data.chapter.CleanupChapterName import eu.kanade.data.chapter.NoChaptersException import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.toChapterUpdate @@ -50,6 +51,7 @@ class SyncChaptersWithSource( .mapIndexed { i, sChapter -> Chapter.create() .copyFromSChapter(sChapter) + .copy(name = CleanupChapterName.await(sChapter.name, manga.title)) .copy(mangaId = manga.id, sourceOrder = i.toLong()) }