diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt index 7c2664ca06..07418c0004 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt @@ -26,15 +26,18 @@ import androidx.compose.runtime.remember import androidx.compose.ui.platform.ComposeView import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController +import com.google.android.ground.R import com.google.android.ground.databinding.OfflineAreaSelectorFragBinding import com.google.android.ground.ui.common.AbstractMapContainerFragment import com.google.android.ground.ui.common.BaseMapViewModel +import com.google.android.ground.ui.common.EphemeralPopups import com.google.android.ground.ui.common.MapConfig import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.MapFragment import com.google.android.ground.ui.map.MapType import com.google.android.ground.ui.theme.AppTheme import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject import kotlinx.coroutines.launch /** Map UI used to select areas for download and viewing offline. */ @@ -44,6 +47,8 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() { private lateinit var viewModel: OfflineAreaSelectorViewModel private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel + @Inject lateinit var popups: EphemeralPopups + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) @@ -81,6 +86,12 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() { } } } + + lifecycleScope.launch { + viewModel.networkUnavailableEvent.collect { + popups.ErrorPopup().show(R.string.connect_to_download_message) + } + } } override fun getMapConfig(): MapConfig = diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt index 22e9d39454..c4324f8eba 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt @@ -25,6 +25,7 @@ import com.google.android.ground.repository.MapStateRepository import com.google.android.ground.repository.OfflineAreaRepository import com.google.android.ground.repository.SurveyRepository import com.google.android.ground.system.LocationManager +import com.google.android.ground.system.NetworkManager import com.google.android.ground.system.PermissionsManager import com.google.android.ground.system.SettingsManager import com.google.android.ground.ui.common.BaseMapViewModel @@ -56,6 +57,7 @@ internal constructor( settingsManager: SettingsManager, permissionsManager: PermissionsManager, locationOfInterestRepository: LocationOfInterestRepository, + private val networkManager: NetworkManager, ) : BaseMapViewModel( locationManager, @@ -79,7 +81,15 @@ internal constructor( private val _navigate = MutableSharedFlow(replay = 0) val navigate = _navigate.asSharedFlow() + private val _networkUnavailableEvent = MutableSharedFlow() + val networkUnavailableEvent = _networkUnavailableEvent.asSharedFlow() + fun onDownloadClick() { + if (!networkManager.isNetworkConnected()) { + viewModelScope.launch { _networkUnavailableEvent.emit(Unit) } + return + } + if (viewport == null) { // Download was likely clicked before map was ready. return diff --git a/ground/src/main/res/values/strings.xml b/ground/src/main/res/values/strings.xml index 81343f21d4..77d6c74df4 100644 --- a/ground/src/main/res/values/strings.xml +++ b/ground/src/main/res/values/strings.xml @@ -56,6 +56,7 @@ Select area No map imagery downloaded for offline use + You are offline. Connect to download offline map imager Signing in Build %s