3 Commits

Author SHA1 Message Date
KaasKop
bc08cac918 Super basic error handling for the feyenoord api. 2024-12-30 20:06:56 +01:00
KaasKop
dce61f7477 Add loading to matches
Update gradle

Use repository?
2024-12-29 19:28:09 +01:00
KaasKop
019ed9c49a Update feyenoord authentication, UI fixes 2024-09-22 12:22:22 +02:00
33 changed files with 233 additions and 196 deletions

9
.gitignore vendored
View File

@@ -1,16 +1,11 @@
*.iml *.iml
.gradle .gradle
/local.properties /local.properties
/.idea/caches /.idea
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store .DS_Store
/build /build
/captures /captures
.externalNativeBuild .externalNativeBuild
.cxx .cxx
local.properties local.properties
app/release app/release

3
.idea/.gitignore generated vendored
View File

@@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name generated
View File

@@ -1 +0,0 @@
Thuis

6
.idea/compiler.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_4_XL_API_31.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-11-06T10:26:15.426480Z" />
</component>
</project>

20
.idea/gradle.xml generated
View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@@ -1,29 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
</profile>
</component>

10
.idea/misc.xml generated
View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

6
.idea/vcs.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -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 {

View File

@@ -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"

View File

@@ -4,12 +4,12 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
object FeyenoordRetrofitHelper { object FeyenoordRetrofitHelper {
val baseUrl = "https://tickets-api.feyenoord.nl/api/" const val baseUrl = "https://feyenoord.api.tymes4-infra.com/v2/"
private val retrofit = Retrofit.Builder() private val retrofit = Retrofit.Builder()
.baseUrl(baseUrl) .baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.build() .build()
val feyenoord = retrofit.create(FeyenoordService::class.java) val feyenoord: FeyenoordService = retrofit.create(FeyenoordService::class.java)
} }

View File

@@ -1,10 +1,14 @@
package com.mitchelbv.thuis_c.network.feyenoord package com.mitchelbv.thuis_c.network.feyenoord
import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordTokenResponse.FeyenoordTokenResponse
import retrofit2.Call import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse.FeyenoordEventResponse
import retrofit2.http.GET import retrofit2.http.GET
import retrofit2.http.Header
interface FeyenoordService { interface FeyenoordService {
@GET("event") @GET("Event")
suspend fun getEvents(): FeyenoordEventResponse suspend fun getEvents(@Header("Authorization") token: String): FeyenoordEventResponse
@GET("Account/default-token")
suspend fun getToken(): FeyenoordTokenResponse
} }

View File

@@ -0,0 +1,28 @@
package com.mitchelbv.thuis_c.network.feyenoord.FeyenoordTokenResponse
import com.google.gson.annotations.SerializedName
data class CurrentChannel(
@SerializedName("Id") var id: Int? = null,
@SerializedName("Name") var name: String? = null,
@SerializedName("Code") var code: String? = null,
@SerializedName("HexColor") var hexColor: String? = null,
@SerializedName("Active") var active: Boolean? = null,
@SerializedName("HexBackColor") var hexBackColor: String? = null,
@SerializedName("HexForeColor") var hexForeColor: String? = null,
@SerializedName("SalesGroupId") var salesGroupId: Int? = null,
@SerializedName("ShowMarketplaceForEvent") var showMarketplaceForEvent: Boolean? = null,
@SerializedName("RedirectToMarketplace") var redirectToMarketplace: Boolean? = null,
@SerializedName("AllowAnonymous") var allowAnonymous: Boolean? = null,
@SerializedName("ParentCode") var parentCode: String? = null,
@SerializedName("ParentId") var parentId: String? = null,
@SerializedName("UserSelectable") var userSelectable: Boolean? = null,
@SerializedName("HeaderImageId") var headerImageId: String? = null,
@SerializedName("HeaderImageFileName") var headerImageFileName: String? = null,
@SerializedName("HeaderImageUrl") var headerImageUrl: String? = null,
@SerializedName("TicketshopHeaderLinkText") var ticketshopHeaderLinkText: String? = null,
@SerializedName("CustomCSS") var customCSS: String? = null
)

View File

@@ -0,0 +1,11 @@
package com.mitchelbv.thuis_c.network.feyenoord.FeyenoordTokenResponse
import com.google.gson.annotations.SerializedName
data class FeyenoordTokenResponse(
@SerializedName("AuthResult") var authResult: Int? = null,
@SerializedName("Token") var token: String? = null,
@SerializedName("CurrentChannel") var currentChannel: CurrentChannel? = CurrentChannel(),
@SerializedName("SalesChannels") var salesChannels: ArrayList<SalesChannels> = arrayListOf(),
@SerializedName("IsArchiveMode") var isArchiveMode: Boolean? = null
)

View File

@@ -0,0 +1,26 @@
package com.mitchelbv.thuis_c.network.feyenoord.FeyenoordTokenResponse
import com.google.gson.annotations.SerializedName
data class SalesChannels(
@SerializedName("Id") var id: Int? = null,
@SerializedName("Name") var name: String? = null,
@SerializedName("Code") var code: String? = null,
@SerializedName("HexColor") var hexColor: String? = null,
@SerializedName("Active") var active: Boolean? = null,
@SerializedName("HexBackColor") var hexBackColor: String? = null,
@SerializedName("HexForeColor") var hexForeColor: String? = null,
@SerializedName("SalesGroupId") var salesGroupId: Int? = null,
@SerializedName("ShowMarketplaceForEvent") var showMarketplaceForEvent: Boolean? = null,
@SerializedName("RedirectToMarketplace") var redirectToMarketplace: Boolean? = null,
@SerializedName("AllowAnonymous") var allowAnonymous: Boolean? = null,
@SerializedName("ParentCode") var parentCode: String? = null,
@SerializedName("ParentId") var parentId: String? = null,
@SerializedName("UserSelectable") var userSelectable: Boolean? = null,
@SerializedName("HeaderImageId") var headerImageId: String? = null,
@SerializedName("HeaderImageFileName") var headerImageFileName: String? = null,
@SerializedName("HeaderImageUrl") var headerImageUrl: String? = null,
@SerializedName("TicketshopHeaderLinkText") var ticketshopHeaderLinkText: String? = null,
@SerializedName("CustomCSS") var customCSS: String? = null
)

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
@@ -8,8 +8,8 @@ data class ButtonData(
@SerializedName("EventId") var EventId: Int? = null, @SerializedName("EventId") var EventId: Int? = null,
@SerializedName("SaleCategoryId") var SaleCategoryId: Int? = null, @SerializedName("SaleCategoryId") var SaleCategoryId: Int? = null,
@SerializedName("TranslationCode") var TranslationCode: String? = null, @SerializedName("TranslationCode") var TranslationCode: String? = null,
@SerializedName("ButtonStyle") var ButtonStyle: Int? = null, @SerializedName("ButtonStyle") var ButtonStyle: String? = null,
@SerializedName("ActionType") var ActionType: Int? = null, @SerializedName("ActionType") var ActionType: String? = null,
@SerializedName("Action") var Action: String? = null, @SerializedName("Action") var Action: String? = null,
@SerializedName("ActiveFrom") var ActiveFrom: String? = null, @SerializedName("ActiveFrom") var ActiveFrom: String? = null,
@SerializedName("ActiveTill") var ActiveTill: String? = null, @SerializedName("ActiveTill") var ActiveTill: String? = null,

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
@@ -51,8 +51,6 @@ data class Items(
@SerializedName("EventTypeLogoFileName") var EventTypeLogoFileName: String? = null, @SerializedName("EventTypeLogoFileName") var EventTypeLogoFileName: String? = null,
@SerializedName("EventTypeLogoUniqueName") var EventTypeLogoUniqueName: String? = null, @SerializedName("EventTypeLogoUniqueName") var EventTypeLogoUniqueName: String? = null,
@SerializedName("InfoUrl") var InfoUrl: String? = null, @SerializedName("InfoUrl") var InfoUrl: String? = null,
@SerializedName("EventStartDateTimeFormatted") var EventStartDateTimeFormatted: EventStartDateTimeFormatted? = EventStartDateTimeFormatted(),
@SerializedName("EventEndDateTimeFormatted") var EventEndDateTimeFormatted: EventEndDateTimeFormatted? = EventEndDateTimeFormatted(),
@SerializedName("ButtonData") var ButtonData: ButtonData? = ButtonData(), @SerializedName("ButtonData") var ButtonData: ButtonData? = ButtonData(),
@SerializedName("ShowMarketplaceForEvent") var ShowMarketplaceForEvent: Boolean? = null, @SerializedName("ShowMarketplaceForEvent") var ShowMarketplaceForEvent: Boolean? = null,
@SerializedName("RedirectToMarketplace") var RedirectToMarketplace: Boolean? = null, @SerializedName("RedirectToMarketplace") var RedirectToMarketplace: Boolean? = null,

View File

@@ -1,4 +1,4 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses package com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName

View File

@@ -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
}
}

View File

@@ -11,6 +11,8 @@ 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.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
@@ -20,14 +22,23 @@ import coil.compose.AsyncImage
import com.mitchelbv.thuis_c.R import com.mitchelbv.thuis_c.R
@Composable @Composable
fun FeyenoordScreen(feyenoordViewModel: FeyenoordViewModel = viewModel(), navHostController: NavHostController) { fun FeyenoordScreen(
feyenoordViewModel: FeyenoordViewModel = viewModel(),
navHostController: NavHostController
) {
val feyenoordUiState by feyenoordViewModel.uiState.collectAsState() val feyenoordUiState by feyenoordViewModel.uiState.collectAsState()
Column( Column(
modifier = Modifier modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()),
.verticalScroll(rememberScrollState()) verticalArrangement = Arrangement.Center,
// .padding(16.dp) horizontalAlignment = Alignment.CenterHorizontally
) { ) {
MatchList(matches = feyenoordUiState.matches, Modifier) if (feyenoordUiState.loading) {
CircularProgressIndicator()
} else if (feyenoordUiState.error != null) {
Text(stringResource(feyenoordUiState.error!!))
} else {
MatchList(matches = feyenoordUiState.matches, Modifier)
}
} }
} }
@@ -41,16 +52,28 @@ 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,
textAlign = TextAlign.Center,
modifier = modifier
.fillMaxWidth()
// .wrapContentWidth(Alignment.CenterHorizontally)
)
} }
} }
@@ -66,8 +89,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
.height(128.dp) .height(128.dp)
) { ) {
TeamNameWithLogo( TeamNameWithLogo(
team_name = match.home_team, teamName = match.homeTeam,
team_logo_url = match.home_image, teamLogoUrl = match.homeImage,
modifier = modifier modifier = modifier
) )
Column( Column(
@@ -76,14 +99,14 @@ fun MatchCard(match: Match, modifier: Modifier) {
) { ) {
Text(text = match.date, overflow = TextOverflow.Ellipsis) Text(text = match.date, overflow = TextOverflow.Ellipsis)
Row { Row {
Text(match.begin_time) Text(match.beginTime)
Text(" - ") Text(" - ")
Text(match.end_time) Text(match.endTime)
} }
} }
TeamNameWithLogo( TeamNameWithLogo(
team_name = match.away_team, teamName = match.awayTeam,
team_logo_url = match.away_image, teamLogoUrl = match.awayImage,
modifier = modifier modifier = modifier
) )
@@ -94,13 +117,13 @@ fun MatchCard(match: Match, modifier: Modifier) {
@Composable @Composable
fun PreviewMatchCard() { fun PreviewMatchCard() {
val test = Match( val test = Match(
home_image = "https://tymes4-cdn.azureedge.net/feyenoord/21-feyenoord-logo-original.png", homeImage = "https://tymes4-cdn.azureedge.net/feyenoord/21-feyenoord-logo-original.png",
away_image = "https://tymes4-cdn.azureedge.net/feyenoord/291-S.S._Lazio_badge.svg-min-original.png", awayImage = "https://tymes4-cdn.azureedge.net/feyenoord/291-S.S._Lazio_badge.svg-min-original.png",
home_team = "Feyenoord Vrouwen 1", homeTeam = "Feyenoord Vrouwen 1",
away_team = "FC Twente Vrouwen 1", awayTeam = "FC Twente Vrouwen 1",
date = "do 03 November 2023", date = "do 03 November 2023",
begin_time = "18:03", beginTime = "18:03",
end_time = "20:03" endTime = "20:03"
) )
MatchCard(match = test, Modifier) MatchCard(match = test, Modifier)
} }

View File

@@ -1,54 +1,39 @@
package com.mitchelbv.thuis_c.ui.feyenoord package com.mitchelbv.thuis_c.ui.feyenoord
import android.util.Log 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.network.feyenoord.responses.FeyenoordEventResponse
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 okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
data class FeyenoordUiState( data class FeyenoordUiState(
val matches: List<Match> = listOf() val matches: List<Match> = listOf(),
val loading: Boolean = true,
val error: Int? = null
) )
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 fillMatches() { private fun fillMatches() {
val tempMatches = mutableListOf<Match>()
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents() try {
for (tabItem in apiResponse.TabItems) { _uiState.value = FeyenoordUiState(matches = feyenoordRepository.getMatches(), loading = false)
val test = arrayOf(tabItem).filter { it.CategoryId == 2 } } catch (e: Exception) {
test.forEach { _uiState.value = FeyenoordUiState(loading = false, error = R.string.feyenoord_network_error)
for (item in it.Items) {
tempMatches.add(Match(
home_team = item.NameHomeTeam!!,
away_team = item.NameAwayTeam!!,
date = item.EventStartDateTimeFormatted?.Full!!,
begin_time = item.EventStartDateTimeFormatted?.Time!!,
end_time = item.EventEndDateTimeFormatted?.Time!!,
away_image = item.AwayImageUrl!!,
home_image = item.HomeImageUrl!!
))
}
}
} }
_uiState.value = FeyenoordUiState(matches = tempMatches)
} }
} }
} }

