Skip to content

Commit

Permalink
chore: change resources generation for resource file to be replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed Jul 3, 2024
1 parent c48218e commit 9c91f93
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 93 deletions.
37 changes: 37 additions & 0 deletions app/src/main/res/values/urls.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Wire
~ Copyright (C) 2024 Wire Swiss GmbH
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~e
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see http://www.gnu.org/licenses/.
-->
<resources>
<string name="url_create_account_learn_more" translatable="false">https://support.wire.com/hc/articles/115004082129</string>
<string name="url_decryption_failure_learn_more" translatable="false">https://support.wire.com/hc/articles/207948115</string>
<string name="url_federation_support" translatable="false">https://support.wire.com/hc/categories/4719917054365</string>
<string name="url_file_sharing_restricted_learn_more" translatable="false">https://support.wire.com/hc/articles/4406404582673</string>
<string name="url_learn_about_conversation_search" translatable="false">https://support.wire.com/hc/articles/115001426529</string>
<string name="url_learn_about_search" translatable="false">https://support.wire.com/hc/articles/203121850</string>
<string name="url_legal_hold_learn_more" translatable="false">https://support.wire.com/hc/articles/360002018278</string>
<string name="url_message_details_offline_backends_learn_more" translatable="false">https://support.wire.com/hc/articles/9357718008093</string>
<string name="url_message_details_reactions_learn_more" translatable="false">https://support.wire.com/hc/articles/212053645</string>
<string name="url_message_details_read_receipts_learn_more" translatable="false">https://support.wire.com/hc/articles/360000665277</string>
<string name="url_privacy_policy" translatable="false">https://wire.com/privacy-policy#:~:text=We%20process%20individual%20data%20about,%C2%A7%201%20a)%20GDPR).</string>
<string name="url_self_client_fingerprint_learn_more" translatable="false">https://support.wire.com/hc/articles/207692235</string>
<string name="url_self_client_verification_learn_more" translatable="false">https://support.wire.com/hc/articles/207693005</string>
<string name="url_support" translatable="false">https://support.wire.com</string>
<string name="url_system_message_learn_more_about_mls" translatable="false">https://support.wire.com/hc/articles/12434725011485</string>
<string name="url_terms_of_use_legal" translatable="false">https://wire.com/legal</string>
<string name="url_welcome_to_new_android" translatable="false">https://support.wire.com/hc/articles/6655706999581</string>
<string name="url_why_verify_conversation" translatable="false">https://support.wire.com/hc/articles/207859815</string>
</resources>
32 changes: 2 additions & 30 deletions buildSrc/src/main/kotlin/customization/FeatureConfigs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@
*/
package customization

import customization.ResType.BUILD_CONFIG
import customization.ResType.STRING_RES

enum class ConfigType(val type: String) {
STRING("String"),
BOOLEAN("Boolean"),
INT("int"),
MapOfStringToListOfStrings("java.util.HashMap<String, java.util.List<String>>")
}

enum class ResType {
BUILD_CONFIG,
STRING_RES
}

