This commit is contained in:
KaasKop-
2023-12-20 19:58:30 +01:00
parent e401b3e34b
commit a1d17919e5
20 changed files with 183 additions and 178 deletions

2
.idea/gradle.xml generated
View File

@@ -7,7 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Android Studio default JDK" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@@ -3,27 +3,35 @@
<option name="myName" value="Project Default" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
</profile>
</component>

3
.idea/misc.xml generated
View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@@ -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 2
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
@@ -49,31 +49,31 @@ android {
dependencies {
//Network
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
// Display images from the internet
implementation "io.coil-kt:coil-compose:2.2.2"
implementation 'io.coil-kt:coil-compose:2.5.0'
// Database
implementation "androidx.room:room-runtime:2.5.1"
annotationProcessor("androidx.room:room-compiler:2.5.1")
implementation 'androidx.room:room-runtime:2.6.0'
annotationProcessor('androidx.room:room-compiler:2.6.0')
// Navigation
implementation "androidx.navigation:navigation-compose:2.5.3"
implementation 'androidx.navigation:navigation-compose:2.7.5'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")
implementation("androidx.compose.runtime:runtime-livedata:1.4.2")
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2'
implementation('androidx.lifecycle:lifecycle-runtime-compose:2.6.2')
implementation('androidx.compose.runtime:runtime-livedata:1.5.4')
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.1'
implementation 'androidx.compose.material3:material3:1.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

View File

@@ -1,9 +1,13 @@
package com.mitchelbv.thuis_c
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
@@ -13,6 +17,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.mitchelbv.thuis_c.network.thuis.responses.FreezerItem
import com.mitchelbv.thuis_c.ui.theme.ThuisTheme
import com.mitchelbv.thuis_c.views.feyenoord.MatchesScreen
import com.mitchelbv.thuis_c.views.freezer.FreezerScreen
@@ -37,6 +42,9 @@ class MainActivity : ComponentActivity() {
fun LayoutWithNavSetup() {
val navController = rememberNavController()
var selectedItem by remember { mutableStateOf(0) }
val currentRoute = navController
.currentBackStackEntryFlow
.collectAsState(initial = navController.currentBackStackEntry)
Scaffold(
topBar = {
@@ -62,7 +70,27 @@ class MainActivity : ComponentActivity() {
})
}
}
}
},
floatingActionButton = {
when (currentRoute.value?.destination?.route?.substringBefore("/")) {
FreezerListDestination.route -> {
FloatingActionButton(onClick = {
}) {
Icon(Icons.Default.Add, contentDescription = "idk")
}
}
FreezerItemListDestination.route -> {
FloatingActionButton(onClick = {
}) {
Icon(Icons.Default.Add, contentDescription = "idk")
}
}
else -> {}
}
},
floatingActionButtonPosition = FabPosition.End
) { innerPadding ->
NavHost(
navController = navController,
@@ -90,26 +118,31 @@ class MainActivity : ComponentActivity() {
}
// Items list
composable(route = "${FreezerItemListDestination.route}/{freezer_id}", arguments = listOf(
navArgument("freezer_id") {
this.type = NavType.IntType
this.nullable = false
})
composable(
route = "${FreezerItemListDestination.route}/{freezer_id}", arguments = listOf(
navArgument("freezer_id") {
this.type = NavType.IntType
this.nullable = false
})
) {
// this is called everytime you enter AND leave the view, so update the freezerlist like this?
val test = it.savedStateHandle.getLiveData<FreezerItem>("updatedFreezer")
Log.d("IDK", "${test.value?.item}")
FreezerItemListScreen(
onEditItem = {freezerItem ->
onEditItem = { freezerItem ->
// I want onEditItem to open a modal dialog, so not sure if this is needed here...
navController.navigate("${FreezerItemDetailDestination.route}/${freezerItem}")
})
}
// Edit items
composable(route = "${FreezerItemDetailDestination.route}/{freezer_id}", arguments = listOf(
navArgument("freezer_id") {
this.type = NavType.IntType
this.nullable = false
}
)) {
composable(route = "${FreezerItemDetailDestination.route}/{freezer_id}",
arguments = listOf(
navArgument("freezer_id") {
this.type = NavType.IntType
this.nullable = false
}
)) {
FreezerItemEditScreen { navController.popBackStack() }
}
}

View File

@@ -4,7 +4,7 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
object FeyenoordRetrofitHelper {
val baseUrl = "https://tickets-api.feyenoord.nl/api/"
val baseUrl = "https://feyenoord.api.tymes4-infra.com/v2/"
private val retrofit = Retrofit.Builder()
.baseUrl(baseUrl)

View File

@@ -1,10 +1,15 @@
package com.mitchelbv.thuis_c.network.feyenoord
import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordEventResponse
import com.mitchelbv.thuis_c.network.feyenoord.responses.FeyenoordTokenResponse
import retrofit2.Call
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 getDefaultToken(): FeyenoordTokenResponse
}

View File

@@ -1,23 +0,0 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses
import com.google.gson.annotations.SerializedName
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("Action") var Action: String? = null,
@SerializedName("ActiveFrom") var ActiveFrom: String? = null,
@SerializedName("ActiveTill") var ActiveTill: String? = null,
@SerializedName("OpenInNewTab") var OpenInNewTab: Boolean? = null,
@SerializedName("InitiativeId") var InitiativeId: String? = null,
@SerializedName("Id") var Id: Int? = null,
@SerializedName("Created") var Created: String? = null,
@SerializedName("Modified") var Modified: String? = null,
@SerializedName("Deleted") var Deleted: String? = null
)

View File

@@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName
data class FeyenoordEventResponse(
@SerializedName("HeaderItem") var HeaderItem: HeaderItem? = HeaderItem(),
@Transient @SerializedName("HeaderItem") var HeaderItem: Nothing? = null,
@SerializedName("TabItems") var TabItems: ArrayList<TabItems> = arrayListOf(),
@SerializedName("CrossSellInfo") var CrossSellInfo: String? = null
@Transient @SerializedName("CrossSellInfo") var CrossSellInfo: Nothing? = null
)

View File

@@ -0,0 +1,13 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses
import com.google.gson.annotations.SerializedName
data class FeyenoordTokenResponse(
@SerializedName("AuthResult") var AuthResult: Int? = null,
@SerializedName("Token") var Token: String? = null,
@Transient @SerializedName("CurrentChannel") var CurrentChannel: Nothing? = null,
@Transient @SerializedName("SalesChannels") var SalesChannels: Nothing? = null,
)

View File

@@ -1,63 +0,0 @@
package com.mitchelbv.thuis_c.network.feyenoord.responses
import com.google.gson.annotations.SerializedName
data class HeaderItem(
@SerializedName("DisplayCountdown") var DisplayCountdown: Boolean? = null,
@SerializedName("ShowResellInHeader") var ShowResellInHeader: Boolean? = null,
@SerializedName("ResellTicketsAllowed") var ResellTicketsAllowed: Boolean? = null,
@SerializedName("ResellTicketsFrom") var ResellTicketsFrom: String? = null,
@SerializedName("ResellTicketsTill") var ResellTicketsTill: String? = null,
@SerializedName("EventId") var EventId: Int? = null,
@SerializedName("SaleCategoryId") var SaleCategoryId: Int? = null,
@SerializedName("HasGeneralSale") var HasGeneralSale: Boolean? = null,
@SerializedName("VisibleInShop") var VisibleInShop: Boolean? = null,
@SerializedName("HighlightInShop") var HighlightInShop: Boolean? = null,
@SerializedName("HasSoldOut") var HasSoldOut: Boolean? = null,
@SerializedName("OnGeneralSaleFrom") var OnGeneralSaleFrom: String? = null,
@SerializedName("OnGeneralSaleTill") var OnGeneralSaleTill: String? = null,
@SerializedName("VisibleInShopFrom") var VisibleInShopFrom: String? = null,
@SerializedName("VisibleInShopTill") var VisibleInShopTill: String? = null,
@SerializedName("Name") var Name: String? = null,
@SerializedName("NameHomeTeam") var NameHomeTeam: String? = null,
@SerializedName("NameAwayTeam") var NameAwayTeam: String? = null,
@SerializedName("EventStartDateTime") var EventStartDateTime: String? = null,
@SerializedName("EventStartDateTimeOffset") var EventStartDateTimeOffset: String? = null,
@SerializedName("EventEndDateTime") var EventEndDateTime: String? = null,
@SerializedName("CategoryTranslationCode") var CategoryTranslationCode: String? = null,
@SerializedName("SaleCategoryOrder") var SaleCategoryOrder: Int? = null,
@SerializedName("ImageId") var ImageId: String? = null,
@SerializedName("ImageFileName") var ImageFileName: String? = null,
@SerializedName("ImageUniqueName") var ImageUniqueName: String? = null,
@SerializedName("HomeImageId") var HomeImageId: Int? = null,
@SerializedName("HomeImageFileName") var HomeImageFileName: String? = null,
@SerializedName("HomeImageUniqueName") var HomeImageUniqueName: String? = null,
@SerializedName("AwayImageId") var AwayImageId: Int? = null,
@SerializedName("AwayImageFileName") var AwayImageFileName: String? = null,
@SerializedName("AwayImageUniqueName") var AwayImageUniqueName: String? = null,
@SerializedName("HasTicketsAvailable") var HasTicketsAvailable: Boolean? = null,
@SerializedName("HasMarketplaceTicketsAvailable") var HasMarketplaceTicketsAvailable: Boolean? = null,
@SerializedName("HasPossibleTicketsInFuture") var HasPossibleTicketsInFuture: Boolean? = null,
@SerializedName("CurrentlyOnSaleForUser") var CurrentlyOnSaleForUser: Boolean? = null,
@SerializedName("PurchaseRightAvailableAfterLogin") var PurchaseRightAvailableAfterLogin: Boolean? = null,
@SerializedName("ImageUrl") var ImageUrl: String? = null,
@SerializedName("HomeImageUrl") var HomeImageUrl: String? = null,
@SerializedName("AwayImageUrl") var AwayImageUrl: String? = null,
@SerializedName("EventTypeName") var EventTypeName: String? = null,
@SerializedName("EventTypeLogoId") var EventTypeLogoId: Int? = null,
@SerializedName("EventTypeLogoUrl") var EventTypeLogoUrl: String? = null,
@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,
@SerializedName("MarketplaceButtonTextColor") var MarketplaceButtonTextColor: String? = null,
@SerializedName("MarketplaceButtonBackgroundColor") var MarketplaceButtonBackgroundColor: String? = null,
@SerializedName("DeepLinkRoute") var DeepLinkRoute: String? = null
)

View File

@@ -51,9 +51,7 @@ 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(),
@Transient @SerializedName("ButtonData") var ButtonData: Nothing? = null,
@SerializedName("ShowMarketplaceForEvent") var ShowMarketplaceForEvent: Boolean? = null,
@SerializedName("RedirectToMarketplace") var RedirectToMarketplace: Boolean? = null,
@SerializedName("MarketplaceButtonTextColor") var MarketplaceButtonTextColor: String? = null,

View File

@@ -1,20 +1,19 @@
package com.mitchelbv.thuis_c.views.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.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
data class FeyenoordUiState(
val matches: List<Match> = listOf()
@@ -31,21 +30,30 @@ class FeyenoordViewModel : ViewModel() {
private fun fillMatches() {
val tempMatches = mutableListOf<Match>()
viewModelScope.launch(Dispatchers.IO) {
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents()
val getToken = FeyenoordRetrofitHelper.feyenoord.getDefaultToken().Token
val apiResponse = FeyenoordRetrofitHelper.feyenoord.getEvents("Bearer $getToken")
for (tabItem in apiResponse.TabItems) {
val test = arrayOf(tabItem).filter { it.CategoryId == 2 }
test.forEach {
for (item in it.Items) {
for (item in it.Items) {
val utcDateBegin = LocalDateTime.parse(item.EventStartDateTime)
val beginDate = utcDateBegin.atZone(ZoneId.of("UTC")).withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime()
val utcDateEnd = LocalDateTime.parse(item.EventEndDateTime)
val endDate = utcDateEnd.atZone(ZoneId.of("UTC")).withZoneSameInstant(ZoneId.of("Europe/Amsterdam")).toLocalDateTime()
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!!
)
home_team = item.NameHomeTeam!!,
away_team = item.NameAwayTeam!!,
date = beginDate.format(
DateTimeFormatter.ofLocalizedDate(
FormatStyle.MEDIUM
)
),
begin_time = "${beginDate.toLocalTime()}",
end_time = "${endDate.toLocalTime()}",
away_image = item.AwayImageUrl!!,
home_image = item.HomeImageUrl!!
)
)
}
}

View File

@@ -71,8 +71,8 @@ fun FreezerList(
fun FreezerListItem(freezer: Freezer, navigateTo: () -> Unit, modifier: Modifier) {
Column {
ListItem(
headlineText = { Text(freezer.name!!) },
supportingText = { Text(" ${freezer.amountInFreezer} " + stringResource(id = R.string.freezer_item_count_partial)) },
headlineContent = { Text(freezer.name!!) },
supportingContent = { Text(" ${freezer.amountInFreezer} " + stringResource(id = R.string.freezer_item_count_partial)) },
trailingContent = { Icon(Icons.Default.ArrowForward, "")},
modifier = modifier.clickable { navigateTo() }
)

View File

@@ -7,6 +7,7 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.window.Dialog
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -24,17 +25,20 @@ fun FreezerItemListScreen(
val freezerItemListUiState by freezerItemListViewModel.uiState.collectAsStateWithLifecycle()
val itemObserver = freezerItemListUiState.items.observeAsState()
itemObserver.value?.forEach { freezerItem ->
FreezerItemElement(freezerItem = freezerItem, arrowPressed = { item_id: Int, newAmount: Int ->
freezerItemListViewModel.UpdateItemAmount(
item_id,
newAmount
Surface {
itemObserver.value?.forEach { freezerItem ->
FreezerItemElement(
freezerItem = freezerItem,
arrowPressed = { item_id: Int, newAmount: Int ->
freezerItemListViewModel.UpdateItemAmount(
item_id,
newAmount
)
},
onEditItem = onEditItem
)
}, onEditItem = onEditItem)
}
}
// FloatingActionButton(onClick = { /*TODO*/ }) {
//
// }
}
@OptIn(ExperimentalMaterial3Api::class)
@@ -45,8 +49,8 @@ fun FreezerItemElement(
onEditItem: (Int) -> Unit
) {
ListItem(
headlineText = { Text("${freezerItem.item}") },
supportingText = { Text("${stringResource(R.string.freezer_item_drawer_partial)} ${freezerItem.drawer}") },
headlineContent = { Text("${freezerItem.item}") },
supportingContent = { Text("${stringResource(R.string.freezer_item_drawer_partial)} ${freezerItem.drawer}") },
trailingContent = {
Row(
verticalAlignment = Alignment.CenterVertically,

View File

@@ -20,12 +20,14 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.mitchelbv.thuis_c.R
import com.mitchelbv.thuis_c.network.thuis.responses.Freezer
import com.mitchelbv.thuis_c.network.thuis.responses.FreezerItem
import com.mitchelbv.thuis_c.network.thuis.responses.FreezerItems
import com.mitchelbv.thuis_c.views.freezer.freezerUiState
@Composable
fun FreezerItemEditScreen(
freezerItemEditViewModel: FreezerItemEditViewModel = viewModel(),
previousScreen: () -> Unit
previousScreen: () -> Unit,
// updatedFreezerItem: FreezerItem? = null
) {
val freezerItemUiState by freezerItemEditViewModel.uiState.collectAsStateWithLifecycle()

View File

@@ -24,6 +24,7 @@ data class FreezerItemEditUiState(
class FreezerItemEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
private val _uiState = MutableStateFlow(FreezerItemEditUiState())
private val stateHandle = savedStateHandle
val uiState: StateFlow<FreezerItemEditUiState> = _uiState.asStateFlow()
init {
@@ -46,20 +47,20 @@ class FreezerItemEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel()
FreezerItemEditUiState(item = getFreezerItems, freezers = getFreezers)
} catch (e: ConnectException) {
// _uiState.value = FreezerItemListUiState(listOf(FreezerItem(item = )))
_uiState.value = FreezerItemEditUiState(error = "Oeps")
}
}
}
fun UpdateFreezerItem(freezerItem: FreezerItem) {
Log.d("TESTINGGG", "hello ${freezerItem.item}")
// Log.d("TESTINGGG", "hello ${freezerItem.item}")
viewModelScope.launch(Dispatchers.IO) {
try {
val putFreezerItem = ThuisRetrofitHelper.thuis.putFreezerItem(
id = freezerItem.freezerItemId!!,
freezerItem = freezerItem
)
// stateHandle["updatedFreezer"] = freezerItem
} catch (e: ConnectException) {
// Not sure yet..
}

View File

@@ -20,7 +20,7 @@ class HomeViewModel : ViewModel() {
val uiState: StateFlow<HomeUiState> = _uiState.asStateFlow()
init {
getUpcomingMatch()
// getUpcomingMatch()
}
fun notNullHandler(test: String?): String {
@@ -30,19 +30,19 @@ class HomeViewModel : ViewModel() {
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)
}
}
// 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

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Thuis</string>
<string name="com_connection_error">Verbindingsproblemen probeer later nog eens.</string>
<string name="com_save">Opslaan</string>
<string name="com_cancel">Annuleer</string>
<string name="nav_matches">Wedstijden</string>
<string name="nav_recipes">Recepten</string>
<string name="nav_home">Thuis</string>
<string name="home_card_cards">Kaarten</string>
<string name="home_card_freezer">Vriezers</string>
<string name="freezer_list_empty">Geen vriezer(s)</string>
<string name="edit_freezer">Vriezer aanpassen</string>
<string name="freezer_item_count_partial">Artikelen</string>
<string name="freezer_item_drawer_partial">La</string>
<string name="freezer_item_edit_description">Omschrijving</string>
<string name="freezer_item_edit_amount">Hoeveelheid</string>
<string name="freezer_item_edit_drawer">La</string>
<string name="freezer_item_edit_freezer">Vriezer</string>
</resources>

View File

@@ -1,10 +1,10 @@
buildscript {
ext {
compose_version = '1.4.2'
compose_version = '1.5.4'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'com.android.application' version '8.1.3' apply false
id 'com.android.library' version '8.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}