From 0322746770d7cbcf7b061eed32ca6fa3d9b4b093 Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Fri, 13 May 2022 19:19:43 -0300 Subject: [PATCH] Add support to sourceName in multisrc generators (#11857) * Add support to sourceName in multisrc generators. * Fix missing attribute in MMRCMS. --- .../tachiyomi/multisrc/mmrcms/MMRCMSGenerator.kt | 11 ++++++++++- .../tachiyomi/multisrc/mmrcms/MMRCMSSources.kt | 3 +++ .../main/java/generator/ThemeSourceGenerator.kt | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSGenerator.kt index 04ed227f7..b3df43d25 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSGenerator.kt @@ -12,7 +12,16 @@ class MMRCMSGenerator : ThemeSourceGenerator { override val baseVersionCode: Int = MMRCMSSources.version override val sources = MMRCMSSources.sourceList.map { - SingleLang(it.name, it.baseUrl, it.lang, it.isNsfw, it.className, it.pkgName, it.overrideVersionCode) + SingleLang( + it.name, + it.baseUrl, + it.lang, + it.isNsfw, + it.className, + it.pkgName, + it.sourceName, + it.overrideVersionCode + ) } companion object { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt index 167617d3f..3ed2f26be 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt @@ -10,6 +10,7 @@ class MMRCMSSources { abstract val isNsfw: Boolean abstract val className: String abstract val pkgName: String + abstract val sourceName: String abstract val overrideVersionCode: Int data class Single( @@ -19,6 +20,7 @@ class MMRCMSSources { override val isNsfw: Boolean = false, override val className: String = name.replace(" ", ""), override val pkgName: String = className.toLowerCase(Locale.ENGLISH), + override val sourceName: String = name, override val overrideVersionCode: Int = 0, ) : SourceData() @@ -29,6 +31,7 @@ class MMRCMSSources { override val isNsfw: Boolean = false, override val className: String = name.replace(" ", "") + "Factory", override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH), + override val sourceName: String = name, override val overrideVersionCode: Int = 0, ) : SourceData() } diff --git a/multisrc/src/main/java/generator/ThemeSourceGenerator.kt b/multisrc/src/main/java/generator/ThemeSourceGenerator.kt index a12ae39ef..2d58390cb 100644 --- a/multisrc/src/main/java/generator/ThemeSourceGenerator.kt +++ b/multisrc/src/main/java/generator/ThemeSourceGenerator.kt @@ -196,11 +196,11 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString fun factoryClassText(): String { return when (source) { is ThemeSourceData.SingleLang -> { - """class ${source.className} : $themeClass("${source.name}", "${source.baseUrl}", "${source.lang}")""" + """class ${source.className} : $themeClass("${source.sourceName}", "${source.baseUrl}", "${source.lang}")""" } is ThemeSourceData.MultiLang -> { val sourceClasses = source.langs.map { lang -> - """$themeClass("${source.name}", "${source.baseUrl}", "$lang")""" + """$themeClass("${source.sourceName}", "${source.baseUrl}", "$lang")""" } """ @@ -243,6 +243,14 @@ sealed class ThemeSourceData { abstract val className: String abstract val pkgName: String + /** + * Override it if for some reason the name attribute inside the source class + * should be different from the extension name. Useful in cases where the + * extension name should be romanized and the source name should be the one + * in the source language. Defaults to the extension name if not specified. + */ + abstract val sourceName: String + /** * overrideVersionCode defaults to 0, if a source changes their source override code or * a previous existing source suddenly needs source code overrides, overrideVersionCode @@ -260,6 +268,7 @@ sealed class ThemeSourceData { override val isNsfw: Boolean = false, override val className: String = name.replace(" ", ""), override val pkgName: String = className.toLowerCase(Locale.ENGLISH), + override val sourceName: String = name, override val overrideVersionCode: Int = 0, ) : ThemeSourceData() @@ -270,6 +279,7 @@ sealed class ThemeSourceData { override val isNsfw: Boolean = false, override val className: String = name.replace(" ", "") + "Factory", override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH), + override val sourceName: String = name, override val overrideVersionCode: Int = 0, ) : ThemeSourceData() }