Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
9320678
Create offline toolkit module & microapp (#835)
shubham7109 May 1, 2025
7aa9ea4
Changes to initialize preplanned map area (#843)
puneet-pdx May 8, 2025
c476ab6
Enhance preplanned area list (#846)
puneet-pdx May 14, 2025
0676f2a
Add Workmanager to OfflineMapAreas (#844)
shubham7109 May 14, 2025
ec5f2b4
Wire workmanager with UI (#849)
shubham7109 May 15, 2025
e602563
Add backing properties (#850)
puneet-pdx May 15, 2025
b5b3718
Add WorkManagerRepository (#851)
puneet-pdx May 20, 2025
8c549d4
OfflineMapAreas: Doc rework (#852)
shubham7109 May 20, 2025
4ce9d92
Add fix so that we always run the workManagerRepository fun in the vi…
puneet-pdx May 22, 2025
8a212e4
update api file
puneet-pdx May 22, 2025
ac41301
WIP
puneet-pdx May 23, 2025
d069b05
WIP
puneet-pdx May 23, 2025
38716d1
some clean up and added currently open message
puneet-pdx May 23, 2025
5964dc6
remove unused fun
puneet-pdx May 27, 2025
484a530
Add fix so that we always run the workManagerRepository funs in viewM…
puneet-pdx May 28, 2025
3b1376c
Merge branch 'feature-branches/offline-map-areas' into puneet/5736_ad…
puneet-pdx May 28, 2025
e3a0d50
update api file
puneet-pdx May 28, 2025
2ebed08
Merge branch 'feature-branches/offline-map-areas' into v.next_copy
puneet-pdx May 28, 2025
a28fca6
Update feature branch with latest v.next changes (#864)
shubham7109 May 28, 2025
96334e7
Merge branch 'feature-branches/offline-map-areas' into puneet/5736_ad…
puneet-pdx May 28, 2025
5528b6c
remove unused import
puneet-pdx May 28, 2025
903954b
add patch fixes
shubham7109 May 28, 2025
12467b1
Add additional functionality (#859)
puneet-pdx May 29, 2025
78b6255
Merge branch 'feature-branches/offline-map-areas' into shubham/patch-…
shubham7109 May 29, 2025
6d05b88
Merge branch 'feature-branches/offline-map-areas' into shubham/patch-…
shubham7109 May 29, 2025
33e1476
Add jobWorkerUuidKey with notification patch
shubham7109 May 29, 2025
ddb846c
revert gradle-wrapper changes
shubham7109 May 29, 2025
a3e2d89
revert settings.gradle.kts change
shubham7109 May 29, 2025
2321c25
Add notification cancel fix
shubham7109 May 29, 2025
795753e
Enhance createCancelPendingIntent and add stopReason
shubham7109 May 29, 2025
bc5acee
test workDataOf error reporting
shubham7109 May 29, 2025
80f1a0b
Switch between online and offline map (#865)
puneet-pdx May 29, 2025
ef30113
Merge branch 'feature-branches/offline-map-areas' into shubham/patch-…
shubham7109 May 29, 2025
caa4fdf
migrate feature-forms-app experience
shubham7109 May 30, 2025
a88fc5b
load selected map with oma
shubham7109 May 30, 2025
b3466a9
cleanup ff code and migrate offline/online map switching
shubham7109 May 30, 2025
17d406a
set default map as Naperville water network
shubham7109 May 30, 2025
afee028
Notification cancel fix (#866)
shubham7109 May 31, 2025
df053fa
working on offline map info
shubham7109 Jun 3, 2025
f380654
Moved constants, added OfflineURLs, and updated WorkManagerRepository
shubham7109 Jun 4, 2025
997d9bf
Add movePreplannedJobResultToDestination logic and add constructor(po…
shubham7109 Jun 4, 2025
7899462
Add movePreplannedOfflineMapInfoToDestination and movePreplannedJobRe…
shubham7109 Jun 4, 2025
2b53d8d
clean up fixes and comments
shubham7109 Jun 5, 2025
fa0cb73
Added restoration support
shubham7109 Jun 5, 2025
2769618
Update offline.api
shubham7109 Jun 5, 2025
bedc2fa
WIP
puneet-pdx Jun 5, 2025
131cd4d
Merge branch 'shubham/5760-OfflineMapInfo' into shubham/full-oma-expe…
shubham7109 Jun 5, 2025
3fc5539
WIP
puneet-pdx Jun 6, 2025
03b4600
Changes to show map area details in a modal bottomsheet
puneet-pdx Jun 9, 2025
eacad89
Offline map info (#870)
shubham7109 Jun 9, 2025
e4611b2
Merge branch 'feature-branches/offline-map-areas' into puneet/5738_De…
puneet-pdx Jun 9, 2025
7c0be3d
copy info file only if it exists in the pending directory
puneet-pdx Jun 9, 2025
ab2f851
add scroll to bottomsheet
puneet-pdx Jun 9, 2025
0ec043e
refactor MapAreaDetailsScreen
puneet-pdx Jun 9, 2025
c8d560f
add newline
puneet-pdx Jun 9, 2025
ca38673
update build.gradle to omit composableSingleton for MapAreaDetailsScreen
puneet-pdx Jun 9, 2025
54c0d2c
added patch changes & cleanup
shubham7109 Jun 10, 2025
eb80b1f
fix exists logic
shubham7109 Jun 10, 2025
4dac8a9
cancel scope after initialization
puneet-pdx Jun 10, 2025
ca8db97
Add remove download methods to OfflineRepository
puneet-pdx Jun 11, 2025
38ae889
Match dir as File and path as String
shubham7109 Jun 11, 2025
029efa7
Merge branch 'shubham/offline-map-info-cleanup-patches' into shubham/…
shubham7109 Jun 11, 2025
53af552
Merge branch 'puneet/5738_DetailsScreen' into shubham/full-oma-experi…
shubham7109 Jun 11, 2025
7522cbb
Update OfflineRepository.kt
shubham7109 Jun 11, 2025
6d2f574
Testing OnDeviceMapInfo
shubham7109 Jun 11, 2025
156c2b6
add delete support for OfflineRepository
shubham7109 Jun 11, 2025
15a3be2
update offlineMapInfos
puneet-pdx Jun 11, 2025
b3280fd
address code review comments
puneet-pdx Jun 11, 2025
c38e027
OfflineMapInfo patch changes & cleanup (#876)
shubham7109 Jun 11, 2025
4dc1ba9
Merge branch 'feature-branches/offline-map-areas' into puneet/5738_De…
puneet-pdx Jun 11, 2025
9beeb25
address code review comments
puneet-pdx Jun 11, 2025
1b32c26
apply feedback
puneet-pdx Jun 11, 2025
2eb03d2
Add MapAreaDetails screen (#875)
puneet-pdx Jun 11, 2025
02dbc59
Merge branch 'feature-branches/offline-map-areas' into shubham/full-o…
shubham7109 Jun 12, 2025
f620936
merge changes
shubham7109 Jun 12, 2025
70c1316
Merge branch 'puneet/5738_DetailsScreen' into shubham/full-oma-experi…
shubham7109 Jun 12, 2025
f6fedd7
Make _offlineMapInfos as SnapshotStateList
shubham7109 Jun 12, 2025
9d57bd2
Changes to make OfflineRepository Singleton, to support single instan…
puneet-pdx Jun 13, 2025
1a52495
some clean up
puneet-pdx Jun 13, 2025
013d534
adding support for various failures
shubham7109 Jun 13, 2025
66dfba0
Revert "adding support for various failures"
shubham7109 Jun 13, 2025
f353e0f
added composables for various failures
shubham7109 Jun 13, 2025
e009096
update api file
puneet-pdx Jun 13, 2025
c6bfffa
Merge branch 'shubham/Support-map-areas-various-fail-reasons' into sh…
shubham7109 Jun 13, 2025
20ef1c3
Merge remote-tracking branch 'origin/puneet/5982_OfflineRepository_Si…
shubham7109 Jun 13, 2025
c26283b
restore offline various fail reasons
shubham7109 Jun 13, 2025
19cce5f
Changes to make OfflineRepository Singleton, to support single instan…
puneet-pdx Jun 13, 2025
579e0aa
wired up offline only mode!
shubham7109 Jun 16, 2025
d6f284a
Merge branch 'feature-branches/offline-map-areas' into shubham/Suppor…
shubham7109 Jun 16, 2025
8cfae96
wired up offline only mode!
shubham7109 Jun 16, 2025
57ea012
update initialize to retryLoad()
shubham7109 Jun 16, 2025
9b6d006
wired up rest of composables
shubham7109 Jun 16, 2025
48b2960
Merge branch 'shubham/Support-map-areas-various-fail-reasons' into sh…
shubham7109 Jun 16, 2025
3b07b56
Wire up on demand init and add icon for "Add map area"
shubham7109 Jun 16, 2025
693a81d
Merge branch 'shubham/Support-map-areas-various-fail-reasons' into sh…
shubham7109 Jun 16, 2025
285c203
add doc cleanup
shubham7109 Jun 16, 2025
908758d
Update offline.api
shubham7109 Jun 16, 2025
45b88c3
Merge branch 'shubham/Support-map-areas-various-fail-reasons' into sh…
shubham7109 Jun 16, 2025
da9d9c4
Added on demand maps
shubham7109 Jun 16, 2025
614943c
minor error fix
shubham7109 Jun 16, 2025
4e31823
Merge branch 'shubham/Support-map-areas-various-fail-reasons' into sh…
shubham7109 Jun 16, 2025
730d88c
Remove usage of ExperimentalMaterial3Api and copy ModalBottomSheet (#…
puneet-pdx Jun 18, 2025
650ba13
Support map areas various fail reasons and errors (#885)
shubham7109 Jun 18, 2025
e28a493
Enhance OfflineMapAreas microapp (#893)
shubham7109 Jun 18, 2025
e831ca4
Add sheetGesturesEnabled (#894)
puneet-pdx Jun 18, 2025
db2b8f0
Init on demand map areas selector screen (#895)
shubham7109 Jun 20, 2025
0f35c3a
Init OnDemand map areas screen (#900)
puneet-pdx Jun 24, 2025
3a3b41b
Level of detail (#902)
shubham7109 Jun 24, 2025
d80f04c
Merge branch 'feature-branches/offline-map-areas' into shubham/full-o…
shubham7109 Jun 24, 2025
fef98ee
wired functionality
shubham7109 Jun 25, 2025
1466f51
added minor UI cleanups
shubham7109 Jun 25, 2025
6733784
wired in OnDemand cancellation, and update list
shubham7109 Jun 25, 2025
5f4e952
Merge branch 'shubham/on-demand-functionality' into shubham/full-oma-…
shubham7109 Jun 25, 2025
149742b
code comments
shubham7109 Jun 25, 2025
eba14b2
Merge branch 'shubham/on-demand-functionality' into shubham/full-oma-…
shubham7109 Jun 25, 2025
33b72de
add preplanned onDownloadDeleted support
shubham7109 Jun 25, 2025
e7e269f
add preplanned onDownloadDeleted support
shubham7109 Jun 25, 2025
4d6d42e
bottom sheet cleanup
shubham7109 Jun 25, 2025
723f494
Merge branch 'shubham/on-demand-functionality' into shubham/full-oma-…
shubham7109 Jun 25, 2025
72ef54f
Add refreshOfflineMapInfos to app
shubham7109 Jun 26, 2025
42fe994
prototyping restoration
shubham7109 Jun 27, 2025
496a590
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jun 27, 2025
1ff1c27
prototyping DisposableEffect
shubham7109 Jun 27, 2025
9e3123b
PR feedback and updated localizations
shubham7109 Jun 27, 2025
6b545aa
Merge branch 'shubham/on-demand-functionality' into shubham/in-progre…
shubham7109 Jun 27, 2025
594f1a6
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jun 27, 2025
53e1fb7
moved JobResultToDestination step to Workers
shubham7109 Jun 30, 2025
995bfad
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jun 30, 2025
42184ae
added metadata functionality
shubham7109 Jun 30, 2025
62c6860
doc cleanup
shubham7109 Jun 30, 2025
cf496de
more doc cleanup
shubham7109 Jun 30, 2025
bd64273
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jun 30, 2025
45e7f00
testing minor fixes
shubham7109 Jun 30, 2025
582918e
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jun 30, 2025
21ff99d
Add functionality to OnDemand (#904)
shubham7109 Jun 30, 2025
1ed6d26
Merge branch 'feature-branches/offline-map-areas' into shubham/in-pro…
shubham7109 Jun 30, 2025
14485fd
resolve update from feature branch
shubham7109 Jul 1, 2025
d897669
cleanup imports
shubham7109 Jul 1, 2025
b9d130d
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jul 1, 2025
cf7bb94
update preplanned restored state
shubham7109 Jul 2, 2025
bc45420
PR feedback
shubham7109 Jul 2, 2025
01f07c0
Merge branch 'shubham/in-progress-download-restoration' into shubham/…
shubham7109 Jul 2, 2025
3fde16a
Support in-progress download restoration (#907)
shubham7109 Jul 2, 2025
a5b0826
updated icon, cleanup states, remove todos
shubham7109 Jul 2, 2025
0aeb6c9
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 2, 2025
f304d13
Demo app enhancements
shubham7109 Jul 2, 2025
855acaf
WIP
puneet-pdx Jul 3, 2025
7f063d1
Dismiss preplanned sheet and update the map areas list only in offlin…
shubham7109 Jul 3, 2025
6a89fd7
WIP
puneet-pdx Jul 3, 2025
3faf5b7
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 3, 2025
d9fe6f7
remove unused import
puneet-pdx Jul 3, 2025
4372012
rename Network
puneet-pdx Jul 3, 2025
6f21a6f
directory and downloads cleanup
shubham7109 Jul 3, 2025
24b1bbb
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 3, 2025
9b1ee10
remove unnecessary check
puneet-pdx Jul 3, 2025
45fcd59
Added tonal button
shubham7109 Jul 3, 2025
143712c
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 3, 2025
0737b5c
Add refresh button to experience app
shubham7109 Jul 3, 2025
8923393
optimize imports
shubham7109 Jul 3, 2025
f462d98
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 3, 2025
34ea5db
Merge branch 'puneet/6029_ConnectivityManager' into shubham/full-oma-…
shubham7109 Jul 3, 2025
8f48590
Update preplanned to convert description htmlToPlainText
shubham7109 Jul 3, 2025
5136b2b
Merge branch 'shubham/cleanup-and-testing-fixes' into shubham/full-om…
shubham7109 Jul 3, 2025
e7db803
update check to determine if the device is offline
puneet-pdx Jul 7, 2025
495724a
Add bug fix
shubham7109 Jul 7, 2025
485e166
Merge branch 'shubham/offline-map-info-bug-fix' into shubham/full-oma…
shubham7109 Jul 7, 2025
8f8cab1
update logic
puneet-pdx Jul 7, 2025
4586d3b
Revert "Merge branch 'puneet/6029_ConnectivityManager' into shubham/f…
shubham7109 Jul 7, 2025
f7f9771
Merge branch 'puneet/6029_DeviceOffline' into shubham/full-oma-experi…
shubham7109 Jul 7, 2025
d6f2411
Offline Map Areas: Cleanup changes. (#913)
shubham7109 Jul 8, 2025
41ed570
Add bug fix (#924)
shubham7109 Jul 8, 2025
3931081
update check to determine if the device is offline (#925)
puneet-pdx Jul 8, 2025
4ff3b4c
Merge branch 'feature-branches/offline-map-areas' into shubham/full-o…
shubham7109 Jul 9, 2025
17f2394
demo app ui changes
shubham7109 Jul 9, 2025
62cf328
Merge branch 'v.next' into shubham/full-oma-experience
shubham7109 Jul 30, 2025
ad6314e
update for 200.8 auth changes
shubham7109 Jul 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions microapps/OfflineMapAreasApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

This micro-app demonstrates the use of the `OfflineMapAreas` toolkit component to take a web map offline by downloading map areas.

| Online map | Opened map | Offline mode |
|:---: |--- |:---: |
| <img src="microapp_screenshot.png"> | <img src="open_map_screenshot.png"> | <img src="offline_map_screenshot.png"> |

## Usage

The application displays the ahead-of-time (preplanned) maps available to download using the stormwater network within Naperville [web-map](https://arcgisruntime.maps.arcgis.com/home/item.html?id=acc027394bc84c2fb04d1ed317aac674). This app displays, downloads, and monitors the status of map areas, allowing users to view details or remove downloaded files. For preplanned maps, it shows available areas when online and downloaded ones when offline; for on-demand, users can define and download custom map areas.
ToDo…

For more information on the `OfflineMapAreas` component and how it works, see its [Readme](../../toolkit/offline).
For more information on the `OfflineMapAreas` component and how it works, see its [Readme](../../toolkit/offline).
21 changes: 20 additions & 1 deletion microapps/OfflineMapAreasApp/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ plugins {
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
id("com.google.dagger.hilt.android")
id("com.google.devtools.ksp")
}

secrets {
Expand Down Expand Up @@ -77,16 +79,33 @@ android {
}

dependencies {
implementation(project(":authentication"))
implementation(project(":geoview-compose"))
implementation(arcgis.mapsSdk)
implementation(project(":offline"))
implementation(project(":microapps-lib"))
// sdk
implementation(arcgis.mapsSdk)
// hilt
implementation(libs.hilt.android.core)
implementation(libs.androidx.hilt.navigation.compose)
ksp(libs.hilt.compiler)
// room
implementation(libs.room.runtime)
annotationProcessor(libs.room.compiler)
implementation(libs.room.ext)
ksp(libs.room.compiler)
// jetpack window manager
implementation(libs.androidx.window)
implementation(libs.androidx.window.core)
// compose
implementation(platform(libs.androidx.compose.bom))
implementation(libs.bundles.composeCore)
implementation(libs.bundles.core)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.navigation)
implementation(libs.androidx.lifecycle.viewmodel.compose)
testImplementation(libs.bundles.unitTest)
testImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.bundles.composeTest)
debugImplementation(libs.bundles.debug)
Expand Down
17 changes: 17 additions & 0 deletions microapps/OfflineMapAreasApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application
android:name=".OfflineMapAreasApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -44,6 +45,22 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.arcgismaps.toolkit.authentication.AuthenticationActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:exported="true"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="auth"
android:scheme="featureformsapp" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2025 Esri
* Copyright 2024 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,41 +26,113 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import com.arcgismaps.ApiKey
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.rememberNavController
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.toolkit.offlinemapareasapp.screens.MainScreen
import com.esri.microappslib.theme.MicroAppTheme
import com.arcgismaps.httpcore.authentication.ArcGISCredentialStore
import com.arcgismaps.httpcore.authentication.NetworkCredentialStore
import com.arcgismaps.portal.Portal
import com.arcgismaps.toolkit.offlinemapareasapp.data.PortalSettings
import com.arcgismaps.toolkit.offlinemapareasapp.navigation.AppNavigation
import com.arcgismaps.toolkit.offlinemapareasapp.navigation.NavigationRoute
import com.arcgismaps.toolkit.offlinemapareasapp.navigation.Navigator
import com.arcgismaps.toolkit.offlinemapareasapp.theme.OfflineMapAreasAppTheme
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

// Interface to get the PortalSettings instance from Hilt
@EntryPoint
@InstallIn(SingletonComponent::class)
interface PortalSettingsFactory {
fun getPortalSettings(): PortalSettings
}

@Inject
lateinit var navigator: Navigator

private val appState: MutableStateFlow<AppState> = MutableStateFlow(AppState.Loading)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.API_KEY)
ArcGISEnvironment.applicationContext = this
enableEdgeToEdge()
setContent {
MicroAppTheme {
OfflineMapAreasApp()
RequestNotificationPermission(
onResult = { isGranted ->
if (!isGranted) {
Log.e("OfflineMapAreas", "Notification permission request was denied.")
}
})
OfflineMapAreasAppTheme {
OfflineMapAreasApp(
appState.collectAsState().value,
navigator
)
}
}
lifecycleScope.launch {
// fetch the singleton PortalSettings
val factory = EntryPointAccessors.fromApplication(
this@MainActivity,
PortalSettingsFactory::class.java
)
loadCredentials(factory.getPortalSettings())
}
}
}

@Composable
fun OfflineMapAreasApp() {
MainScreen()
private suspend fun loadCredentials(portalSettings: PortalSettings) =
withContext(Dispatchers.Default) {
// create and set a ArcGISCredentialStore that persists
val arcGISCredentialStore = ArcGISCredentialStore.createWithPersistence().getOrThrow()
ArcGISEnvironment.authenticationManager.arcGISCredentialStore = arcGISCredentialStore
// create and set a NetworkCredentialStore that persists
val networkCredentialStore = NetworkCredentialStore.createWithPersistence().getOrThrow()
ArcGISEnvironment.authenticationManager.networkCredentialStore = networkCredentialStore
// get the portal settings url
val url = portalSettings.getPortalUrl()
// check if any credentials are present for this portal
val credential =
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.getCredential(url)
appState.value = if (credential == null) {
// if the portal connection type set it Anonymous, then the user has skipped sign in
if (portalSettings.getPortalConnection() == Portal.Connection.Anonymous) {
AppState.SkipSignIn
} else {
AppState.NotLoggedIn
}
} else {
AppState.LoggedIn
}
}
}

@Composable
Expand Down Expand Up @@ -102,3 +174,75 @@ private fun RequestNotificationPermission(
}
}
}

@Composable
fun OfflineMapAreasApp(
appState: AppState,
navigator: Navigator
) {
if (appState is AppState.Loading) {
AnimatedLoading({ true }, modifier = Modifier.fillMaxSize())
} else {
// create a NavController
val navController = rememberNavController()
// if the user has logged in or skipped sign in, go to the Home screen, else present
// login screen
val startDestination =
if (appState is AppState.LoggedIn || appState is AppState.SkipSignIn) {
NavigationRoute.Home.route
} else {
NavigationRoute.Login.route
}
AppNavigation(
navController = navController,
navigator = navigator,
startDestination = startDestination
)
}
RequestNotificationPermission(
onResult = { isGranted ->
if (!isGranted) {
Log.e("OfflineMapAreas", "Notification permission request was denied.")
}
})
}

@Composable
fun AnimatedLoading(
visibilityProvider: () -> Boolean,
modifier: Modifier = Modifier,
backgroundColor: Color = MaterialTheme.colorScheme.surface,
statusText: String = "",
) {
val visible = visibilityProvider()
if (visible) {
Surface(
modifier = modifier,
color = backgroundColor
) {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
CircularProgressIndicator(
modifier = Modifier.size(30.dp),
strokeWidth = 5.dp
)
if (statusText.isNotEmpty()) {
Spacer(modifier = Modifier.size(10.dp))
Text(text = statusText)
}
}
}
}
}

/**
* Represents the current app state based on the login state of the user.
*/
sealed class AppState {
data object Loading : AppState()
data object LoggedIn : AppState()
data object NotLoggedIn : AppState()
data object SkipSignIn : AppState()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2023 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.arcgismaps.toolkit.offlinemapareasapp

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class OfflineMapAreasApplication : Application()
Loading