Last active
October 9, 2022 11:03
-
-
Save reactivedroid/efd28badd08dac80dd46dc31adee80a9 to your computer and use it in GitHub Desktop.
Implementation of the BuildConfigProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BuildConfigProviderImpl | |
@Inject | |
constructor(@ApplicationContext private val context: Context) : BuildConfigProvider { | |
private fun getFlavorMap(): MutableMap<String, String> { | |
return if (BuildConfig.BUILD_TYPE == "release") { | |
BuildConfig.RELEASE_MAP | |
} else { | |
buildConfigurationFor(getFlavor()) | |
} | |
} | |
@Suppress("UNCHECKED_CAST") | |
private fun getFieldFromBuildConfig( | |
clazz: Class<*>, | |
fieldName: String | |
): MutableMap<String, String> { | |
return clazz.getField(fieldName).get(null) as MutableMap<String, String> | |
} | |
override fun setFlavor(text: String) { | |
// Sets the selected flavor as chosen by the user | |
} | |
override fun getFlavor(): String { | |
val flavor = // // Gets the selected flavor as chosen by the user | |
return flavor ?: BuildConfig.FLAVOR | |
} | |
override fun getValue(key: String): String { | |
val flavorMap: MutableMap<String, String> = getFlavorMap() | |
return (flavorMap[key].toString()) | |
} | |
private fun buildConfigurationFor(flavorName: String): MutableMap<String, String> { | |
val flavorPropertiesMap: MutableMap<String, String> by lazy { | |
getFieldFromBuildConfig( | |
BuildConfig::class.java, | |
"${flavorName.uppercase(Locale.ENGLISH)}_MAP" | |
) | |
} | |
return flavorPropertiesMap | |
} | |
override fun allFlavors(): List<String> { | |
return BuildConfig.SET_OF_FLAVORS | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment