Handle generic errors

This commit is contained in:
2021-01-15 11:00:52 +01:00
parent 45034b294c
commit 5550de5836
10 changed files with 34 additions and 18 deletions

View File

@@ -75,14 +75,16 @@ class CircularLetterFragment :
circularLetterViewModel.showMessage.observe(
viewLifecycleOwner,
{
if (it) activity?.findViewById<ConstraintLayout>(R.id.container)?.let { view ->
if (it < 0) activity?.findViewById<ConstraintLayout>(R.id.container)?.let { view ->
val message = if (it == -1) getString(R.string.snackbar_generic_error) else getString(R.string.snackbar_connection_not_available)
Snackbar.make(
view,
getString(R.string.snackbar_connection_not_available),
message,
Snackbar.LENGTH_LONG
).show()
circularLetterViewModel.showMessage.postValue(false)
circularLetterViewModel.showMessage.postValue(0)
}
}
)
@@ -91,8 +93,6 @@ class CircularLetterFragment :
{
if (it) {
binding.circularsRefresh.isRefreshing = false
circularLetterViewModel.showMessage.postValue(false)
}
}
)

View File

@@ -49,7 +49,7 @@ class CircularLetterViewModel internal constructor(
}
}
val showMessage = MutableLiveData<Boolean>().apply { value = false }
val showMessage = MutableLiveData<Int>().apply { value = 0 }
val circularsUpdated = MutableLiveData<Boolean>().apply { value = false }
private var isNotUpdating = true
@@ -65,9 +65,8 @@ class CircularLetterViewModel internal constructor(
viewModelScope.launch {
isNotUpdating = false
if (circularRepository.updateCirculars(false).second == -1) {
showMessage.postValue(true)
}
val result = circularRepository.updateCirculars(false).second
showMessage.postValue(result)
isNotUpdating = true
circularsUpdated.postValue(true)

View File

@@ -83,7 +83,9 @@ class PollWork(appContext: Context, workerParams: WorkerParameters) :
val circularRepository = AndroidCircularRepository.getInstance(applicationContext)
val result = circularRepository.updateCirculars()
if (result.second == -1)
// Retry only if it's a network error, otherwise there is probably an issue with the parser code which can only be solved with an update
if (result.second == -2)
return@coroutineScope Result.retry()
val newCirculars = result.first

View File

@@ -77,6 +77,7 @@
<string name="snackbar_circular_downloaded">La circolare sarà salvata nella cartella Download</string>
<string name="snackbar_connection_not_available">Rete non disponibile. I risultati potrebbero non essere aggiornati</string>
<string name="snackbar_generic_error">Si è verificato un errore</string>
<string name="image_view_attachment">Visualizza allegato</string>
<string name="image_share_attachment">Condividi allegato</string>

View File

@@ -78,6 +78,7 @@
<string name="snackbar_circular_downloaded">The circular letter will be saved into the download folder</string>
<string name="snackbar_connection_not_available">Network not available. Results may be outdated</string>
<string name="snackbar_generic_error">An error has occurred</string>
<string name="image_view_attachment">View attachment</string>
<string name="image_share_attachment">Share attachment</string>