Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14e51baa authored by Fynn Godau's avatar Fynn Godau
Browse files

Inject stadia API key if set

New options for `local.properties` (`stadia.key`) or as
an environment variable (`STADIA_API_KEY`)
parent bb5c25b5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ android {
        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk
        buildConfigField "String", "MAPBOX_KEY", "\"${localProperties.getProperty("mapbox.key", System.getenv('MAPBOX_VECTOR_TILES_KEY') ?: "")}\""
        buildConfigField "String", "STADIA_KEY", "\"${localProperties.getProperty("stadia.key", System.getenv('STADIA_API_KEY') ?: "")}\""

        ndk {
            abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
+17 −0
Original line number Diff line number Diff line
@@ -49,6 +49,23 @@ fun getStyle(
        ).bufferedReader().readText()
    )

    // Inject API key
    if (BuildConfig.STADIA_KEY.isNotEmpty()) {
        val sourceArray = styleJson.getJSONObject("sources")
        for (i in sourceArray.keys()) {
            val sourceObject = sourceArray.getJSONObject(i)
            if (sourceObject.has("url")) {
                sourceObject.put("url", "${sourceObject["url"]}?api_key=${BuildConfig.STADIA_KEY}")
            }
            if (sourceObject.has("tiles")) {
                val tilesArray = sourceObject.getJSONArray("tiles")
                for (j in 0 until tilesArray.length()) {
                    tilesArray.put(j, "${tilesArray.getString(j)}?api_key=${BuildConfig.STADIA_KEY}")
                }
            }
        }
    }

    styleOptions?.apply(styleJson)

    return if (styleFromFileWorkaround) {