-
Notifications
You must be signed in to change notification settings - Fork 120
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
494f766
e00b968
d41ab05
ff4c85f
96871f2
60d4787
b70eb4a
a16a172
e8555fe
6b8fa5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.launch | ||
|
||
private const val MIN_DOWNLOAD_ZOOM_LEVEL = 9 | ||
|
@@ -77,6 +78,7 @@ | |
val downloadProgress = MutableLiveData(0f) | ||
val bottomText = MutableLiveData<String?>(null) | ||
val downloadButtonEnabled = MutableLiveData(false) | ||
val isFailure = MutableLiveData(false) | ||
|
||
private val _navigate = MutableSharedFlow<UiState>(replay = 0) | ||
val navigate = _navigate.asSharedFlow() | ||
|
@@ -98,15 +100,21 @@ | |
isDownloadProgressVisible.value = true | ||
downloadProgress.value = 0f | ||
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) | ||
} | ||
offlineAreaRepository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add tests for this logic as well? |
||
.downloadTiles(viewport!!) | ||
Check warning on line 104 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt Codecov / codecov/patchground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L103-L104
|
||
.catch { | ||
isFailure.postValue(true) | ||
isDownloadProgressVisible.postValue(false) | ||
} | ||
.collect { (bytesDownloaded, totalBytes) -> | ||
val progressValue = | ||
Check warning on line 110 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt Codecov / codecov/patchground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L106-L110
|
||
anandwana001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (totalBytes > 0) { | ||
(bytesDownloaded.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f) | ||
Check warning on line 112 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt Codecov / codecov/patchground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L112
|
||
} else { | ||
0f | ||
Check warning on line 114 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt Codecov / codecov/patchground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L114
|
||
} | ||
downloadProgress.postValue(progressValue) | ||
} | ||
Check warning on line 117 in ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt Codecov / codecov/patchground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt#L116-L117
|
||
isDownloadProgressVisible.postValue(false) | ||
_navigate.emit(UiState.OfflineAreaBackToHomeScreen) | ||
} | ||
|
There was a problem hiding this comment.
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?