Dependency updates to gradle and such
Basic error handling for feyenoord update api endpoints feyenoord
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'org.jetbrains.kotlin.plugin.compose'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.mitchelbv.thuis_c'
|
||||
compileSdk 34
|
||||
compileSdk 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.mitchelbv.thuis_c"
|
||||
minSdk 30
|
||||
targetSdk 34
|
||||
targetSdk 36
|
||||
versionCode 3
|
||||
versionName "1.3"
|
||||
|
||||
@@ -48,32 +49,34 @@ android {
|
||||
|
||||
dependencies {
|
||||
//Network
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation 'com.google.code.gson:gson:2.9.1'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:3.0.0'
|
||||
implementation 'com.google.code.gson:gson:2.13.2'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:3.0.0'
|
||||
|
||||
// Display images from the internet
|
||||
implementation "io.coil-kt:coil-compose:2.2.2"
|
||||
implementation "io.coil-kt:coil-compose:2.7.0"
|
||||
|
||||
// Database
|
||||
implementation "androidx.room:room-runtime:2.5.0"
|
||||
annotationProcessor("androidx.room:room-compiler:2.5.0")
|
||||
implementation "androidx.room:room-runtime:2.8.4"
|
||||
annotationProcessor("androidx.room:room-compiler:2.8.4")
|
||||
|
||||
// Navigation
|
||||
implementation "androidx.navigation:navigation-compose:2.5.3"
|
||||
implementation "androidx.navigation:navigation-compose:2.9.6"
|
||||
|
||||
// ViewModel
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0"
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.9.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
|
||||
implementation 'androidx.activity:activity-compose:1.6.1'
|
||||
implementation "androidx.compose.material:material-icons-core:1.7.8"
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.10.0'
|
||||
implementation 'androidx.activity:activity-compose:1.12.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.4.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
|
||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Thuis"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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.fillMaxSize
|
||||
@@ -20,6 +21,7 @@ import com.mitchelbv.thuis_c.ui.card.CardsScreen
|
||||
import com.mitchelbv.thuis_c.ui.feyenoord.FeyenoordScreen
|
||||
import com.mitchelbv.thuis_c.ui.freezer.FreezerScreen
|
||||
import com.mitchelbv.thuis_c.ui.freezer.detailed.FreezerDetailedScreen
|
||||
import com.mitchelbv.thuis_c.ui.freezer.freezer_item.FreezerItemScreen
|
||||
import com.mitchelbv.thuis_c.ui.home.HomeScreen
|
||||
import com.mitchelbv.thuis_c.ui.recipe.RecipeScreen
|
||||
import com.mitchelbv.thuis_c.ui.theme.ThuisTheme
|
||||
@@ -59,6 +61,9 @@ fun ThuisApp() {
|
||||
bottomBar = {
|
||||
NavigationBar {
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
// if (currentDestination != null) {
|
||||
// currentDestination.route?.let { Log.d("currentDestination", it) }
|
||||
// }
|
||||
screenItems.forEach { screen ->
|
||||
NavigationBarItem(
|
||||
icon = { Icon(screen.icon, contentDescription = stringResource(id = screen.resourceId))},
|
||||
@@ -82,6 +87,7 @@ fun ThuisApp() {
|
||||
composable("feyenoord") { FeyenoordScreen(navHostController = navController) }
|
||||
composable("recipes") { RecipeScreen(navHostController = navController)}
|
||||
composable("freezer") {FreezerScreen(navHostController = navController)}
|
||||
composable("freezer-items/{freezerId}") { navBackStackEntry -> FreezerItemScreen(navHostController = navController, freezerId = navBackStackEntry.arguments?.getString("freezerId")) }
|
||||
composable("cards") { CardsScreen(navHostController = navController) }
|
||||
composable("freezer-details/{freezerId}") { backStackEntry -> FreezerDetailedScreen(navHostController = navController, freezerId = backStackEntry.arguments?.getString("freezerId")) }
|
||||
composable("freezer-edit") { CardsScreen(navHostController = navController) }
|
||||
|
||||
@@ -2,16 +2,18 @@ package com.mitchelbv.thuis_c
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.*
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.navigation.NavArgs
|
||||
|
||||
sealed class Screen(val route: String, @StringRes val resourceId: Int, val icon: ImageVector) {
|
||||
object Feyenoord : Screen("feyenoord", R.string.nav_feyenoord, Icons.Default.DateRange)
|
||||
object Recipes : Screen("recipes", R.string.nav_recipes, Icons.Default.List)
|
||||
object Recipes : Screen("recipes", R.string.nav_recipes, Icons.AutoMirrored.Filled.List)
|
||||
object Home : Screen("home", R.string.nav_home, Icons.Default.Home)
|
||||
object Cards : Screen("cards", R.string.home_card_cards, Icons.Default.Call)
|
||||
object Freezer : Screen("freezer", R.string.home_card_freezer, Icons.Default.DateRange)
|
||||
object FreezerItems : Screen("freezer-items", R.string.home_card_freezer, Icons.Default.DateRange)
|
||||
object FreezerDetails : Screen("freezer-details", R.string.home_card_freezer, Icons.Default.ShoppingCart)
|
||||
object FreezerEdit : Screen("freezer-edit", R.string.edit_freezer, Icons.Default.Call)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
object FeyenoordRetrofitHelper {
|
||||
const val baseUrl = "https://feyenoord.api.tymes4-infra.com/v2/"
|
||||
private const val baseUrl = "https://feyenoord.api.tymes4-infra.com/v2/"
|
||||
|
||||
private val retrofit = Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
|
||||
@@ -9,6 +9,6 @@ interface FeyenoordService {
|
||||
@GET("Event")
|
||||
suspend fun getEvents(@Header("Authorization") token: String): FeyenoordEventResponse
|
||||
|
||||
@GET("Account/default-token")
|
||||
@GET("Account/ensure-valid-token")
|
||||
suspend fun getToken(): FeyenoordTokenResponse
|
||||
}
|
||||
@@ -4,13 +4,12 @@ import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
object ThuisRetrofitHelper {
|
||||
val baseUrl = "http://10.0.2.2:5052/"
|
||||
|
||||
private const val BASE_URL = "http://10.0.2.2:5052/"
|
||||
|
||||
private val retrofit = Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
||||
val thuis = retrofit.create(ThuisService::class.java)
|
||||
val thuisService: ThuisService = retrofit.create(ThuisService::class.java)
|
||||
}
|
||||
@@ -19,7 +19,7 @@ interface ThuisService {
|
||||
// Freezer
|
||||
// Getters
|
||||
@GET("api/Freezer")
|
||||
suspend fun getFreezers(): ArrayList<Freezer>
|
||||
suspend fun getFreezers(): Freezers
|
||||
|
||||
@GET("api/Freezer/{id}")
|
||||
suspend fun getFreezer(@Path("id") id: Int): Freezer
|
||||
@@ -46,7 +46,7 @@ interface ThuisService {
|
||||
suspend fun getFreezerItem(id: Int): FreezerItem
|
||||
|
||||
@GET("api/FreezerItem/InFreezer/{id}")
|
||||
suspend fun getFreezerItemsInFreezer(id: Int): FreezerItemsInFreezer
|
||||
suspend fun getFreezerItemsInFreezer(@Path("id") id: Int): FreezerItems
|
||||
|
||||
// Post
|
||||
@POST("api/FreezerItem")
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.mitchelbv.thuis_c.network.thuis.responses
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Cards (
|
||||
@SerializedName("cards") var cards: ArrayList<Card> = arrayListOf()
|
||||
)
|
||||
@@ -4,6 +4,6 @@ import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Freezer(
|
||||
@SerializedName("freezerId") var freezerId: Int? = null,
|
||||
@SerializedName("location") var location: String? = null,
|
||||
@SerializedName("name") var name: String? = null,
|
||||
@SerializedName("amountInFreezer") var amountInFreezer: Int? = null
|
||||
)
|
||||
@@ -5,10 +5,9 @@ import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class FreezerItem(
|
||||
@SerializedName("freezerItemId") var freezerItemId: Int? = null,
|
||||
@SerializedName("item") var item: String? = null,
|
||||
@SerializedName("name") var name: String? = null,
|
||||
@SerializedName("amount") var amount: Int? = null,
|
||||
@SerializedName("drawer") var drawer: Int? = null,
|
||||
@SerializedName("dateTimeAdded") var dateTimeAdded: String? = null,
|
||||
@SerializedName("addedOn") var addedOn: String? = null,
|
||||
@SerializedName("freezerId") var freezerId: Int? = null
|
||||
|
||||
)
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.mitchelbv.thuis_c.network.thuis.responses
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
|
||||
data class FreezerItemsInFreezer(
|
||||
@SerializedName("freezerItemId") var freezerItemId: Int? = null,
|
||||
@SerializedName("item") var item: String? = null,
|
||||
@SerializedName("amount") var amount: Int? = null,
|
||||
@SerializedName("drawer") var drawer: Int? = null,
|
||||
@SerializedName("dateTimeAdded") var dateTimeAdded: String? = null,
|
||||
@SerializedName("freezerId") var freezerId: Int? = null
|
||||
)
|
||||
@@ -1,6 +1,5 @@
|
||||
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
|
||||
@@ -26,7 +25,6 @@ class FeyenoordRepository() {
|
||||
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!!,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mitchelbv.thuis_c.ui.feyenoord
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mitchelbv.thuis_c.R
|
||||
@@ -9,7 +8,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class FeyenoordUiState(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mitchelbv.thuis_c.ui.freezer
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
@@ -30,9 +31,9 @@ fun FreezerScreen(
|
||||
) {
|
||||
val freezerUiState by freezerViewModel.uiState.collectAsState()
|
||||
FreezerList(freezerUiState.freezers, navHostController, Modifier)
|
||||
FloatingActionButton(onClick = { navHostController.navigate("edit_freezer") }) {
|
||||
Icon(Icons.Default.Edit, contentDescription = "Edit")
|
||||
}
|
||||
// FloatingActionButton(onClick = { navHostController.navigate("edit_freezer") }) {
|
||||
// Icon(Icons.Default.Edit, contentDescription = "Edit")
|
||||
// }
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -42,7 +43,7 @@ fun FreezerList(freezers: List<Freezer>, navHostController: NavHostController, m
|
||||
items(freezers) { freezer ->
|
||||
FreezerListItem(
|
||||
freezer = freezer,
|
||||
navigateTo = { navHostController.navigate("${Screen.FreezerDetails.route}/${freezer.freezerId}") },
|
||||
navigateTo = { navHostController.navigate("${Screen.FreezerItems.route}/${freezer.freezerId}") },
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
@@ -60,22 +61,23 @@ fun FreezerListItem(freezer: Freezer, navigateTo: () -> Unit, modifier: Modifier
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(150.dp),
|
||||
.heightIn(50.dp, 100.dp)
|
||||
.clickable { navigateTo() },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(freezer.location!!)
|
||||
Column(
|
||||
horizontalAlignment = Alignment.End,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
Text(freezer.name!!)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = modifier.fillMaxHeight()
|
||||
) {
|
||||
Text("${freezer.amountInFreezer} artikelen")
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.arrow),
|
||||
contentDescription = "arrow",
|
||||
modifier = modifier.size(20.dp)
|
||||
)
|
||||
Text("${freezer.amountInFreezer} artikelen")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -96,13 +98,13 @@ fun FreezerCard(freezer: Freezer, navigateTo: () -> Unit) {
|
||||
.height(100.dp)
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Text(freezer.location!!)
|
||||
Text(freezer.name!!)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(widthDp = 250, showBackground = true, heightDp = 300)
|
||||
@Composable
|
||||
fun FreezerListItemPreview() {
|
||||
val freezer = Freezer(freezerId = 1, location = "Keuken", amountInFreezer = 5)
|
||||
val freezer = Freezer(freezerId = 1, name = "Keuken", amountInFreezer = 5)
|
||||
FreezerListItem(freezer = freezer, modifier = Modifier, navigateTo = {})
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mitchelbv.thuis_c.ui.freezer
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mitchelbv.thuis_c.network.thuis.ThuisRetrofitHelper
|
||||
@@ -27,8 +26,8 @@ class FreezerViewModel : ViewModel() {
|
||||
private fun fillFreezer() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val apiResponse = ThuisRetrofitHelper.thuis.getFreezers()
|
||||
_uiState.value = FreezerUiState(apiResponse)
|
||||
val apiResponse = ThuisRetrofitHelper.thuisService.getFreezers()
|
||||
_uiState.value = FreezerUiState(apiResponse.freezers)
|
||||
} catch (e: ConnectException) {
|
||||
_uiState.value = FreezerUiState(listOf())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mitchelbv.thuis_c.network.thuis.ThuisRetrofitHelper
|
||||
import com.mitchelbv.thuis_c.network.thuis.responses.Freezer
|
||||
import com.mitchelbv.thuis_c.ui.freezer.FreezerUiState
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -25,6 +26,14 @@ class FreezerEditViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
private fun fillFreezerTextField() {
|
||||
// Todo
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val apiResponse = ThuisRetrofitHelper.thuisService.getFreezers()
|
||||
// _uiState.value = FreezerEditUiState(apiResponse.freezers)
|
||||
} catch (e: ConnectException) {
|
||||
// _uiState.value = FreezerEditUiState(listOf())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mitchelbv.thuis_c.ui.freezer.freezer_item
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import com.mitchelbv.thuis_c.R
|
||||
import com.mitchelbv.thuis_c.network.thuis.responses.Freezer
|
||||
import com.mitchelbv.thuis_c.network.thuis.responses.FreezerItem
|
||||
|
||||
@Composable
|
||||
fun FreezerItemScreen(
|
||||
navHostController: NavHostController,
|
||||
freezerId: String?
|
||||
) {
|
||||
val viewModel = FreezerItemViewModel(freezerId?.toInt())
|
||||
val freezerUiState by viewModel.uiState.collectAsState()
|
||||
FreezerList(freezerUiState.freezerItems, navHostController, Modifier)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FreezerList(freezers: List<FreezerItem>, navHostController: NavHostController, modifier: Modifier) {
|
||||
if (freezers.isNotEmpty()) {
|
||||
LazyColumn {
|
||||
items(freezers) { freezer ->
|
||||
FreezerListItem(
|
||||
freezerItem = freezer,
|
||||
// navigateTo = { navHostController.navigate("${Screen.FreezerDetails.route}/${freezer.freezerId}") },
|
||||
navigateTo = {},
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Text(stringResource(id = R.string.freezer_item_list_empty))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FreezerListItem(freezerItem: FreezerItem, navigateTo: () -> Unit, modifier: Modifier) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(50.dp, 100.dp)
|
||||
.clickable { navigateTo() },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(freezerItem.name!!)
|
||||
Text(freezerItem.amount!!.toString())
|
||||
Text(freezerItem.drawer!!.toString())
|
||||
}
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color(0f, 0f, 0f, .5f))
|
||||
.height(1.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun FreezerCard(freezer: Freezer, navigateTo: () -> Unit) {
|
||||
Card(
|
||||
onClick = { navigateTo() }, modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(100.dp)
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Text(freezer.name!!)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(widthDp = 250, showBackground = true, heightDp = 300)
|
||||
@Composable
|
||||
fun FreezerListItemPreview() {
|
||||
val freezer = FreezerItem(freezerId = 1, name = "Kip", amount = 5, drawer = 1)
|
||||
FreezerListItem(freezerItem = freezer, modifier = Modifier, navigateTo = {})
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.mitchelbv.thuis_c.ui.freezer.freezer_item
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.mitchelbv.thuis_c.network.thuis.ThuisRetrofitHelper
|
||||
import com.mitchelbv.thuis_c.network.thuis.responses.Freezer
|
||||
import com.mitchelbv.thuis_c.network.thuis.responses.FreezerItem
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.ConnectException
|
||||
|
||||
data class FreezerItemUiState(
|
||||
val freezerItems: List<FreezerItem> = listOf()
|
||||
)
|
||||
|
||||
class FreezerItemViewModel(freezerId: Int?) : ViewModel() {
|
||||
private val _uiState = MutableStateFlow(FreezerItemUiState())
|
||||
val uiState: StateFlow<FreezerItemUiState> = _uiState.asStateFlow()
|
||||
|
||||
init {
|
||||
fillFreezerItems(freezerId)
|
||||
}
|
||||
|
||||
private fun fillFreezerItems(freezerId: Int?) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
if (freezerId != null) {
|
||||
val apiResponse = ThuisRetrofitHelper.thuisService.getFreezerItemsInFreezer(freezerId)
|
||||
// val orderedByDrawer = apiResponse.freezerItems.forEach()
|
||||
_uiState.value = FreezerItemUiState(apiResponse.freezerItems)
|
||||
}
|
||||
} catch (e: ConnectException) {
|
||||
_uiState.value = FreezerItemUiState()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,12 @@ fun HomeScreen(navController: NavHostController) {
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text("De thuis app!", style = Typography.bodySmall)
|
||||
// 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.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_freezer, routeTo = Screen.Freezer.route, navController = navController)
|
||||
// }
|
||||
HomeButton(buttonText = R.string.home_card_freezer, routeTo = Screen.Freezer.route, navController = navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ fun RecipeScreen(navHostController: NavHostController) {
|
||||
settings.javaScriptEnabled = true
|
||||
settings.domStorageEnabled = true
|
||||
settings.safeBrowsingEnabled = false
|
||||
loadUrl("https://rs.mitchelbv.nl/")
|
||||
loadUrl("https://td.digitrommel.nl/")
|
||||
webView = this
|
||||
}
|
||||
}, update = { webView = it}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<string name="home_card_freezer">Vriezer</string>
|
||||
|
||||
<string name="freezer_list_empty">Er zijn geen vriezers</string>
|
||||
<string name="freezer_item_list_empty">Er zit niks in deze vriezer</string>
|
||||
<string name="edit_freezer">Vriezer aanpassen</string>
|
||||
<string name="feyenoord_network_error">Er is geen netwerk beschikbaar</string>
|
||||
</resources>
|
||||
10
build.gradle
10
build.gradle
@@ -1,10 +1,12 @@
|
||||
buildscript {
|
||||
ext {
|
||||
compose_version = '1.3.3'
|
||||
compose_version = '1.9.5'
|
||||
lifecycle_version = "2.10.0"
|
||||
}
|
||||
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.7.3' apply false
|
||||
id 'com.android.library' version '8.7.3' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
|
||||
id 'com.android.application' version '8.13.2' apply false
|
||||
id 'com.android.library' version '8.13.2' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '2.2.21' apply false
|
||||
id 'org.jetbrains.kotlin.plugin.compose' version '2.2.21' apply false
|
||||
}
|
||||
@@ -21,5 +21,4 @@ kotlin.code.style=official
|
||||
# resources declared in the library itself and none from the library's dependencies,
|
||||
# thereby reducing the size of the R class for that library
|
||||
android.nonTransitiveRClass=true
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonFinalResIds=false
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Oct 31 14:59:45 CET 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
Reference in New Issue
Block a user