Slight update

This commit is contained in:
2022-11-06 21:39:51 +01:00
parent 78b0d3aac7
commit f7236485c0
5 changed files with 57 additions and 11 deletions

View File

@@ -6,10 +6,10 @@ import retrofit2.converter.gson.GsonConverterFactory
object FeyenoordRetrofitHelper { object FeyenoordRetrofitHelper {
val baseUrl = "https://tickets-api.feyenoord.nl/api/" val baseUrl = "https://tickets-api.feyenoord.nl/api/"
fun getInstance(): Retrofit { private val retrofit = Retrofit.Builder()
return Retrofit.Builder() .baseUrl(baseUrl)
.baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create()) .build()
.build()
} val feyenoord = retrofit.create(FeyenoordService::class.java)
} }

View File

@@ -32,9 +32,7 @@ class FeyenoordViewModel : ViewModel() {
// TODO Get data from the internet // TODO Get data from the internet
val tempMatches = mutableListOf<Match>() val tempMatches = mutableListOf<Match>()
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val fApiClient = val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents()
FeyenoordRetrofitHelper.getInstance().create(FeyenoordService::class.java)
val apiResponse = fApiClient.getEvents()
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 {

View File

@@ -13,6 +13,5 @@ import com.mitchelbv.thuis_c.ui.theme.Typography
fun HomeScreen(navController: NavHostController) { fun HomeScreen(navController: NavHostController) {
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Text("De thuis app!", style = Typography.bodySmall) Text("De thuis app!", style = Typography.bodySmall)
} }
} }

View File

@@ -0,0 +1,49 @@
package com.mitchelbv.thuis_c.ui.home
import androidx.lifecycle.ViewModel
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.FeyenoordService
import com.mitchelbv.thuis_c.ui.feyenoord.Match
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
data class HomeUiState(
val upcomingMatch: Match? = null
)
class HomeViewModel : ViewModel() {
private val _uiState = MutableStateFlow(HomeUiState())
val uiState: StateFlow<HomeUiState> = _uiState.asStateFlow()
init {
getUpcomingMatch()
}
fun notNullHandler(test: String?): String {
if (!test.isNullOrEmpty()) {
return test;
}
return ""
}
private fun getUpcomingMatch() {
viewModelScope.launch {
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents().HeaderItem!!
val match = Match(
home_team = notNullHandler(apiResponse.NameHomeTeam),
away_team = notNullHandler(apiResponse.NameAwayTeam),
date = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Full),
begin_time = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Time),
end_time = notNullHandler(apiResponse.EventEndDateTimeFormatted?.Time),
away_image = notNullHandler(apiResponse.AwayImageUrl),
home_image = notNullHandler(apiResponse.HomeImageUrl)
)
_uiState.value = HomeUiState(upcomingMatch = match)
}
}
}

View File

@@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name">Thuis</string> <string name="app_name">Thuis</string>
<string name="nav_feyenoord">Feyenoord</string> <string name="nav_feyenoord">Wedstrijden</string>
<string name="nav_recipes">Recepten</string> <string name="nav_recipes">Recepten</string>
<string name="nav_home">Home</string> <string name="nav_home">Home</string>
</resources> </resources>