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

Error Handling for urlConnection #2902

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

anandwana001
Copy link
Collaborator

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 21 lines in your changes missing coverage. Please review.

Project coverage is 62.42%. Comparing base (a8cbc36) to head (6b8fa5e).

Files with missing lines Patch % Lines
...lineareas/selector/OfflineAreaSelectorViewModel.kt 6.25% 15 Missing ⚠️
...flineareas/selector/OfflineAreaSelectorFragment.kt 50.00% 1 Missing and 4 partials ⚠️
...android/ground/repository/OfflineAreaRepository.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2902      +/-   ##
============================================
- Coverage     62.52%   62.42%   -0.11%     
- Complexity     1203     1204       +1     
============================================
  Files           267      267              
  Lines          6357     6374      +17     
  Branches        881      885       +4     
============================================
+ Hits           3975     3979       +4     
- Misses         1831     1841      +10     
- Partials        551      554       +3     
Files with missing lines Coverage Δ
...le/android/ground/ui/map/gms/mog/UrlInputStream.kt 0.00% <ø> (ø)
...android/ground/repository/OfflineAreaRepository.kt 49.18% <0.00%> (ø)
...flineareas/selector/OfflineAreaSelectorFragment.kt 44.64% <50.00%> (-1.20%) ⬇️
...lineareas/selector/OfflineAreaSelectorViewModel.kt 24.41% <6.25%> (-1.56%) ⬇️

@gino-m
Copy link
Collaborator

gino-m commented Dec 12, 2024

We should handle the error upstream where it can actually be addressed:

viewModelScope.launch(ioDispatcher) {
offlineAreaRepository.downloadTiles(viewport!!).collect { (bytesDownloaded, totalBytes) ->
val progressValue =
if (totalBytes > 0) {
(bytesDownloaded.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f)
} else {
0f
}
downloadProgress.postValue(progressValue)
}
isDownloadProgressVisible.postValue(false)
_navigate.emit(UiState.OfflineAreaBackToHomeScreen)
}
}

You would add .catch{} before collect to handle the failure (show a toast and close the dialog).

Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

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

Thanks! A few requests, LG

ground/src/main/res/values-es/strings.xml Outdated Show resolved Hide resolved
ground/src/main/res/values-fr/strings.xml Outdated Show resolved Hide resolved
ground/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
@@ -62,8 +66,17 @@ class OfflineAreaSelectorFragment : AbstractMapContainerFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.isDownloadProgressVisible.observe(viewLifecycleOwner) {
showDownloadProgressDialog(it)
viewLifecycleOwner.lifecycleScope.launch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add tests for this logic?

}
downloadProgress.postValue(progressValue)
}
offlineAreaRepository
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add tests for this logic as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App Crash - While Downloading Area
4 participants