Skip to content

Commit 5b9d068

Browse files
committed
Merge branch 'main' into sample-renameing
2 parents fc4fa4a + 757c4fb commit 5b9d068

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

add-feature-layers/src/main/java/com/esri/arcgismaps/sample/addfeaturelayers/DownloadActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class DownloadActivity : DownloaderActivity() {
99
super.onCreate(savedInstanceState)
1010
downloadAndStartSample(
1111
Intent(this, MainActivity::class.java),
12-
// get the download path of the sample
13-
getExternalFilesDir(null)?.path.toString(),
12+
// get the app name of the sample
13+
getString(R.string.app_name),
1414
listOf(
1515
// ArcGIS Portal item containing the .mmpk mobile map package
1616
"https://www.arcgis.com/home/item.html?id=2b0f9e17105847809dfeb04e3cad69e0",

add-feature-layers/src/main/java/com/esri/arcgismaps/sample/addfeaturelayers/MainActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class MainActivity : AppCompatActivity() {
5353
activityMainBinding.mapView
5454
}
5555

56+
private val provisionPath: String by lazy {
57+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
58+
}
59+
5660
// enum to keep track of the selected source to display the feature layer
5761
enum class FeatureLayerSource(val menuPosition: Int) {
5862
SERVICE_FEATURE_TABLE(0),
@@ -130,8 +134,7 @@ class MainActivity : AppCompatActivity() {
130134
*/
131135
private suspend fun loadGeodatabase() {
132136
// locate the .geodatabase file in the device
133-
val geodatabaseFile =
134-
File(getExternalFilesDir(null), getString(R.string.geodatabase_la_trails))
137+
val geodatabaseFile = File(provisionPath, getString(R.string.geodatabase_la_trails))
135138
// instantiate the geodatabase with the file path
136139
val geodatabase = Geodatabase(geodatabaseFile.path)
137140
// load the geodatabase
@@ -159,7 +162,7 @@ class MainActivity : AppCompatActivity() {
159162
*/
160163
private suspend fun loadGeopackage() {
161164
// locate the .gpkg file in the device
162-
val geopackageFile = File(getExternalFilesDir(null), "/AuroraCO.gpkg")
165+
val geopackageFile = File(provisionPath, "/AuroraCO.gpkg")
163166
// instantiate the geopackage with the file path
164167
val geoPackage = GeoPackage(geopackageFile.path)
165168
// load the geopackage
@@ -183,7 +186,7 @@ class MainActivity : AppCompatActivity() {
183186
private suspend fun loadShapefile() {
184187
// locate the shape file in device
185188
val file = File(
186-
getExternalFilesDir(null),
189+
provisionPath,
187190
"/ScottishWildlifeTrust_ReserveBoundaries_20201102.shp"
188191
)
189192
// create a shapefile feature table from a named bundle resource

add-feature-layers/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
2-
<string name="app_name">Display feature layers</string>
2+
<string name="app_name">Add feature layers</string>
33
<string name="hint">Select a feature layer source</string>
44
<string name="sample_service_url">https://sampleserver6.arcgisonline.com/arcgis/rest/services/NapervilleShelters/FeatureServer/0</string>
55
<string name="geodatabase_la_trails">/LA_Trails.geodatabase</string>

display-map-from-mobile-map-package/src/main/java/com/esri/arcgismaps/sample/displaymapfrommobilemappackage/DownloadActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class DownloadActivity : DownloaderActivity() {
2525
super.onCreate(savedInstanceState)
2626
downloadAndStartSample(
2727
Intent(this, MainActivity::class.java),
28-
// get the download path of the sample
29-
getExternalFilesDir(null)?.path.toString(),
28+
// get the app name of the sample
29+
getString(R.string.app_name),
3030
listOf(
3131
// ArcGIS Portal item containing the .mmpk mobile map package
3232
"https://www.arcgis.com/home/item.html?id=e1f3a7254cb845b09450f54937c16061"

display-map-from-mobile-map-package/src/main/java/com/esri/arcgismaps/sample/displaymapfrommobilemappackage/MainActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import com.arcgismaps.mapping.MobileMapPackage
2828
import com.esri.arcgismaps.sample.displaymapfrommobilemappackage.databinding.ActivityMainBinding
2929
import com.google.android.material.snackbar.Snackbar
3030
import kotlinx.coroutines.launch
31+
import java.io.File
3132

3233
class MainActivity : AppCompatActivity() {
3334

3435
private val TAG = MainActivity::class.java.simpleName
3536

37+
private val provisionPath: String by lazy {
38+
getExternalFilesDir(null)?.path.toString() + File.separator + getString(R.string.app_name)
39+
}
40+
3641
override fun onCreate(savedInstanceState: Bundle?) {
3742
super.onCreate(savedInstanceState)
3843

@@ -48,7 +53,7 @@ class MainActivity : AppCompatActivity() {
4853
lifecycle.addObserver(mapView)
4954

5055
// get the file path of the (.mmpk) file
51-
val filePath = getExternalFilesDir(null)?.path + getString(R.string.yellowstone_mmpk)
56+
val filePath = provisionPath + getString(R.string.yellowstone_mmpk)
5257

5358
// create the mobile map package
5459
val mapPackage = MobileMapPackage(filePath)

samples-lib/src/main/java/com/esri/arcgismaps/sample/sampleslib/DownloaderActivity.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,29 @@ import java.util.zip.ZipInputStream
4646
@OptIn(ExperimentalCoroutinesApi::class)
4747
abstract class DownloaderActivity : AppCompatActivity() {
4848

49+
/**
50+
* Returns the location of the download folder based on the [appName]
51+
*/
52+
private fun getDownloadFolder(appName: String): String{
53+
return getExternalFilesDir(null)?.path.toString() + File.separator + appName
54+
}
55+
4956
// set up data binding for the activity
5057
private val activitySamplesBinding: ActivitySamplesBinding by lazy {
5158
DataBindingUtil.setContentView(this, R.layout.activity_samples)
5259
}
5360

5461
/**
5562
* Gets the [provisionURL] of the portal item to download at
56-
* the [samplePath], once download completes it starts the [mainActivity]
63+
* the [sampleName], once download completes it starts the [mainActivity]
5764
*/
5865
fun downloadAndStartSample(
5966
mainActivity: Intent,
60-
samplePath: String,
67+
sampleName: String,
6168
provisionURLs: List<String>
6269
) {
70+
// get the path to download files
71+
val samplePath: String = getDownloadFolder(sampleName)
6372
// start the download manager to automatically add the .mmpk file to the app
6473
// alternatively, you can use ADB/Device File Explorer
6574
lifecycleScope.launch {
@@ -95,6 +104,9 @@ abstract class DownloaderActivity : AppCompatActivity() {
95104

96105
// the provision folder at the destination
97106
val provisionFolder = File(destinationPath)
107+
if (!provisionFolder.exists()) {
108+
provisionFolder.mkdirs()
109+
}
98110

99111
// suspends the coroutine until the dialog is resolved.
100112
val downloadRequired: Boolean =
@@ -103,8 +115,8 @@ abstract class DownloaderActivity : AppCompatActivity() {
103115
val provisionQuestionDialog = AlertDialog.Builder(this@DownloaderActivity)
104116
.setTitle("Download data?")
105117

106-
if (provisionFolder.exists()) {
107-
// folder exists, prompt user to download again
118+
if (provisionFolder.list()?.isNotEmpty() == true) {
119+
// folder is not empty, prompt user to download again
108120
provisionQuestionDialog.setMessage(getString(R.string.already_provisioned))
109121
// if user taps "Re-download" data
110122
provisionQuestionDialog.setNeutralButton("Re-download data") { dialog, _ ->

0 commit comments

Comments
 (0)