summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-04-25 18:00:18 +0200
committerTobrun <tobrun.van.nuland@gmail.com>2019-04-26 16:08:37 +0200
commit70abecdde8fffd5d3b167fcb993eaa8cb01ffc06 (patch)
tree1f0f0702a4f30386add77a7c25b9db47688d4275
parent5e04091795d5e27b787a16b2b0be2140e066ceee (diff)
downloadqtlocation-mapboxgl-70abecdde8fffd5d3b167fcb993eaa8cb01ffc06.tar.gz
[android] - callbacks as fields to MergeOfflineAcitivity
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/MergeOfflineRegionsActivity.kt74
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt2
2 files changed, 42 insertions, 34 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/MergeOfflineRegionsActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/MergeOfflineRegionsActivity.kt
index 45ff67d688..e9321d5e27 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/MergeOfflineRegionsActivity.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/MergeOfflineRegionsActivity.kt
@@ -4,8 +4,8 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.mapbox.mapboxsdk.Mapbox
-import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.log.Logger
+import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.offline.OfflineManager
import com.mapbox.mapboxsdk.offline.OfflineRegion
import com.mapbox.mapboxsdk.storage.FileSource
@@ -20,6 +20,43 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
private const val TEST_STYLE = Style.SATELLITE
}
+ private val onFileCopiedListener = object : FileUtils.OnFileCopiedFromAssetsListener {
+ override fun onFileCopiedFromAssets() {
+ Toast.makeText(
+ this@MergeOfflineRegionsActivity,
+ String.format("OnFileCOpied."),
+ Toast.LENGTH_LONG).show()
+ mergeDb()
+ }
+
+ override fun onError() {
+ Toast.makeText(
+ this@MergeOfflineRegionsActivity,
+ String.format("Error copying DB file."),
+ Toast.LENGTH_LONG).show()
+ }
+ }
+
+ private val onRegionMergedListener = object : OfflineManager.MergeOfflineRegionsCallback {
+ override fun onMerge(offlineRegions: Array<OfflineRegion>) {
+ mapView.getMapAsync {
+ it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
+ }
+ Toast.makeText(
+ this@MergeOfflineRegionsActivity,
+ String.format("Merged %d regions.", offlineRegions.size),
+ Toast.LENGTH_LONG).show()
+ }
+
+ override fun onError(error: String) {
+ Toast.makeText(
+ this@MergeOfflineRegionsActivity,
+ String.format("Offline DB merge error."),
+ Toast.LENGTH_LONG).show()
+ Logger.e(LOG_TAG, error)
+ }
+ }
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_merge_offline_regions)
@@ -39,42 +76,13 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
private fun copyAsset() {
// copy db asset to internal memory
- FileUtils.CopyFileFromAssetsTask(this, object : FileUtils.OnFileCopiedFromAssetsListener {
- override fun onFileCopiedFromAssets() {
- mergeDb()
- }
-
- override fun onError() {
- Toast.makeText(
- this@MergeOfflineRegionsActivity,
- String.format("Error copying DB file."),
- Toast.LENGTH_LONG).show()
- }
- }).execute(TEST_DB_FILE_NAME, FileSource.getResourcesCachePath(this))
+ FileUtils.CopyFileFromAssetsTask(this, onFileCopiedListener).execute(TEST_DB_FILE_NAME, FileSource.getResourcesCachePath(this))
}
private fun mergeDb() {
OfflineManager.getInstance(this).mergeOfflineRegions(
- FileSource.getResourcesCachePath(this) + "/" + TEST_DB_FILE_NAME,
- object : OfflineManager.MergeOfflineRegionsCallback {
- override fun onMerge(offlineRegions: Array<OfflineRegion>) {
- mapView.getMapAsync{
- it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
- }
- Toast.makeText(
- this@MergeOfflineRegionsActivity,
- String.format("Merged %d regions.", offlineRegions.size),
- Toast.LENGTH_LONG).show()
- }
-
- override fun onError(error: String) {
- Toast.makeText(
- this@MergeOfflineRegionsActivity,
- String.format("Offline DB merge error."),
- Toast.LENGTH_LONG).show()
- Logger.e(LOG_TAG, error)
- }
- })
+ FileSource.getResourcesCachePath(this) + "/" + TEST_DB_FILE_NAME, onRegionMergedListener
+ )
}
override fun onStart() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt
index 26f2a2c56b..457ad928db 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt
@@ -19,7 +19,7 @@ class FileUtils {
override fun doInBackground(vararg strings: String): Boolean? {
val assetName = strings[0]
val destinationPath = strings[1]
-
+
contextWeakReference.get()?.let {
try {
copyAsset(it, assetName, destinationPath)