Skip to content

Commit

Permalink
Remove the Gradle Secrets plugin (#305)
Browse files Browse the repository at this point in the history
* Remove the Gradle Secrets plugin

* Support use without API key
  • Loading branch information
ianthetechie authored Oct 22, 2024
1 parent 359ec90 commit 08898d5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
3 changes: 2 additions & 1 deletion android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ To run the demo app, you'll need a Stadia Maps API key
(free for development and evaluation use; no credit card required; get one at https://client.stadiamaps.com/).
You can also modify it to work with your preferred maps and routing vendor by editing `AppModule.kt`.

Set your API key in `local.properties` to run the demo app:
Set your API key in `local.properties` to run the demo app
(it is functional with demo tiles and routing, but only for limited testing):

```properties
stadiaApiKey=YOUR-API-KEY
Expand Down
7 changes: 6 additions & 1 deletion android/demo-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
alias libs.plugins.jetbrainsKotlinAndroid
alias libs.plugins.ktfmt
alias libs.plugins.compose.compiler
alias libs.plugins.mapsplatform.secrets.plugin
}

android {
Expand All @@ -21,6 +20,12 @@ android {
vectorDrawables {
useSupportLibrary true
}

Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())

android.buildFeatures.buildConfig true
buildConfigField "String", "stadiaApiKey", "\"${properties.getProperty("stadiaApiKey")}\""
}

buildTypes {
Expand Down
6 changes: 0 additions & 6 deletions android/demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
android:theme="@style/Theme.Ferrostar"
tools:targetApi="31">

<!--
Set a value for stadiaApiKey in local.properties.
You can get an API key (no credit card required; free for development and evaluation) at client.stadiamaps.com
-->
<meta-data android:name="stadiaApiKey" android:value="${stadiaApiKey}" />

<activity
android:name="com.stadiamaps.ferrostar.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.stadiamaps.ferrostar

import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import com.stadiamaps.ferrostar.composeui.notification.DefaultForegroundNotificationBuilder
import com.stadiamaps.ferrostar.core.AlternativeRouteProcessor
Expand Down Expand Up @@ -36,21 +35,28 @@ object AppModule {
// You can also modify this file to use your preferred sources for maps and/or routing.
// See https://stadiamaps.github.io/ferrostar/vendors.html for vendors known to work with
// Ferrostar.
val stadiaApiKey: String by lazy {
val appInfo =
appContext.packageManager.getApplicationInfo(
appContext.packageName, PackageManager.GET_META_DATA)
val metaData = appInfo.metaData

metaData.getString("stadiaApiKey")!!
}
//
// NOTE: Don't set this directly in source code. Add a line to your local.properties file:
// stadiaApiKey=YOUR-API-KEY
val stadiaApiKey =
if (BuildConfig.stadiaApiKey.isBlank() || BuildConfig.stadiaApiKey == "null") {
null
} else {
BuildConfig.stadiaApiKey
}

val mapStyleUrl: String by lazy {
"https://tiles.stadiamaps.com/styles/outdoors.json?api_key=$stadiaApiKey"
if (stadiaApiKey != null)
"https://tiles.stadiamaps.com/styles/outdoors.json?api_key=$stadiaApiKey"
else "https://demotiles.maplibre.org/style.json"
}

val valhallaEndpointUrl: URL by lazy {
URL("https://api.stadiamaps.com/route/v1?api_key=$stadiaApiKey")
if (stadiaApiKey != null) {
URL("https://api.stadiamaps.com/route/v1?api_key=$stadiaApiKey")
} else {
URL("https://valhalla1.openstreeetmap.de/route")
}
}

fun init(context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,33 @@ fun DemoNavigationScene(
InnerGridView(
modifier = modifier.fillMaxSize().padding(bottom = 16.dp, top = 16.dp),
topCenter = {
AutocompleteSearch(
apiKey = AppModule.stadiaApiKey, userLocation = loc.toAndroidLocation()) {
feature ->
feature.center()?.let { center ->
// Fetch a route in the background
scope.launch(Dispatchers.IO) {
// TODO: Fail gracefully
val routes =
AppModule.ferrostarCore.getRoutes(
loc,
listOf(
Waypoint(
coordinate =
GeographicCoordinate(
center.latitude, center.longitude),
kind = WaypointKind.BREAK),
))
AppModule.stadiaApiKey?.let { apiKey ->
AutocompleteSearch(apiKey = apiKey, userLocation = loc.toAndroidLocation()) {
feature ->
feature.center()?.let { center ->
// Fetch a route in the background
scope.launch(Dispatchers.IO) {
// TODO: Fail gracefully
val routes =
AppModule.ferrostarCore.getRoutes(
loc,
listOf(
Waypoint(
coordinate =
GeographicCoordinate(center.latitude, center.longitude),
kind = WaypointKind.BREAK),
))

val route = routes.first()
viewModel = AppModule.ferrostarCore.startNavigation(route = route)
val route = routes.first()
viewModel = AppModule.ferrostarCore.startNavigation(route = route)

if (locationProvider is SimulatedLocationProvider) {
locationProvider.setSimulatedRoute(route)
}
if (locationProvider is SimulatedLocationProvider) {
locationProvider.setSimulatedRoute(route)
}
}
}
}
}
})
}
}) { uiState ->
Expand Down
2 changes: 0 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ junitCompose = "1.7.3"
espressoCore = "3.6.1"
okhttp-mock = "2.0.0"
mavenPublish = "0.29.0"
secretsGradlePlugin = "2.0.1"
material = "1.12.0"
stadiaAutocompleteSearch = "1.0.0"

Expand Down Expand Up @@ -78,4 +77,3 @@ ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
mapsplatform-secrets-plugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }

0 comments on commit 08898d5

Please sign in to comment.