View File

@@ -1,11 +1,11 @@
package com.mitchelbv.thuis_c.ui.feyenoord package com.mitchelbv.thuis_c.ui.feyenoord
data class Match( data class Match(
val home_image: String, val homeImage: String,
val away_image: String, val awayImage: String,
val home_team: String, val homeTeam: String,
val away_team: String, val awayTeam: String,
val date: String, val date: String,
val begin_time: String, val beginTime: String,
val end_time: String val endTime: String
) )

View File

@@ -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)
// } // }
} }
} }

View File

@@ -2,11 +2,8 @@ package com.mitchelbv.thuis_c.ui.home
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.mitchelbv.thuis_c.Screen
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.ui.feyenoord.Match import com.mitchelbv.thuis_c.ui.feyenoord.Match
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
@@ -33,17 +30,17 @@ class HomeViewModel : ViewModel() {
private fun getUpcomingMatch() { private fun getUpcomingMatch() {
viewModelScope.launch { viewModelScope.launch {
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents().HeaderItem!! // val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents().HeaderItem!!
val match = Match( // val match = Match(
home_team = notNullHandler(apiResponse.NameHomeTeam), // homeTeam = notNullHandler(apiResponse.NameHomeTeam),
away_team = notNullHandler(apiResponse.NameAwayTeam), // awayTeam = notNullHandler(apiResponse.NameAwayTeam),
date = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Full), // date = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Full),
begin_time = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Time), // beginTime = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Time),
end_time = notNullHandler(apiResponse.EventEndDateTimeFormatted?.Time), // endTime = notNullHandler(apiResponse.EventEndDateTimeFormatted?.Time),
away_image = notNullHandler(apiResponse.AwayImageUrl), // awayImage = notNullHandler(apiResponse.AwayImageUrl),
home_image = notNullHandler(apiResponse.HomeImageUrl) // homeImage = notNullHandler(apiResponse.HomeImageUrl)
) // )
_uiState.value = HomeUiState(upcomingMatch = match) // _uiState.value = HomeUiState(upcomingMatch = match)
} }
} }
} }

View File

@@ -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>

View File

@@ -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 '7.4.0' apply false id 'com.android.application' version '8.7.3' apply false
id 'com.android.library' version '7.4.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
} }

View File

@@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the # Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies, # resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library # thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

View File

@@ -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-7.5-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