mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Generate null MapTiler BuildConfig values when not provided
Remove the default values from the Gradle file, the public MapTiler defaults are now only defined in MapTilerDefaults. buildConfigFieldStr now accepts a null value. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@ android {
|
||||
defaultConfig {
|
||||
buildConfigFieldStr(
|
||||
name = "MAPTILER_BASE_URL",
|
||||
value = BuildTimeConfig.SERVICES_MAPTILER_BASE_URL ?: "https://api.maptiler.com/maps"
|
||||
value = BuildTimeConfig.SERVICES_MAPTILER_BASE_URL,
|
||||
)
|
||||
buildConfigFieldStr(
|
||||
name = "MAPTILER_API_KEY",
|
||||
@@ -35,8 +35,7 @@ android {
|
||||
} else {
|
||||
System.getenv("ELEMENT_ANDROID_MAPTILER_API_KEY")
|
||||
?: readLocalProperty("services.maptiler.apikey")
|
||||
}
|
||||
?: ""
|
||||
},
|
||||
)
|
||||
buildConfigFieldStr(
|
||||
name = "MAPTILER_LIGHT_MAP_ID",
|
||||
@@ -45,9 +44,7 @@ android {
|
||||
} else {
|
||||
System.getenv("ELEMENT_ANDROID_MAPTILER_LIGHT_MAP_ID")
|
||||
?: readLocalProperty("services.maptiler.lightMapId")
|
||||
}
|
||||
// fall back to maptiler's default light map.
|
||||
?: "basic-v2"
|
||||
},
|
||||
)
|
||||
buildConfigFieldStr(
|
||||
name = "MAPTILER_DARK_MAP_ID",
|
||||
@@ -56,9 +53,7 @@ android {
|
||||
} else {
|
||||
System.getenv("ELEMENT_ANDROID_MAPTILER_DARK_MAP_ID")
|
||||
?: readLocalProperty("services.maptiler.darkMapId")
|
||||
}
|
||||
// fall back to maptiler's default dark map.
|
||||
?: "basic-v2-dark"
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -19,14 +19,13 @@ val LocalMapTilerConfig = staticCompositionLocalOf { buildTimeMapTilerConfig() }
|
||||
* The [MapTilerConfig] defined at build time, or null if no MapTiler API key has been provided.
|
||||
*/
|
||||
fun buildTimeMapTilerConfig(): MapTilerConfig? {
|
||||
return BuildConfig.MAPTILER_API_KEY
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.let { apiKey ->
|
||||
MapTilerConfig(
|
||||
apiKey = apiKey,
|
||||
lightStyleId = BuildConfig.MAPTILER_LIGHT_MAP_ID,
|
||||
darkStyleId = BuildConfig.MAPTILER_DARK_MAP_ID,
|
||||
baseUrl = BuildConfig.MAPTILER_BASE_URL
|
||||
)
|
||||
}
|
||||
// BuildConfig fields are null when not provided at build time.
|
||||
val apiKey: String? = BuildConfig.MAPTILER_API_KEY
|
||||
if (apiKey.isNullOrEmpty()) return null
|
||||
return MapTilerConfig(
|
||||
apiKey = apiKey,
|
||||
lightStyleId = BuildConfig.MAPTILER_LIGHT_MAP_ID,
|
||||
darkStyleId = BuildConfig.MAPTILER_DARK_MAP_ID,
|
||||
baseUrl = BuildConfig.MAPTILER_BASE_URL,
|
||||
)
|
||||
}
|
||||
|
||||
+2
-3
@@ -11,7 +11,6 @@ package io.element.android.features.location.impl
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.enterprise.api.remoteconfig.CustomMapTilerConfigProvider
|
||||
import io.element.android.features.enterprise.test.remoteconfig.aMapTilerConfig
|
||||
import io.element.android.features.location.api.BuildConfig
|
||||
import io.element.android.features.location.api.buildTimeMapTilerConfig
|
||||
import io.element.android.libraries.matrix.test.AN_EXCEPTION
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -30,7 +29,7 @@ class DefaultLocationServiceTest {
|
||||
)
|
||||
runCurrent()
|
||||
assertThat(locationService.mapTilerConfig.value).isEqualTo(buildTimeMapTilerConfig())
|
||||
assertThat(locationService.isServiceAvailable().value).isEqualTo(BuildConfig.MAPTILER_API_KEY.isNotEmpty())
|
||||
assertThat(locationService.isServiceAvailable().value).isEqualTo(buildTimeMapTilerConfig() != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,7 +39,7 @@ class DefaultLocationServiceTest {
|
||||
)
|
||||
runCurrent()
|
||||
assertThat(locationService.mapTilerConfig.value).isEqualTo(buildTimeMapTilerConfig())
|
||||
assertThat(locationService.isServiceAvailable().value).isEqualTo(BuildConfig.MAPTILER_API_KEY.isNotEmpty())
|
||||
assertThat(locationService.isServiceAvailable().value).isEqualTo(buildTimeMapTilerConfig() != null)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,14 +10,17 @@ package extension
|
||||
|
||||
import com.android.build.api.dsl.VariantDimension
|
||||
|
||||
/**
|
||||
* Adds a String field to the generated BuildConfig class. If [value] is null, the field will be null.
|
||||
*/
|
||||
fun VariantDimension.buildConfigFieldStr(
|
||||
name: String,
|
||||
value: String,
|
||||
value: String?,
|
||||
) {
|
||||
buildConfigField(
|
||||
type = "String",
|
||||
name = name,
|
||||
value = "\"$value\""
|
||||
value = value?.let { "\"$it\"" } ?: "null"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user