Add support to sourceName in multisrc generators (#11857)

* Add support to sourceName in multisrc generators.

* Fix missing attribute in MMRCMS.
This commit is contained in:
Alessandro Jean 2022-05-13 19:19:43 -03:00 committed by GitHub
parent e3cd553ee6
commit 0322746770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View File

@ -12,7 +12,16 @@ class MMRCMSGenerator : ThemeSourceGenerator {
override val baseVersionCode: Int = MMRCMSSources.version override val baseVersionCode: Int = MMRCMSSources.version
override val sources = MMRCMSSources.sourceList.map { 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 { companion object {

View File

@ -10,6 +10,7 @@ class MMRCMSSources {
abstract val isNsfw: Boolean abstract val isNsfw: Boolean
abstract val className: String abstract val className: String
abstract val pkgName: String abstract val pkgName: String
abstract val sourceName: String
abstract val overrideVersionCode: Int abstract val overrideVersionCode: Int
data class Single( data class Single(
@ -19,6 +20,7 @@ class MMRCMSSources {
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", ""), override val className: String = name.replace(" ", ""),
override val pkgName: String = className.toLowerCase(Locale.ENGLISH), override val pkgName: String = className.toLowerCase(Locale.ENGLISH),
override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : SourceData() ) : SourceData()
@ -29,6 +31,7 @@ class MMRCMSSources {
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", "") + "Factory", override val className: String = name.replace(" ", "") + "Factory",
override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH), override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH),
override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : SourceData() ) : SourceData()
} }

View File

@ -196,11 +196,11 @@ ${placeholders.map { "${" ".repeat(28)}${it.key}: \"${it.value}\""}.joinToString
fun factoryClassText(): String { fun factoryClassText(): String {
return when (source) { return when (source) {
is ThemeSourceData.SingleLang -> { 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 -> { is ThemeSourceData.MultiLang -> {
val sourceClasses = source.langs.map { lang -> 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 className: String
abstract val pkgName: 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 * overrideVersionCode defaults to 0, if a source changes their source override code or
* a previous existing source suddenly needs source code overrides, overrideVersionCode * a previous existing source suddenly needs source code overrides, overrideVersionCode
@ -260,6 +268,7 @@ sealed class ThemeSourceData {
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", ""), override val className: String = name.replace(" ", ""),
override val pkgName: String = className.toLowerCase(Locale.ENGLISH), override val pkgName: String = className.toLowerCase(Locale.ENGLISH),
override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : ThemeSourceData() ) : ThemeSourceData()
@ -270,6 +279,7 @@ sealed class ThemeSourceData {
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,
override val className: String = name.replace(" ", "") + "Factory", override val className: String = name.replace(" ", "") + "Factory",
override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH), override val pkgName: String = className.substringBefore("Factory").toLowerCase(Locale.ENGLISH),
override val sourceName: String = name,
override val overrideVersionCode: Int = 0, override val overrideVersionCode: Int = 0,
) : ThemeSourceData() ) : ThemeSourceData()
} }