Add loading to matches
Update gradle Use repository?
This commit is contained in:
@@ -5,14 +5,14 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace 'com.mitchelbv.thuis_c'
|
namespace 'com.mitchelbv.thuis_c'
|
||||||
compileSdk 33
|
compileSdk 34
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.mitchelbv.thuis_c"
|
applicationId "com.mitchelbv.thuis_c"
|
||||||
minSdk 30
|
minSdk 30
|
||||||
targetSdk 33
|
targetSdk 34
|
||||||
versionCode 1
|
versionCode 3
|
||||||
versionName "1.0"
|
versionName "1.3"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
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
|
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||||
|
|
||||||
import android.widget.Spinner
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
@@ -12,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.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
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -26,22 +26,24 @@ fun FeyenoordScreen(
|
|||||||
navHostController: NavHostController
|
navHostController: NavHostController
|
||||||
) {
|
) {
|
||||||
val feyenoordUiState by feyenoordViewModel.uiState.collectAsState()
|
val feyenoordUiState by feyenoordViewModel.uiState.collectAsState()
|
||||||
if (feyenoordUiState.loading) {
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
if (feyenoordUiState.matches.isEmpty()) {
|
||||||
CircularProgressIndicator()
|
CircularProgressIndicator()
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.verticalScroll(rememberScrollState())
|
|
||||||
// .padding(16.dp)
|
|
||||||
) {
|
|
||||||
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)
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -54,7 +56,7 @@ 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(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.size(128.dp)
|
.size(128.dp)
|
||||||
@@ -63,17 +65,18 @@ fun TeamNameWithLogo(team_name: String, team_logo_url: String, modifier: Modifie
|
|||||||
Alignment.CenterHorizontally
|
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(
|
||||||
text = team_name,
|
text = teamName,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentWidth(Alignment.CenterHorizontally)
|
// .wrapContentWidth(Alignment.CenterHorizontally)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +93,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
|||||||
.height(128.dp)
|
.height(128.dp)
|
||||||
) {
|
) {
|
||||||
TeamNameWithLogo(
|
TeamNameWithLogo(
|
||||||
team_name = match.homeTeam,
|
teamName = match.homeTeam,
|
||||||
team_logo_url = match.homeImage,
|
teamLogoUrl = match.homeImage,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
Column(
|
Column(
|
||||||
@@ -106,8 +109,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TeamNameWithLogo(
|
TeamNameWithLogo(
|
||||||
team_name = match.awayTeam,
|
teamName = match.awayTeam,
|
||||||
team_logo_url = match.awayImage,
|
teamLogoUrl = match.awayImage,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
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
|
||||||
|
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordService
|
||||||
|
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
|
||||||
@@ -14,58 +17,21 @@ 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
class FeyenoordViewModel : ViewModel() {
|
class FeyenoordViewModel : ViewModel() {
|
||||||
private val _uiState = MutableStateFlow(FeyenoordUiState())
|
private val _uiState = MutableStateFlow(FeyenoordUiState())
|
||||||
val uiState: StateFlow<FeyenoordUiState> = _uiState.asStateFlow()
|
val uiState: StateFlow<FeyenoordUiState> = _uiState.asStateFlow()
|
||||||
|
private val feyenoordRepository: FeyenoordRepository = FeyenoordRepository()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
fillMatches()
|
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() {
|
private fun fillMatches() {
|
||||||
val tempMatches = mutableListOf<Match>()
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
_uiState.value = FeyenoordUiState(matches = feyenoordRepository.getMatches(), loading = false)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,8 +24,8 @@ fun HomeScreen(navController: NavHostController) {
|
|||||||
// Row(modifier = Modifier.height(100.dp).width(180.dp)) {
|
// 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.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)
|
// 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_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_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.
|
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application' version '8.6.0' apply false
|
id 'com.android.application' version '8.7.3' apply false
|
||||||
id 'com.android.library' version '8.6.0' apply false
|
id 'com.android.library' version '8.7.3' apply false
|
||||||
id 'org.jetbrains.kotlin.android' version '1.7.20' 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
|
#Mon Oct 31 14:59:45 CET 2022
|
||||||
distributionBase=GRADLE_USER_HOME
|
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
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
Reference in New Issue
Block a user