Add loading to matches
Update gradle Use repository?
This commit is contained in:
@@ -5,14 +5,14 @@ plugins {
|
||||
|
||||
android {
|
||||
namespace 'com.mitchelbv.thuis_c'
|
||||
compileSdk 33
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.mitchelbv.thuis_c"
|
||||
minSdk 30
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
targetSdk 34
|
||||
versionCode 3
|
||||
versionName "1.3"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mitchelbv.thuis_c.repository
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordRetrofitHelper
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordService
|
||||
import com.mitchelbv.thuis_c.ui.feyenoord.Match
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
class FeyenoordRepository() {
|
||||
private val feyenoordService: FeyenoordService = FeyenoordRetrofitHelper.feyenoord
|
||||
|
||||
private fun toLocalFormattedDateTime(date: String, outputFormat: String): String {
|
||||
val apiUtcDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault())
|
||||
apiUtcDate.timeZone = TimeZone.getTimeZone("UTC")
|
||||
val parsedDate = apiUtcDate.parse(date)
|
||||
|
||||
val localDateFormat = SimpleDateFormat(outputFormat, Locale.getDefault())
|
||||
localDateFormat.timeZone = TimeZone.getDefault()
|
||||
return localDateFormat.format(parsedDate)
|
||||
}
|
||||
suspend fun getMatches(): List<Match> {
|
||||
val tempMatches = mutableListOf<Match>()
|
||||
val token = feyenoordService.getToken()
|
||||
val feyenoordApiResponse = token.token?.let { feyenoordService.getEvents(it) }
|
||||
feyenoordApiResponse?.TabItems?.filter { it.CategoryId == 2 }?.forEach {
|
||||
for (item in it.Items) {
|
||||
|
||||
tempMatches.add(
|
||||
Match(
|
||||
homeTeam = item.NameHomeTeam!!,
|
||||
awayTeam = item.NameAwayTeam!!,
|
||||
date = item.EventStartDateTime?.let { it1 ->
|
||||
toLocalFormattedDateTime(
|
||||
it1,
|
||||
"dd MMMM"
|
||||
)
|
||||
}.toString(),
|
||||
beginTime = item.EventStartDateTime?.let { it1 ->
|
||||
toLocalFormattedDateTime(
|
||||
it1,
|
||||
"HH:mm"
|
||||
)
|
||||
}.toString(),
|
||||
endTime = item.EventEndDateTime?.let { it1 ->
|
||||
toLocalFormattedDateTime(
|
||||
it1,
|
||||
"HH:mm"
|
||||
)
|
||||
}.toString(),
|
||||
awayImage = item.AwayImageUrl!!,
|
||||
homeImage = item.HomeImageUrl!!
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
return tempMatches
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||
|
||||
import android.widget.Spinner
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@@ -12,6 +11,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -26,21 +26,23 @@ fun FeyenoordScreen(
|
||||
navHostController: NavHostController
|
||||
) {
|
||||
val feyenoordUiState by feyenoordViewModel.uiState.collectAsState()
|
||||
if (feyenoordUiState.loading) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
// .padding(16.dp)
|
||||
modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
MatchList(matches = feyenoordUiState.matches, Modifier)
|
||||
if (feyenoordUiState.matches.isEmpty()) {
|
||||
CircularProgressIndicator()
|
||||
} else {
|
||||
MatchList(matches = feyenoordUiState.matches, Modifier)
|
||||
}
|
||||
// if (feyenoordUiState.loading) {
|
||||
// CircularProgressIndicator()
|
||||
// } else if (feyenoordUiState.error) {
|
||||
// Text(feyenoordUiState.errorMessage)
|
||||
// } else {
|
||||
// MatchList(matches = feyenoordUiState.matches, Modifier)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ fun MatchList(matches: List<Match>, 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)
|
||||
@@ -63,17 +65,18 @@ fun TeamNameWithLogo(team_name: String, team_logo_url: String, modifier: Modifie
|
||||
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,
|
||||
text = teamName,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentWidth(Alignment.CenterHorizontally)
|
||||
// .wrapContentWidth(Alignment.CenterHorizontally)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -90,8 +93,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
||||
.height(128.dp)
|
||||
) {
|
||||
TeamNameWithLogo(
|
||||
team_name = match.homeTeam,
|
||||
team_logo_url = match.homeImage,
|
||||
teamName = match.homeTeam,
|
||||
teamLogoUrl = match.homeImage,
|
||||
modifier = modifier
|
||||
)
|
||||
Column(
|
||||
@@ -106,8 +109,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
||||
}
|
||||
}
|
||||
TeamNameWithLogo(
|
||||
team_name = match.awayTeam,
|
||||
team_logo_url = match.awayImage,
|
||||
teamName = match.awayTeam,
|
||||
teamLogoUrl = match.awayImage,
|
||||
modifier = modifier
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordRetrofitHelper
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordService
|
||||
import com.mitchelbv.thuis_c.repository.FeyenoordRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -14,58 +17,21 @@ import java.util.TimeZone
|
||||
|
||||
data class FeyenoordUiState(
|
||||
val matches: List<Match> = listOf(),
|
||||
val loading: Boolean = true
|
||||
val loading: Boolean = true,
|
||||
)
|
||||
|
||||
class FeyenoordViewModel : ViewModel() {
|
||||
private val _uiState = MutableStateFlow(FeyenoordUiState())
|
||||
val uiState: StateFlow<FeyenoordUiState> = _uiState.asStateFlow()
|
||||
private val feyenoordRepository: FeyenoordRepository = FeyenoordRepository()
|
||||
|
||||
init {
|
||||
fillMatches()
|
||||
}
|
||||
|
||||
private fun toLocalFormattedDateTime(date: String, outputFormat: String): String {
|
||||
val apiUtcDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault())
|
||||
apiUtcDate.timeZone = TimeZone.getTimeZone("UTC")
|
||||
val parsedDate = apiUtcDate.parse(date)
|
||||
|
||||
val localDateFormat = SimpleDateFormat(outputFormat, Locale.getDefault())
|
||||
localDateFormat.timeZone = TimeZone.getDefault()
|
||||
return localDateFormat.format(parsedDate);
|
||||
}
|
||||
|
||||
private fun fillMatches() {
|
||||
val tempMatches = mutableListOf<Match>()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
|
||||
val tokenResponse = FeyenoordRetrofitHelper.feyenoord.getToken()
|
||||
val apiResponse = tokenResponse.token?.let {
|
||||
FeyenoordRetrofitHelper.feyenoord.getEvents(
|
||||
it
|
||||
)
|
||||
}
|
||||
if (apiResponse != null) {
|
||||
for (tabItem in apiResponse.TabItems) {
|
||||
val test = arrayOf(tabItem).filter { it.CategoryId == 2 }
|
||||
test.forEach {
|
||||
for (item in it.Items) {
|
||||
tempMatches.add(
|
||||
Match(
|
||||
homeTeam = item.NameHomeTeam!!,
|
||||
awayTeam = item.NameAwayTeam!!,
|
||||
date = item.EventStartDateTime?.let { it1 -> toLocalFormattedDateTime(it1, "dd MMMM") }.toString(),
|
||||
beginTime = item.EventStartDateTime?.let { it1 -> toLocalFormattedDateTime(it1, "HH:mm")}.toString(),
|
||||
endTime = item.EventEndDateTime?.let { it1 -> toLocalFormattedDateTime(it1, "HH:mm")}.toString(),
|
||||
awayImage = item.AwayImageUrl!!,
|
||||
homeImage = item.HomeImageUrl!!
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_uiState.value = FeyenoordUiState(matches = tempMatches, loading = false)
|
||||
_uiState.value = FeyenoordUiState(matches = feyenoordRepository.getMatches(), loading = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ fun HomeScreen(navController: NavHostController) {
|
||||
// Row(modifier = Modifier.height(100.dp).width(180.dp)) {
|
||||
// HomeCard(cardId = R.drawable.storefront, cardText = R.string.home_card_cards, routeTo = Screen.Cards.route, navController = navController)
|
||||
// HomeCard(cardId = R.drawable.feyenoord, cardText = R.string.home_card_freezer, routeTo = Screen.Freezer.route, navController = navController)
|
||||
HomeButton(buttonText = R.string.home_card_cards, routeTo = Screen.Cards.route, navController = navController)
|
||||
HomeButton(buttonText = R.string.home_card_freezer, routeTo = Screen.Freezer.route, navController = navController)
|
||||
// HomeButton(buttonText = R.string.home_card_cards, routeTo = Screen.Cards.route, navController = navController)
|
||||
// HomeButton(buttonText = R.string.home_card_freezer, routeTo = Screen.Freezer.route, navController = navController)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ buildscript {
|
||||
}
|
||||
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.6.0' apply false
|
||||
id 'com.android.library' version '8.6.0' apply false
|
||||
id 'com.android.application' version '8.7.3' apply false
|
||||
id 'com.android.library' version '8.7.3' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
|
||||
}
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Oct 31 14:59:45 CET 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
Reference in New Issue
Block a user