enum class FeatureConfigs(val value: String, val configType: ConfigType, val resType: ResType = BUILD_CONFIG) {
enum class FeatureConfigs(val value: String, val configType: ConfigType) {
/**
* General APP Coordinates
*/
Expand Down Expand Up @@ -87,28 +79,8 @@ enum class FeatureConfigs(val value: String, val configType: ConfigType, val res
DEVELOPMENT_API_ENABLED("development_api_enabled", ConfigType.BOOLEAN),
REPORT_BUG_MENU_ITEM_ENABLED("report_bug_menu_item_enabled", ConfigType.BOOLEAN),

/**
* Urls
*/
URL_SUPPORT("url_support", ConfigType.STRING),
URL_RSS_RELEASE_NOTES("url_rss_release_notes", ConfigType.STRING),
URL_SUPPORT("url_support", ConfigType.STRING, STRING_RES),
URL_PRIVACY_POLICY("url_privacy_policy", ConfigType.STRING, STRING_RES),
URL_TERMS_OF_USE_LEGAL("url_terms_of_use_legal", ConfigType.STRING, STRING_RES),
URL_DECRYPTION_FAILURE_LEARN_MORE("url_decryption_failure_learn_more", ConfigType.STRING, STRING_RES),
URL_WELCOME_TO_NEW_ANDROID("url_welcome_to_new_android", ConfigType.STRING, STRING_RES),
URL_MESSAGE_DETAILS_REACTIONS_LEARN_MORE("url_message_details_reactions_learn_more", ConfigType.STRING, STRING_RES),
URL_MESSAGE_DETAILS_READ_RECEIPTS_LEARN_MORE("url_message_details_read_receipts_learn_more", ConfigType.STRING, STRING_RES),
URL_MESSAGE_DETAILS_OFFLINE_BACKENDS_LEARN_MORE("url_message_details_offline_backends_learn_more", ConfigType.STRING, STRING_RES),
URL_SELF_CLIENT_VERIFICATION_LEARN_MORE("url_self_client_verification_learn_more", ConfigType.STRING, STRING_RES),
URL_SELF_CLIENT_FINGERPRINT_LEARN_MORE("url_self_client_fingerprint_learn_more", ConfigType.STRING, STRING_RES),
URL_FEDERATION_SUPPORT("url_federation_support", ConfigType.STRING, STRING_RES),
URL_CREATE_ACCOUNT_LEARN_MORE("url_create_account_learn_more", ConfigType.STRING, STRING_RES),
URL_LEGAL_HOLD_LEARN_MORE("url_legal_hold_learn_more", ConfigType.STRING, STRING_RES),
URL_FILE_SHARING_RESTRICTED_LEARN_MORE("url_file_sharing_restricted_learn_more", ConfigType.STRING, STRING_RES),
URL_SYSTEM_MESSAGE_LEARN_MORE_ABOUT_MLS("url_system_message_learn_more_about_mls", ConfigType.STRING, STRING_RES),
URL_WHY_VERIFY_CONVERSATION("url_why_verify_conversation", ConfigType.STRING, STRING_RES),
URL_LEARN_ABOUT_SEARCH("url_learn_about_search", ConfigType.STRING, STRING_RES),
URL_LEARN_ABOUT_CONVERSATION_SEARCH("url_learn_about_conversation_search", ConfigType.STRING, STRING_RES),

/**
* In runtime, will use these values to determine which backend to use.
Expand Down
101 changes: 38 additions & 63 deletions buildSrc/src/main/kotlin/scripts/variants.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import customization.Customization.getBuildtimeConfiguration
import customization.FeatureConfigs
import customization.FeatureFlags
import customization.Features
import customization.ResType
import customization.overrideResourcesForAllFlavors
import flavor.FlavorDimensions
import flavor.ProductFlavors
Expand Down Expand Up @@ -183,71 +182,54 @@ android {
overrideResourcesForAllFlavors(it)
}

// Process defined product flavors and generates: BuildConfig values or Android Resources.
/**
* Process feature flags and if the feature is not included in a product flavor,
* a default value of "false" or "deactivated" is used.
*
* @see "FeatureFlags.kt" file definition.
*/
productFlavors.forEach { flavor ->
/**
* Process feature flags and if the feature is not included in a product flavor,
* a default value of "false" or "deactivated" is used.
*
* @see "FeatureFlags.kt" file definition.
*/
Features.values().forEach { feature ->
val activated = FeatureFlags.activated.mapKeys { it.key.buildName }[flavor.name].orEmpty().contains(feature)
flavor.buildConfigField("Boolean", feature.name, activated.toString())
}

FeatureConfigs.values().forEach { configs ->
when (configs.resType) {
ResType.STRING_RES -> buildStringRes(
productFlavour = flavor,
name = configs.name,
value = flavorMap[flavor.name]?.get(configs.value)?.toString()
)

ResType.BUILD_CONFIG -> buildCompilationConfig(configs = configs, flavor = flavor, flavorMap = flavorMap)
}
}
}
}

fun buildCompilationConfig(
configs: FeatureConfigs,
flavor: ProductFlavor,
flavorMap: Map<String, Map<String, Any?>>
) {
when (configs.configType) {
ConfigType.STRING -> {
buildStringConfig(
flavor,
configs.configType.type,
configs.name,
flavorMap[flavor.name]?.get(configs.value)?.toString()
)
}
when (configs.configType) {
ConfigType.STRING -> {
buildStringConfig(
flavor,
configs.configType.type,
configs.name,
flavorMap[flavor.name]?.get(configs.value)?.toString()
)
}

ConfigType.INT,
ConfigType.BOOLEAN -> {
buildNonStringConfig(
flavor,
configs.configType.type,
configs.name,
flavorMap[flavor.name]?.get(configs.value).toString()
)
}
ConfigType.INT,
ConfigType.BOOLEAN -> {
buildNonStringConfig(
flavor,
configs.configType.type,
configs.name,
flavorMap[flavor.name]?.get(configs.value).toString()
)
}

ConfigType.MapOfStringToListOfStrings -> {
val map = flavorMap[flavor.name]?.get(configs.value) as? Map<*, *>
val mapString = map?.map { (key, value) ->
"\"$key\", java.util.Arrays.asList(${(value as? List<*>)?.joinToString { "\"$it\"" } ?: ""})".let {
"put($it);"
ConfigType.MapOfStringToListOfStrings -> {
val map = flavorMap[flavor.name]?.get(configs.value) as? Map<*, *>
val mapString = map?.map { (key, value) ->
"\"$key\", java.util.Arrays.asList(${(value as? List<*>)?.joinToString { "\"$it\"" } ?: ""})".let {
"put($it);"
}
}?.joinToString(",\n") ?: ""
buildNonStringConfig(
flavor,
configs.configType.type,
configs.name,
"new java.util.HashMap<String, java.util.List<String>>() {{\n$mapString\n}}"
)
}
}?.joinToString(",\n") ?: ""
buildNonStringConfig(
flavor,
configs.configType.type,
configs.name,
"new java.util.HashMap<String, java.util.List<String>>() {{\n$mapString\n}}"
)
}
}
}
}
Expand All @@ -267,10 +249,3 @@ fun buildNonStringConfig(productFlavour: ProductFlavor, type: String, name: Stri
value
)
}

fun buildStringRes(productFlavour: ProductFlavor, name: String, value: String?) {
requireNotNull(value) {
"Missing default value for stringRes $name"
}
productFlavour.resValue("string", name.lowercase(), value)
}

0 comments on commit 9c91f93

Please sign in to comment.