From 4ac5fe7392790cac4003f9ccf904884d2453ae11 Mon Sep 17 00:00:00 2001 From: KaasKop- Date: Mon, 29 Jan 2024 20:57:00 +0100 Subject: [PATCH] Update --- .../thuis_c/views/feyenoord/FeyenoordView.kt | 19 +++++++++--------- .../views/feyenoord/FeyenoordViewModel.kt | 20 +++++++++---------- .../thuis_c/views/feyenoord/Match.kt | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordView.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordView.kt index 0443111..8b7521c 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordView.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordView.kt @@ -15,7 +15,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel -import androidx.navigation.NavHostController import coil.compose.AsyncImage import com.mitchelbv.thuis_c.R @@ -41,16 +40,16 @@ fun MatchList(matches: List, modifier: Modifier) { } @Composable -fun TeamNameWithLogo(team_name: String, team_logo_url: String, modifier: Modifier) { +fun TeamNameWithLogo(teamName: String, teamLogoUrl: String, modifier: Modifier) { Column(modifier = modifier.size(128.dp).fillMaxWidth(), Arrangement.Center, Alignment.CenterHorizontally) { AsyncImage( - model = team_logo_url, - contentDescription = team_name, + model = teamLogoUrl, + contentDescription = teamName, placeholder = painterResource(id = R.drawable.placeholder), contentScale = ContentScale.Fit, modifier = modifier.size(64.dp) ) - Text(text = team_name, modifier = modifier.fillMaxWidth().wrapContentWidth(Alignment.CenterHorizontally)) + Text(text = teamName, modifier = modifier.fillMaxWidth().wrapContentWidth(Alignment.CenterHorizontally)) } } @@ -66,8 +65,8 @@ fun MatchCard(match: Match, modifier: Modifier) { .height(128.dp) ) { TeamNameWithLogo( - team_name = match.home_team, - team_logo_url = match.home_image, + teamName = match.home_team, + teamLogoUrl = match.home_image, modifier = modifier ) Column( @@ -82,8 +81,8 @@ fun MatchCard(match: Match, modifier: Modifier) { } } TeamNameWithLogo( - team_name = match.away_team, - team_logo_url = match.away_image, + teamName = match.away_team, + teamLogoUrl = match.away_image ?: "", modifier = modifier ) @@ -98,7 +97,7 @@ fun PreviewMatchCard() { away_image = "https://tymes4-cdn.azureedge.net/feyenoord/291-S.S._Lazio_badge.svg-min-original.png", home_team = "Feyenoord Vrouwen 1", away_team = "FC Twente Vrouwen 1", - date = "do 03 November 2023", + date = "03 Nov 2024", begin_time = "18:03", end_time = "20:03" ) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt index b811ecb..4cb44e0 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt @@ -1,5 +1,6 @@ package com.mitchelbv.thuis_c.views.feyenoord +import androidx.compose.ui.text.toLowerCase import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordRetrofitHelper @@ -8,12 +9,11 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId -import java.time.ZoneOffset import java.time.format.DateTimeFormatter import java.time.format.FormatStyle +import java.util.Locale data class FeyenoordUiState( val matches: List = listOf() @@ -32,26 +32,26 @@ class FeyenoordViewModel : ViewModel() { viewModelScope.launch(Dispatchers.IO) { val getToken = FeyenoordRetrofitHelper.feyenoord.getDefaultToken().Token val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents("Bearer $getToken") + val dayOfWeek = arrayOf("Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo") for (tabItem in apiResponse.TabItems) { val test = arrayOf(tabItem).filter { it.CategoryId == 2 } test.forEach { for (item in it.Items) { val utcDateBegin = LocalDateTime.parse(item.EventStartDateTime) - val beginDate = utcDateBegin.atZone(ZoneId.of("UTC")).withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime() + val beginDate = utcDateBegin.atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime() val utcDateEnd = LocalDateTime.parse(item.EventEndDateTime) - val endDate = utcDateEnd.atZone(ZoneId.of("UTC")).withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime() + val endDate = utcDateEnd.atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime() tempMatches.add( Match( home_team = item.NameHomeTeam!!, away_team = item.NameAwayTeam!!, - date = beginDate.format( - DateTimeFormatter.ofLocalizedDate( - FormatStyle.MEDIUM - ) - ), + date = "${dayOfWeek[beginDate.dayOfWeek.value - 1]} ${beginDate.dayOfMonth} ${beginDate.month.toString() + .lowercase(Locale.getDefault())}", begin_time = "${beginDate.toLocalTime()}", end_time = "${endDate.toLocalTime()}", - away_image = item.AwayImageUrl!!, + away_image = item.AwayImageUrl, home_image = item.HomeImageUrl!! ) ) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/Match.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/Match.kt index 4ee8388..ad1d1b0 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/Match.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/Match.kt @@ -2,7 +2,7 @@ package com.mitchelbv.thuis_c.views.feyenoord data class Match( val home_image: String, - val away_image: String, + val away_image: String?, val home_team: String, val away_team: String, val date: String,