diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6e5389e..ae388c2 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,7 +7,7 @@ - + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index bd2a505..ed76bea 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -3,27 +3,35 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9f71c83..8978d23 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,6 @@ - - + diff --git a/app/build.gradle b/app/build.gradle index 867ebad..bfcd18e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/com/mitchelbv/thuis_c/MainActivity.kt b/app/src/main/java/com/mitchelbv/thuis_c/MainActivity.kt index 5adaeea..2534486 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/MainActivity.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/MainActivity.kt @@ -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("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() } } } diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordRetrofitHelper.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordRetrofitHelper.kt index 13fb1b1..b0cced3 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordRetrofitHelper.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordRetrofitHelper.kt @@ -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) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordService.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordService.kt index c3c92cf..aeccf14 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordService.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/FeyenoordService.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/ButtonData.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/ButtonData.kt deleted file mode 100644 index bd3536c..0000000 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/ButtonData.kt +++ /dev/null @@ -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 - -) \ No newline at end of file diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordEventResponse.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordEventResponse.kt index 0b85424..4dced27 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordEventResponse.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordEventResponse.kt @@ -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 = arrayListOf(), - @SerializedName("CrossSellInfo") var CrossSellInfo: String? = null + @Transient @SerializedName("CrossSellInfo") var CrossSellInfo: Nothing? = null ) \ No newline at end of file diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordTokenResponse.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordTokenResponse.kt new file mode 100644 index 0000000..1cfa00a --- /dev/null +++ b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/FeyenoordTokenResponse.kt @@ -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, + + ) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/HeaderItem.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/HeaderItem.kt deleted file mode 100644 index 1ead3e3..0000000 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/HeaderItem.kt +++ /dev/null @@ -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 - -) \ No newline at end of file diff --git a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/Items.kt b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/Items.kt index b51be2e..3591b93 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/Items.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/network/feyenoord/responses/Items.kt @@ -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, diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt index 14eec49..b811ecb 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/feyenoord/FeyenoordViewModel.kt @@ -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 = listOf() @@ -31,21 +30,30 @@ class FeyenoordViewModel : ViewModel() { private fun fillMatches() { val tempMatches = mutableListOf() 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!! + ) ) } } diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/FreezerView.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/FreezerView.kt index e886805..9d2e676 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/FreezerView.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/FreezerView.kt @@ -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() } ) diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/FreezerItemListView.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/FreezerItemListView.kt index f72627a..5b64261 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/FreezerItemListView.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/FreezerItemListView.kt @@ -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, diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEdit.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEdit.kt index e1d0bc3..e5e6793 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEdit.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEdit.kt @@ -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() diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEditViewModel.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEditViewModel.kt index a337792..af49446 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEditViewModel.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/freezer/item_list/edit_item/FreezerItemEditViewModel.kt @@ -24,6 +24,7 @@ data class FreezerItemEditUiState( class FreezerItemEditViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { private val _uiState = MutableStateFlow(FreezerItemEditUiState()) + private val stateHandle = savedStateHandle val uiState: StateFlow = _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.. } diff --git a/app/src/main/java/com/mitchelbv/thuis_c/views/home/HomeViewModel.kt b/app/src/main/java/com/mitchelbv/thuis_c/views/home/HomeViewModel.kt index 917104d..ab72742 100644 --- a/app/src/main/java/com/mitchelbv/thuis_c/views/home/HomeViewModel.kt +++ b/app/src/main/java/com/mitchelbv/thuis_c/views/home/HomeViewModel.kt @@ -20,7 +20,7 @@ class HomeViewModel : ViewModel() { val uiState: StateFlow = _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) +// } +// } } \ No newline at end of file diff --git a/app/src/main/res/values-nl-rNL/strings.xml b/app/src/main/res/values-nl-rNL/strings.xml new file mode 100644 index 0000000..553cf12 --- /dev/null +++ b/app/src/main/res/values-nl-rNL/strings.xml @@ -0,0 +1,20 @@ + + + Thuis + Verbindingsproblemen probeer later nog eens. + Opslaan + Annuleer + Wedstijden + Recepten + Thuis + Kaarten + Vriezers + Geen vriezer(s) + Vriezer aanpassen + Artikelen + La + Omschrijving + Hoeveelheid + La + Vriezer + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1af5111..7b2bc64 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } \ No newline at end of file