Skip to content

Commit

Permalink
Only use presence of download token to include/disclude Mapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg authored and grzesiek2010 committed Jun 29, 2022
1 parent d101b29 commit 96afe0e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ Certain functions in ODK Collect depend on cloud services that require API keys
**Google Maps API**: When the "Google Maps SDK" option is selected in the "User interface" settings, ODK Collect uses the Google Maps API for displaying maps in the geospatial widgets (GeoPoint, GeoTrace, and GeoShape). To enable this API:
1. [Get a Google Maps API key](https://developers.google.com/maps/documentation/android-api/signup). Note that this requires a credit card number, though the card will not be charged immediately; some free API usage is permitted. You should carefully read the terms before providing a credit card number.
1. Edit or create `collect_app/secrets.properties` and set the `GOOGLE_MAPS_API_KEY` property to your API key. You should end up with a line that looks like this:
1. Edit or create `secrets.properties` and set the `GOOGLE_MAPS_API_KEY` property to your API key. You should end up with a line that looks like this:
```
GOOGLE_MAPS_API_KEY=AIbzvW8e0ub...
```
**Mapbox Maps SDK for Android**: When the "Mapbox SDK" option is selected in the "User interface" settings, ODK Collect uses the Mapbox SDK for displaying maps in the geospatial widgets (GeoPoint, GeoTrace, and GeoShape). To enable this API:
1. [Create a Mapbox account](https://www.mapbox.com/signup/). Note that signing up with the "Pay-As-You-Go" plan does not require a credit card. Mapbox provides free API usage up to the monthly thresholds documented at [https://www.mapbox.com/pricing](https://www.mapbox.com/pricing). If your usage exceeds these thresholds, you will receive e-mail with instructions on how to add a credit card for payment; services will remain live until the end of the 30-day billing term, after which the account will be deactivated and will require a credit card to reactivate.
1. Find your access token on your [account page](https://account.mapbox.com/).
1. Edit or create `collect_app/secrets.properties` and set the `MAPBOX_ACCESS_TOKEN` property to your access token. You should end up with a line that looks like this:
1. Edit or create `secrets.properties` and set the `MAPBOX_ACCESS_TOKEN` property to your access token. You should end up with a line that looks like this:
```
MAPBOX_ACCESS_TOKEN=pk.eyJk3bumVp4i...
```
Expand Down Expand Up @@ -242,9 +242,9 @@ Maintainers keep a folder with a clean checkout of the code and use [jenv.be](ht

- the keystore file and passwords

- a `secrets.properties` file in the `collect_app` folder with the following:
- a `secrets.properties` file in the root project folder folder with the following:
```
// collect_app/secrets.properties
// secrets.properties
RELEASE_STORE_FILE=/path/to/collect.keystore
RELEASE_STORE_PASSWORD=secure-store-password
RELEASE_KEY_ALIAS=key-alias
Expand All @@ -262,4 +262,4 @@ Maintainers keep a folder with a clean checkout of the code and use [jenv.be](ht
- verify a basic "happy path": scan a QR code to configure a new project, get a blank form, fill it, open the form map (confirms that the Google Maps key is correct), send form
- create and publish scheduled forum post with release description
- write Play Store release notes, include link to forum post
- upload to Play Store
- upload to Play Store
11 changes: 1 addition & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dependencies.Versions
apply from: 'secrets.gradle'

// Plugin for detecting outdated dependencies. Run './gradlew dependencyUpdates' to generate a report.
apply plugin: "com.github.ben-manes.versions"
Expand Down Expand Up @@ -26,16 +27,6 @@ buildscript {
}

allprojects {
ext.getSecrets = { ->
def secretsFile = file('secrets.properties')
def secrets = new Properties()
if (secretsFile.exists()) {
secrets.load(new FileInputStream(secretsFile))
}

return secrets
}

repositories {
// Needs to go first to get specialty libraries https://stackoverflow.com/a/48438866/137744
google()
Expand Down
2 changes: 1 addition & 1 deletion collect_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ dependencies {
implementation project(':maps')
implementation project(':osmdroid')

if (hasProperty("includeMapbox") && getProperty('includeMapbox') == 'true') {
if (getSecrets().getProperty('MAPBOX_DOWNLOADS_TOKEN', '') != '') {
implementation project(':mapbox')
}

Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ the specific language governing permissions and limitations under the License.
<activity android:name=".activities.WebViewActivity" />
<activity android:name=".activities.CaptureSelfieVideoActivity" />

<!-- Configure this key by setting GOOGLE_MAPS_API_KEY in collect_app/secrets.properties. -->
<!-- Configure this key by setting GOOGLE_MAPS_API_KEY in secrets.properties. -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY" />
Expand Down
10 changes: 10 additions & 0 deletions secrets.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Helper for grabbing secrets from `secrets.properties` file
ext.getSecrets = { ->
def secretsFile = file("$rootDir/secrets.properties")
def secrets = new Properties()
if (secretsFile.exists()) {
secrets.load(new FileInputStream(secretsFile))
}

return secrets
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include ':servicetest'
include ':maps'
include ':osmdroid'

if (hasProperty("includeMapbox") && getProperty('includeMapbox') == 'true') {
apply from: 'secrets.gradle'
if (getSecrets().getProperty('MAPBOX_DOWNLOADS_TOKEN', '') != '') {
include ':mapbox'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.odk.collect.shared

import java.util.function.Supplier

interface MultiClassProviderHost {
fun getMultiClassProvider(): MultiClassProvider
}

interface MultiClassProvider {
fun <T> provide(clazz: Class<T>): T
}

class SupplierMultiClassProvider : MultiClassProvider {

private val suppliers: MutableMap<Class<*>, Supplier<*>> = mutableMapOf()

fun <T> addSupplier(clazz: Class<T>, supplier: Supplier<T>) {
suppliers[clazz] = supplier
}

@Suppress("UNCHECKED_CAST")
override fun <T> provide(clazz: Class<T>): T {
return suppliers[clazz]!!.get() as T
}
}

0 comments on commit 96afe0e

Please sign in to comment.