Merge pull request #1532 from Jaehwa-Noh/refactor-flavor-diemsion

Refactor to improve `FlavorDimension` extensibility
pull/1238/merge
Don Turner 6 days ago committed by GitHub
commit 1d67facf6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -16,23 +16,26 @@ enum class FlavorDimension {
@Suppress("EnumEntryName") @Suppress("EnumEntryName")
enum class NiaFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) { enum class NiaFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) {
demo(FlavorDimension.contentType, applicationIdSuffix = ".demo"), demo(FlavorDimension.contentType, applicationIdSuffix = ".demo"),
prod(FlavorDimension.contentType) prod(FlavorDimension.contentType),
} }
fun configureFlavors( fun configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *, *>, commonExtension: CommonExtension<*, *, *, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {} flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {},
) { ) {
commonExtension.apply { commonExtension.apply {
flavorDimensions += FlavorDimension.contentType.name FlavorDimension.values().forEach { flavorDimension ->
flavorDimensions += flavorDimension.name
}
productFlavors { productFlavors {
NiaFlavor.values().forEach { NiaFlavor.values().forEach { niaFlavor ->
create(it.name) { register(niaFlavor.name) {
dimension = it.dimension.name dimension = niaFlavor.dimension.name
flavorConfigurationBlock(this, it) flavorConfigurationBlock(this, niaFlavor)
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) { if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
if (it.applicationIdSuffix != null) { if (niaFlavor.applicationIdSuffix != null) {
applicationIdSuffix = it.applicationIdSuffix applicationIdSuffix = niaFlavor.applicationIdSuffix
} }
} }
} }

Loading…
Cancel
Save