Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Toast when offline in Download #2990

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
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. */
Expand All @@ -44,6 +47,8 @@
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)
Expand Down Expand Up @@ -81,6 +86,12 @@
}
}
}

lifecycleScope.launch {
viewModel.networkUnavailableEvent.collect {
popups.ErrorPopup().show(R.string.connect_to_download_message)
}

Check warning on line 93 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt#L92-L93

Added lines #L92 - L93 were not covered by tests
}
}

override fun getMapConfig(): MapConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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
Expand Down Expand Up @@ -56,6 +57,7 @@
settingsManager: SettingsManager,
permissionsManager: PermissionsManager,
locationOfInterestRepository: LocationOfInterestRepository,
private val networkManager: NetworkManager,
) :
BaseMapViewModel(
locationManager,
Expand All @@ -79,7 +81,15 @@
private val _navigate = MutableSharedFlow<UiState>(replay = 0)
val navigate = _navigate.asSharedFlow()

private val _networkUnavailableEvent = MutableSharedFlow<Unit>()
val networkUnavailableEvent = _networkUnavailableEvent.asSharedFlow()

fun onDownloadClick() {
if (!networkManager.isNetworkConnected()) {
viewModelScope.launch { _networkUnavailableEvent.emit(Unit) }
return

Check warning on line 90 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L89-L90

Added lines #L89 - L90 were not covered by tests
}

if (viewport == null) {
// Download was likely clicked before map was ready.
return
Expand Down
1 change: 1 addition & 0 deletions ground/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<!-- Label of button used enter the offline area selector. -->
<string name="offline_area_selector_select">Select area</string>
<string name="no_basemaps_downloaded">No map imagery downloaded for offline use</string>
<string name="connect_to_download_message">You are offline. Connect to download offline map imager</string>
<string name="signing_in">Signing in</string>
<!-- Precedes the build number shown in the side menu of debug builds. -->
<string name="build">Build %s</string>
Expand Down
Loading