Super basic error handling for the feyenoord api.
This commit is contained in:
@@ -11,6 +11,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
@@ -31,18 +32,13 @@ fun FeyenoordScreen(
|
|||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
if (feyenoordUiState.matches.isEmpty()) {
|
if (feyenoordUiState.loading) {
|
||||||
CircularProgressIndicator()
|
CircularProgressIndicator()
|
||||||
|
} else if (feyenoordUiState.error != null) {
|
||||||
|
Text(stringResource(feyenoordUiState.error!!))
|
||||||
} else {
|
} else {
|
||||||
MatchList(matches = feyenoordUiState.matches, Modifier)
|
MatchList(matches = feyenoordUiState.matches, Modifier)
|
||||||
}
|
}
|
||||||
// if (feyenoordUiState.loading) {
|
|
||||||
// CircularProgressIndicator()
|
|
||||||
// } else if (feyenoordUiState.error) {
|
|
||||||
// Text(feyenoordUiState.errorMessage)
|
|
||||||
// } else {
|
|
||||||
// MatchList(matches = feyenoordUiState.matches, Modifier)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import android.content.res.Resources
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordRetrofitHelper
|
import com.mitchelbv.thuis_c.R
|
||||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordService
|
|
||||||
import com.mitchelbv.thuis_c.repository.FeyenoordRepository
|
import com.mitchelbv.thuis_c.repository.FeyenoordRepository
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Locale
|
|
||||||
import java.util.TimeZone
|
|
||||||
|
|
||||||
data class FeyenoordUiState(
|
data class FeyenoordUiState(
|
||||||
val matches: List<Match> = listOf(),
|
val matches: List<Match> = listOf(),
|
||||||
val loading: Boolean = true,
|
val loading: Boolean = true,
|
||||||
|
val error: Int? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
class FeyenoordViewModel : ViewModel() {
|
class FeyenoordViewModel : ViewModel() {
|
||||||
@@ -31,7 +29,11 @@ class FeyenoordViewModel : ViewModel() {
|
|||||||
|
|
||||||
private fun fillMatches() {
|
private fun fillMatches() {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
_uiState.value = FeyenoordUiState(matches = feyenoordRepository.getMatches(), loading = false)
|
try {
|
||||||
|
_uiState.value = FeyenoordUiState(matches = feyenoordRepository.getMatches(), loading = false)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_uiState.value = FeyenoordUiState(loading = false, error = R.string.feyenoord_network_error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,4 +10,5 @@
|
|||||||
|
|
||||||
<string name="freezer_list_empty">Er zijn geen vriezers</string>
|
<string name="freezer_list_empty">Er zijn geen vriezers</string>
|
||||||
<string name="edit_freezer">Vriezer aanpassen</string>
|
<string name="edit_freezer">Vriezer aanpassen</string>
|
||||||
|
<string name="feyenoord_network_error">Er is geen netwerk beschikbaar</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user