CategoryUI scuffed

This commit is contained in:
Florian 2025-01-15 16:34:04 +01:00
parent adcd8bb3a0
commit 63083c6cab
4 changed files with 230 additions and 43 deletions

View File

@ -1,6 +1,5 @@
package at.xaxa.ledger.ui
import android.util.Log
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
@ -13,7 +12,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import at.xaxa.ledger.ui.add.Add
import at.xaxa.ledger.ui.category.addCategory
import at.xaxa.ledger.ui.category.add.addCategory
import at.xaxa.ledger.ui.category.edit.EditCategory
import at.xaxa.ledger.ui.edit.Edit
import at.xaxa.ledger.ui.home.Home
@ -21,7 +21,8 @@ enum class AppRoutes(val route: String) {
Home("home"),
Add("add"),
Edit("edit/{entryId}"),
Category("category")
Category("category"),
EditCategory("categoryEdit/{categoryId}")
}
@Composable
@ -69,10 +70,27 @@ fun LedgerApp(modifier: Modifier = Modifier){
}
)
}
composable(
route = AppRoutes.EditCategory.route,
arguments = listOf(navArgument("categoryId") {
type = NavType.IntType
})
) {
backStackEntry ->
EditCategory(
modifier = Modifier,
onCardClick = {
navController.navigate("category")
}
)
}
composable(AppRoutes.Category.route){
addCategory(
onButtonClick = {
navController.navigate("home")
},
onCardClick = {
navController.navigate("catEdit/$it")
}
)
}

View File

@ -156,7 +156,7 @@ fun CategoryCard(modifier: Modifier = Modifier, name: String, icon : Int, onClic
.fillMaxSize()
.padding(16.dp)
) {
LayoutMediaText(modifier, name, date, amount)
LayoutMediaText(modifier, name, icon)
}
}
}
@ -209,6 +209,45 @@ fun LayoutMediaText(modifier: Modifier = Modifier, name: String, date: String, a
}
}
}
@Composable
fun LayoutMediaText(modifier: Modifier = Modifier, name: String, icon: Int) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.fillMaxWidth()
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.Top),
modifier = Modifier
.weight(1f)
) {
Text(
text = name,
color = Color(0xff1b1b1b),
lineHeight = 1.5.em,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Medium,
letterSpacing = 0.15.sp
)
)
}
Box(
modifier = Modifier
.fillMaxHeight()
.wrapContentWidth() // Allow the Box to wrap its content width
.padding(start = 16.dp), // Add some padding to separate from the Column
contentAlignment = Alignment.Center
) {
Text(
text = icon.toString(),
fontSize = 30.sp, // Set the desired font size
modifier = Modifier.wrapContentSize() // Ensure the text wraps its content
)
}
}
}
@Preview(widthDp = 360, heightDp = 80)
@Composable

View File

@ -1,4 +1,4 @@
package at.xaxa.ledger.ui.category
package at.xaxa.ledger.ui.category.add
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -24,14 +24,14 @@ import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.ui.AppViewModelProvider
import at.xaxa.ledger.ui.ButtonSuccess
import at.xaxa.ledger.ui.CategoryCard
import at.xaxa.ledger.ui.HorizontalCard
import at.xaxa.ledger.ui.convertMillisToDate
import at.xaxa.ledger.ui.category.CategoryViewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun addCategory(
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
onCardClick: (Int) -> Unit,
categoryViewModel: CategoryViewModel = viewModel(factory = AppViewModelProvider.Factory)
) {
var name by remember { mutableStateOf("") }
@ -47,9 +47,6 @@ fun addCategory(
.fillMaxSize()
.padding(16.dp, 0.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
LazyColumn(
Modifier.weight(1f)
) {
OutlinedTextField(
value = category.categoryName,
@ -86,7 +83,9 @@ fun addCategory(
}
)
}
LazyColumn(
Modifier.weight(1f)
) {
items(categories) { item ->
Column(
modifier = Modifier.padding(vertical = 4.dp)

View File

@ -0,0 +1,131 @@
package at.xaxa.ledger.ui.category.edit
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults.TrailingIcon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import at.xaxa.ledger.data.Entry
import at.xaxa.ledger.ui.AppViewModelProvider
import at.xaxa.ledger.ui.ButtonDanger
import at.xaxa.ledger.ui.ButtonSuccess
import at.xaxa.ledger.ui.DatePickerDocked
import at.xaxa.ledger.ui.edit.EditViewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EditCategory(modifier: Modifier = Modifier, onCardClick: () -> Unit, editViewModel : EditViewModel = viewModel(factory = AppViewModelProvider.Factory), onValueChange: (Entry) -> Unit = {},
) {
/*
val entry = editViewModel.editUiState.entry
val category = editViewModel.categoryUi.category
val categories by editViewModel.categoryListUiState.categories.collectAsState(initial = emptyList())
var expanded by remember { mutableStateOf(false) }
Column(
modifier = modifier.fillMaxSize()
.padding(16.dp, 0.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Column(
Modifier.weight(1f)
) {
OutlinedTextField(
value = entry.name,
onValueChange = {editViewModel.updateEntry(entry.copy(name = it))},
label = { Text("Name") },
modifier = Modifier
.fillMaxWidth()
)
OutlinedTextField(
value = entry.amount.toString(),
onValueChange = { editViewModel.updateEntry(entry.copy(amount = it.toFloat())) },
label = { Text("Spending") },
modifier = Modifier
.fillMaxWidth()
)
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { expanded = it }
) {
// TextField to display the selected item and trigger the dropdown
OutlinedTextField(
value = category.categoryName,
onValueChange = {},
label = { Text("Category") },
readOnly = true,
trailingIcon = {
TrailingIcon(expanded = expanded)
},
modifier = Modifier
.menuAnchor()
.fillMaxWidth()
)
// Dropdown menu
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
categories.forEach { item ->
DropdownMenuItem(
text = { Text(text = item.categoryName) },
onClick = {
entry.copy(categoryID = item._id)
editViewModel.updateEntry(entry)
expanded = false
}
)
}
}
}
Log.w("xaver", entry.date.toString())
DatePickerDocked(entry){
dateMilis -> editViewModel.updateEntry(entry.copy(date = dateMilis))
}
}
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally // Center buttons horizontally
) {
ButtonDanger(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 8.dp),
text = "Delete",
onClick = { onCardClick() }
)
ButtonSuccess(
modifier = Modifier.fillMaxWidth(), // Add spacing between buttons
text = "Done",
onClick = {
editViewModel.saveEntry()
onCardClick()
}
)
}
}*/
}