Merge remote-tracking branch 'origin/Florian'
This commit is contained in:
commit
67fc41940f
@ -1,6 +1,5 @@
|
|||||||
package at.xaxa.ledger.ui
|
package at.xaxa.ledger.ui
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -13,7 +12,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState
|
|||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
import at.xaxa.ledger.ui.add.Add
|
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.edit.Edit
|
||||||
import at.xaxa.ledger.ui.home.Home
|
import at.xaxa.ledger.ui.home.Home
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ enum class AppRoutes(val route: String) {
|
|||||||
Home("home"),
|
Home("home"),
|
||||||
Add("add"),
|
Add("add"),
|
||||||
Edit("edit/{entryId}"),
|
Edit("edit/{entryId}"),
|
||||||
Category("category")
|
Category("category"),
|
||||||
|
EditCategory("categoryEdit/{categoryId}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@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){
|
composable(AppRoutes.Category.route){
|
||||||
addCategory(
|
addCategory(
|
||||||
onButtonClick = {
|
onButtonClick = {
|
||||||
navController.navigate("home")
|
navController.navigate("home")
|
||||||
|
},
|
||||||
|
onCardClick = {
|
||||||
|
navController.navigate("catEdit/$it")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ fun CategoryCard(modifier: Modifier = Modifier, name: String, icon : Int, onClic
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(16.dp)
|
.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)
|
@Preview(widthDp = 360, heightDp = 80)
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -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.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
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.AppViewModelProvider
|
||||||
import at.xaxa.ledger.ui.ButtonSuccess
|
import at.xaxa.ledger.ui.ButtonSuccess
|
||||||
import at.xaxa.ledger.ui.CategoryCard
|
import at.xaxa.ledger.ui.CategoryCard
|
||||||
import at.xaxa.ledger.ui.HorizontalCard
|
import at.xaxa.ledger.ui.category.CategoryViewModel
|
||||||
import at.xaxa.ledger.ui.convertMillisToDate
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun addCategory(
|
fun addCategory(
|
||||||
onButtonClick: () -> Unit,
|
onButtonClick: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
onCardClick: (Int) -> Unit,
|
||||||
categoryViewModel: CategoryViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
categoryViewModel: CategoryViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||||
) {
|
) {
|
||||||
var name by remember { mutableStateOf("") }
|
var name by remember { mutableStateOf("") }
|
||||||
@ -48,45 +48,44 @@ fun addCategory(
|
|||||||
.padding(16.dp, 0.dp),
|
.padding(16.dp, 0.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = category.categoryName,
|
||||||
|
onValueChange = { name = it },
|
||||||
|
label = { Text("Name") },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = category.icon.toString(),
|
||||||
|
onValueChange = { category.copy(icon = it.toInt()) },
|
||||||
|
label = { Text("Icon") },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
ButtonSuccess(
|
||||||
|
modifier = Modifier,
|
||||||
|
"Add Category",
|
||||||
|
onClick = {
|
||||||
|
if (name.isNotBlank()) {
|
||||||
|
val newCategory = CategoryEntity(
|
||||||
|
_id = 0,
|
||||||
|
categoryName = name,
|
||||||
|
icon = icon
|
||||||
|
)
|
||||||
|
categoryViewModel.addCategory(newCategory)
|
||||||
|
onButtonClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
Modifier.weight(1f)
|
Modifier.weight(1f)
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
|
||||||
value = category.categoryName,
|
|
||||||
onValueChange = { name = it },
|
|
||||||
label = { Text("Name") },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
OutlinedTextField(
|
|
||||||
value = category.icon.toString(),
|
|
||||||
onValueChange = { category.copy(icon = it.toInt()) },
|
|
||||||
label = { Text("Icon") },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
ButtonSuccess(
|
|
||||||
modifier = Modifier,
|
|
||||||
"Add Category",
|
|
||||||
onClick = {
|
|
||||||
if (name.isNotBlank()) {
|
|
||||||
val newCategory = CategoryEntity(
|
|
||||||
_id = 0,
|
|
||||||
categoryName = name,
|
|
||||||
icon = icon
|
|
||||||
)
|
|
||||||
categoryViewModel.addCategory(newCategory)
|
|
||||||
onButtonClick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
items(categories) { item ->
|
items(categories) { item ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(vertical = 4.dp)
|
modifier = Modifier.padding(vertical = 4.dp)
|
@ -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()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user