CategoryUI updated
This commit is contained in:
parent
b32cfe1844
commit
adcd8bb3a0
@ -141,6 +141,27 @@ fun HorizontalCard(modifier: Modifier = Modifier, name: String, date: String, am
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CategoryCard(modifier: Modifier = Modifier, name: String, icon : Int, onClick: () -> Unit ) {
|
||||
Surface(
|
||||
onClick = onClick,
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
color = Color(0xfff9f9f9),
|
||||
border = BorderStroke(1.dp, Color(0xffc6c6c6)),
|
||||
modifier = modifier
|
||||
.clip(shape = RoundedCornerShape(12.dp))
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(16.dp)
|
||||
) {
|
||||
LayoutMediaText(modifier, name, date, amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun LayoutMediaText(modifier: Modifier = Modifier, name: String, date: String, amount:String) {
|
||||
Row(
|
||||
|
@ -5,6 +5,8 @@ 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.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
@ -21,6 +23,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
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
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@ -33,7 +38,7 @@ fun addCategory(
|
||||
var icon by remember { mutableStateOf(0) }
|
||||
|
||||
val categories by categoryViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
||||
|
||||
val category = categoryViewModel.categoryUi.category
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
|
||||
@ -43,25 +48,23 @@ fun addCategory(
|
||||
.padding(16.dp, 0.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Column(
|
||||
LazyColumn(
|
||||
Modifier.weight(1f)
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
value = category.categoryName,
|
||||
onValueChange = { name = it },
|
||||
label = { Text("Name") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = icon.toString(),
|
||||
onValueChange = { icon = it.toInt() },
|
||||
value = category.icon.toString(),
|
||||
onValueChange = { category.copy(icon = it.toInt()) },
|
||||
label = { Text("Icon") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
)
|
||||
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
@ -83,6 +86,19 @@ fun addCategory(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
items(categories) { item ->
|
||||
Column(
|
||||
modifier = Modifier.padding(vertical = 4.dp)
|
||||
) {
|
||||
CategoryCard(
|
||||
modifier = modifier,
|
||||
name = category.categoryName,
|
||||
icon = category.icon,
|
||||
onClick = { onCardClick(category._id) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
data class CategoryUIState(val category: CategoryEntity = CategoryEntity(0,"",0))
|
||||
data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList()))
|
||||
|
||||
|
||||
@ -25,6 +25,8 @@ class CategoryViewModel(
|
||||
private val repository: EntryRepository
|
||||
) : ViewModel() {
|
||||
var categoryUiState by mutableStateOf(CategoryListUIState())
|
||||
var categoryUi by mutableStateOf(CategoryUIState())
|
||||
private set
|
||||
|
||||
init {
|
||||
getAllCategories()
|
||||
@ -56,6 +58,14 @@ class CategoryViewModel(
|
||||
categoryUiState = CategoryListUIState(categories)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun findCategoryByID(categoryId: Int) {
|
||||
viewModelScope.launch {
|
||||
val category = withContext(Dispatchers.IO) {
|
||||
repository.findCategoryById(categoryId)
|
||||
}
|
||||
categoryUi = CategoryUIState(category)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user