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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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)
Expand Down Expand Up @@ -81,6 +86,14 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() {
}
}
}

lifecycleScope.launch {
viewModel.showPopupEvent.collect { show ->
if (show) {
popups.ErrorPopup().show(R.string.connect_to_download_message)
}
}
}
}

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.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
Expand Down Expand Up @@ -56,6 +57,7 @@ internal constructor(
settingsManager: SettingsManager,
permissionsManager: PermissionsManager,
locationOfInterestRepository: LocationOfInterestRepository,
private val networkManager: NetworkManager,
) :
BaseMapViewModel(
locationManager,
Expand All @@ -79,7 +81,16 @@ internal constructor(
private val _navigate = MutableSharedFlow<UiState>(replay = 0)
val navigate = _navigate.asSharedFlow()

private val _showPopupEvent = MutableSharedFlow<Boolean>()
val showPopupEvent = _showPopupEvent.asSharedFlow()
Comment on lines +84 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to networkUnavailableEvent? Also, we aren't using the value of the emitted value. So the type can be changed to Nil.


fun onDownloadClick() {
val isConnected = networkManager.isNetworkConnected()
if (!isConnected) {
Comment on lines +88 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline this

viewModelScope.launch { _showPopupEvent.emit(true) }
return
}

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