Update feyenoord authentication, UI fixes
This commit is contained in:
@@ -4,12 +4,12 @@ import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
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()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
||||
val feyenoord = retrofit.create(FeyenoordService::class.java)
|
||||
val feyenoord: FeyenoordService = retrofit.create(FeyenoordService::class.java)
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.mitchelbv.thuis_c.network.feyenoord
|
||||
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
|
||||
import retrofit2.Call
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.FeyenoordTokenResponse.FeyenoordTokenResponse
|
||||
import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse.FeyenoordEventResponse
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
|
||||
interface FeyenoordService {
|
||||
@GET("event")
|
||||
suspend fun getEvents(): FeyenoordEventResponse
|
||||
@GET("Event")
|
||||
suspend fun getEvents(@Header("Authorization") token: String): FeyenoordEventResponse
|
||||
|
||||
@GET("Account/default-token")
|
||||
suspend fun getToken(): FeyenoordTokenResponse
|
||||
}
|
||||
@@ -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
|
||||
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
@@ -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
|
||||
|
||||
)
|
||||
@@ -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
|
||||
|
||||
@@ -8,8 +8,8 @@ data class ButtonData(
|
||||
@SerializedName("EventId") var EventId: Int? = null,
|
||||
@SerializedName("SaleCategoryId") var SaleCategoryId: Int? = null,
|
||||
@SerializedName("TranslationCode") var TranslationCode: String? = null,
|
||||
@SerializedName("ButtonStyle") var ButtonStyle: Int? = null,
|
||||
@SerializedName("ActionType") var ActionType: Int? = null,
|
||||
@SerializedName("ButtonStyle") var ButtonStyle: String? = null,
|
||||
@SerializedName("ActionType") var ActionType: String? = null,
|
||||
@SerializedName("Action") var Action: String? = null,
|
||||
@SerializedName("ActiveFrom") var ActiveFrom: String? = null,
|
||||
@SerializedName("ActiveTill") var ActiveTill: String? = null,
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -51,8 +51,6 @@ data class Items(
|
||||
@SerializedName("EventTypeLogoFileName") var EventTypeLogoFileName: String? = null,
|
||||
@SerializedName("EventTypeLogoUniqueName") var EventTypeLogoUniqueName: 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("ShowMarketplaceForEvent") var ShowMarketplaceForEvent: Boolean? = null,
|
||||
@SerializedName("RedirectToMarketplace") var RedirectToMarketplace: Boolean? = null,
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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
|
||||
@@ -20,8 +21,20 @@ import coil.compose.AsyncImage
|
||||
import com.mitchelbv.thuis_c.R
|
||||
|
||||
@Composable
|
||||
fun FeyenoordScreen(feyenoordViewModel: FeyenoordViewModel = viewModel(), navHostController: NavHostController) {
|
||||
fun FeyenoordScreen(
|
||||
feyenoordViewModel: FeyenoordViewModel = viewModel(),
|
||||
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())
|
||||
@@ -42,7 +55,13 @@ fun MatchList(matches: List<Match>, modifier: Modifier) {
|
||||
|
||||
@Composable
|
||||
fun TeamNameWithLogo(team_name: String, team_logo_url: 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(
|
||||
model = team_logo_url,
|
||||
contentDescription = team_name,
|
||||
@@ -50,7 +69,12 @@ fun TeamNameWithLogo(team_name: String, team_logo_url: String, modifier: Modifie
|
||||
contentScale = ContentScale.Fit,
|
||||
modifier = modifier.size(64.dp)
|
||||
)
|
||||
Text(text = team_name, modifier = modifier.fillMaxWidth().wrapContentWidth(Alignment.CenterHorizontally))
|
||||
Text(
|
||||
text = team_name,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentWidth(Alignment.CenterHorizontally)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,8 +90,8 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
||||
.height(128.dp)
|
||||
) {
|
||||
TeamNameWithLogo(
|
||||
team_name = match.home_team,
|
||||
team_logo_url = match.home_image,
|
||||
team_name = match.homeTeam,
|
||||
team_logo_url = match.homeImage,
|
||||
modifier = modifier
|
||||
)
|
||||
Column(
|
||||
@@ -76,14 +100,14 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
||||
) {
|
||||
Text(text = match.date, overflow = TextOverflow.Ellipsis)
|
||||
Row {
|
||||
Text(match.begin_time)
|
||||
Text(match.beginTime)
|
||||
Text(" - ")
|
||||
Text(match.end_time)
|
||||
Text(match.endTime)
|
||||
}
|
||||
}
|
||||
TeamNameWithLogo(
|
||||
team_name = match.away_team,
|
||||
team_logo_url = match.away_image,
|
||||
team_name = match.awayTeam,
|
||||
team_logo_url = match.awayImage,
|
||||
modifier = modifier
|
||||
)
|
||||
|
||||
@@ -94,13 +118,13 @@ fun MatchCard(match: Match, modifier: Modifier) {
|
||||
@Composable
|
||||
fun PreviewMatchCard() {
|
||||
val test = Match(
|
||||
home_image = "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",
|
||||
home_team = "Feyenoord Vrouwen 1",
|
||||
away_team = "FC Twente Vrouwen 1",
|
||||
homeImage = "https://tymes4-cdn.azureedge.net/feyenoord/21-feyenoord-logo-original.png",
|
||||
awayImage = "https://tymes4-cdn.azureedge.net/feyenoord/291-S.S._Lazio_badge.svg-min-original.png",
|
||||
homeTeam = "Feyenoord Vrouwen 1",
|
||||
awayTeam = "FC Twente Vrouwen 1",
|
||||
date = "do 03 November 2023",
|
||||
begin_time = "18:03",
|
||||
end_time = "20:03"
|
||||
beginTime = "18:03",
|
||||
endTime = "20:03"
|
||||
)
|
||||
MatchCard(match = test, Modifier)
|
||||
}
|
||||
@@ -1,23 +1,20 @@
|
||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||
|
||||
import android.util.Log
|
||||
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.network.feyenoord.responses.FeyenoordEventResponse
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
data class FeyenoordUiState(
|
||||
val matches: List<Match> = listOf()
|
||||
val matches: List<Match> = listOf(),
|
||||
val loading: Boolean = true
|
||||
)
|
||||
|
||||
class FeyenoordViewModel : ViewModel() {
|
||||
@@ -28,27 +25,47 @@ class FeyenoordViewModel : ViewModel() {
|
||||
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 apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents()
|
||||
for (tabItem in apiResponse.TabItems) {
|
||||
val test = arrayOf(tabItem).filter { it.CategoryId == 2 }
|
||||
test.forEach {
|
||||
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!!
|
||||
))
|
||||
|
||||
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)
|
||||
_uiState.value = FeyenoordUiState(matches = tempMatches, loading = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||
|
||||
data class Match(
|
||||
val home_image: String,
|
||||
val away_image: String,
|
||||
val home_team: String,
|
||||
val away_team: String,
|
||||
val homeImage: String,
|
||||
val awayImage: String,
|
||||
val homeTeam: String,
|
||||
val awayTeam: String,
|
||||
val date: String,
|
||||
val begin_time: String,
|
||||
val end_time: String
|
||||
val beginTime: String,
|
||||
val endTime: String
|
||||
)
|
||||
@@ -2,11 +2,8 @@ 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
|
||||
@@ -33,17 +30,17 @@ class HomeViewModel : ViewModel() {
|
||||
|
||||
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)
|
||||
// val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents().HeaderItem!!
|
||||
// val match = Match(
|
||||
// homeTeam = notNullHandler(apiResponse.NameHomeTeam),
|
||||
// awayTeam = notNullHandler(apiResponse.NameAwayTeam),
|
||||
// date = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Full),
|
||||
// beginTime = notNullHandler(apiResponse.EventStartDateTimeFormatted?.Time),
|
||||
// endTime = notNullHandler(apiResponse.EventEndDateTimeFormatted?.Time),
|
||||
// awayImage = notNullHandler(apiResponse.AwayImageUrl),
|
||||
// homeImage = notNullHandler(apiResponse.HomeImageUrl)
|
||||
// )
|
||||
// _uiState.value = HomeUiState(upcomingMatch = match)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user