This commit is contained in:
KaasKop-
2024-01-29 20:57:00 +01:00
parent a1d17919e5
commit 4ac5fe7392
3 changed files with 20 additions and 21 deletions

View File

@@ -15,7 +15,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.mitchelbv.thuis_c.R import com.mitchelbv.thuis_c.R
@@ -41,16 +40,16 @@ fun MatchList(matches: List<Match>, modifier: Modifier) {
} }
@Composable @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) { Column(modifier = modifier.size(128.dp).fillMaxWidth(), Arrangement.Center, Alignment.CenterHorizontally) {
AsyncImage( AsyncImage(
model = team_logo_url, model = teamLogoUrl,
contentDescription = team_name, contentDescription = teamName,
placeholder = painterResource(id = R.drawable.placeholder), placeholder = painterResource(id = R.drawable.placeholder),
contentScale = ContentScale.Fit, contentScale = ContentScale.Fit,
modifier = modifier.size(64.dp) 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) .height(128.dp)
) { ) {
TeamNameWithLogo( TeamNameWithLogo(
team_name = match.home_team, teamName = match.home_team,
team_logo_url = match.home_image, teamLogoUrl = match.home_image,
modifier = modifier modifier = modifier
) )
Column( Column(
@@ -82,8 +81,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
} }
} }
TeamNameWithLogo( TeamNameWithLogo(
team_name = match.away_team, teamName = match.away_team,
team_logo_url = match.away_image, teamLogoUrl = match.away_image ?: "",
modifier = modifier 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", away_image = "https://tymes4-cdn.azureedge.net/feyenoord/291-S.S._Lazio_badge.svg-min-original.png",
home_team = "Feyenoord Vrouwen 1", home_team = "Feyenoord Vrouwen 1",
away_team = "FC Twente Vrouwen 1", away_team = "FC Twente Vrouwen 1",
date = "do 03 November 2023", date = "03 Nov 2024",
begin_time = "18:03", begin_time = "18:03",
end_time = "20:03" end_time = "20:03"
) )

View File

@@ -1,5 +1,6 @@
package com.mitchelbv.thuis_c.views.feyenoord package com.mitchelbv.thuis_c.views.feyenoord
import androidx.compose.ui.text.toLowerCase
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.network.feyenoord.FeyenoordRetrofitHelper
@@ -8,12 +9,11 @@ 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.launch import kotlinx.coroutines.launch
import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneId import java.time.ZoneId
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
import java.util.Locale
data class FeyenoordUiState( data class FeyenoordUiState(
val matches: List<Match> = listOf() val matches: List<Match> = listOf()
@@ -32,26 +32,26 @@ class FeyenoordViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val getToken = FeyenoordRetrofitHelper.feyenoord.getDefaultToken().Token val getToken = FeyenoordRetrofitHelper.feyenoord.getDefaultToken().Token
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents("Bearer $getToken") val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents("Bearer $getToken")
val dayOfWeek = arrayOf("Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo")
for (tabItem in apiResponse.TabItems) { for (tabItem in apiResponse.TabItems) {
val test = arrayOf(tabItem).filter { it.CategoryId == 2 } val test = arrayOf(tabItem).filter { it.CategoryId == 2 }
test.forEach { test.forEach {
for (item in it.Items) { for (item in it.Items) {
val utcDateBegin = LocalDateTime.parse(item.EventStartDateTime) 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 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( tempMatches.add(
Match( Match(
home_team = item.NameHomeTeam!!, home_team = item.NameHomeTeam!!,
away_team = item.NameAwayTeam!!, away_team = item.NameAwayTeam!!,
date = beginDate.format( date = "${dayOfWeek[beginDate.dayOfWeek.value - 1]} ${beginDate.dayOfMonth} ${beginDate.month.toString()
DateTimeFormatter.ofLocalizedDate( .lowercase(Locale.getDefault())}",
FormatStyle.MEDIUM
)
),
begin_time = "${beginDate.toLocalTime()}", begin_time = "${beginDate.toLocalTime()}",
end_time = "${endDate.toLocalTime()}", end_time = "${endDate.toLocalTime()}",
away_image = item.AwayImageUrl!!, away_image = item.AwayImageUrl,
home_image = item.HomeImageUrl!! home_image = item.HomeImageUrl!!
) )
) )

View File

@@ -2,7 +2,7 @@ package com.mitchelbv.thuis_c.views.feyenoord
data class Match( data class Match(
val home_image: String, val home_image: String,
val away_image: String, val away_image: String?,
val home_team: String, val home_team: String,
val away_team: String, val away_team: String,
val date: String, val date: String,