From b871082b9e3b1c1a68fbd264bbe43fd07eaf49e0 Mon Sep 17 00:00:00 2001 From: kingofirony Date: Mon, 27 Jul 2015 17:23:56 -0400 Subject: [PATCH] removes version from manifest and cleans key downloading logic --- app/src/main/AndroidManifest.xml | 4 +--- .../mapzen/erasermap/CrashReportService.java | 4 +++- .../erasermap/model/ManifestDownLoader.kt | 17 ++++++++++++--- .../com/mapzen/erasermap/view/MainActivity.kt | 21 ++++++++++--------- .../erasermap/model/ManifestDownLoaderTest.kt | 3 +-- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 800b53f5..a8794fbe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,6 @@ + package="com.mapzen.erasermap"> diff --git a/app/src/main/java/com/mapzen/erasermap/CrashReportService.java b/app/src/main/java/com/mapzen/erasermap/CrashReportService.java index 0f7b4c90..cc0b4b79 100644 --- a/app/src/main/java/com/mapzen/erasermap/CrashReportService.java +++ b/app/src/main/java/com/mapzen/erasermap/CrashReportService.java @@ -6,6 +6,8 @@ public class CrashReportService { public void initAndStartSession(Context context) { - Mint.initAndStartSession(context, BuildConfig.MINT_API_KEY); + if (BuildConfig.MINT_API_KEY != null) { + Mint.initAndStartSession(context, BuildConfig.MINT_API_KEY); + } } } diff --git a/app/src/main/kotlin/com/mapzen/erasermap/model/ManifestDownLoader.kt b/app/src/main/kotlin/com/mapzen/erasermap/model/ManifestDownLoader.kt index 5e53d004..0a0a2256 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/model/ManifestDownLoader.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/model/ManifestDownLoader.kt @@ -1,13 +1,24 @@ package com.mapzen.erasermap.model +import com.google.common.io.Files + +import android.content.Context import android.os.AsyncTask import android.util.Log import com.google.gson.Gson -import com.squareup.okhttp.OkHttpClient -import com.squareup.okhttp.Request -import com.squareup.okhttp.Response +import com.google.gson.JsonParseException +import com.mapzen.erasermap.model.ManifestModel +import com.squareup.okhttp.* + +import java.io.BufferedInputStream +import java.io.File import java.io.IOException +import java.io.InputStream +import java.net.HttpURLConnection +import java.net.MalformedURLException import java.net.URL +import java.util.concurrent.TimeUnit +import javax.inject.Inject public class ManifestDownLoader() { private var client: OkHttpClient? = null diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt index 9f0f9f18..4a7231db 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt @@ -83,6 +83,7 @@ public class MainActivity : AppCompatActivity(), MainViewController, Router.Call super.onCreate(savedInstanceState) app = getApplication() as EraserMapApplication app?.component()?.inject(this) + initCrashReportService() setContentView(R.layout.activity_main) presenter?.mainViewController = this presenter?.bus = bus @@ -93,7 +94,7 @@ public class MainActivity : AppCompatActivity(), MainViewController, Router.Call initReverseButton() centerMapOnCurrentLocation() presenter?.onRestoreViewState() - getApiKeys({initCrashReportService()}) + getApiKeys() } override fun onStart() { @@ -148,16 +149,16 @@ public class MainActivity : AppCompatActivity(), MainViewController, Router.Call crashReportService?.initAndStartSession(this) } - private fun getApiKeys(callback : () -> Unit) { + private fun getApiKeys() { var dl: ManifestDownLoader = ManifestDownLoader() - dl.download(apiKeys, callback) - - if(apiKeys?.getValhallaApiKey()== null) { - apiKeys?.setValhallaApiKey(BuildConfig.VALHALLA_API_KEY) - } - if(apiKeys?.getVectorTileApiKeyReleaseProp()== null) { - apiKeys?.setVectorTileApiKeyReleaseProp(BuildConfig.VECTOR_TILE_API_KEY) - } + dl.download(apiKeys, { + if(apiKeys?.getValhallaApiKey()== null) { + apiKeys?.setValhallaApiKey(BuildConfig.VALHALLA_API_KEY) + } + if(apiKeys?.getVectorTileApiKeyReleaseProp()== null) { + apiKeys?.setVectorTileApiKeyReleaseProp(BuildConfig.VECTOR_TILE_API_KEY) + } + }) } private fun initLocationUpdates() { diff --git a/app/src/test/java/com/mapzen/erasermap/model/ManifestDownLoaderTest.kt b/app/src/test/java/com/mapzen/erasermap/model/ManifestDownLoaderTest.kt index 4d824312..4becf2de 100644 --- a/app/src/test/java/com/mapzen/erasermap/model/ManifestDownLoaderTest.kt +++ b/app/src/test/java/com/mapzen/erasermap/model/ManifestDownLoaderTest.kt @@ -52,8 +52,7 @@ public class ManifestDownLoaderTest { public fun shouldSetManifestModelObject() { var keys: ManifestModel = ManifestModel() server?.enqueue(MockResponse().setBody(sampleResponse)) - downLoader?.download(keys, { - }) + downLoader?.download(keys, {}) server?.takeRequest(1000, TimeUnit.MILLISECONDS); assertThat(keys.getValhallaApiKey()).isEqualTo("routeKey") assertThat(keys.getVectorTileApiKeyReleaseProp()).isEqualTo("vectorKey")