category strucutre
This commit is contained in:
parent
d6ff6de339
commit
cbe06735b1
@ -5,8 +5,9 @@ import androidx.lifecycle.createSavedStateHandle
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import at.xaxa.ledger.LedgerApplication
|
||||
import at.xaxa.ledger.ui.category.overview.OverviewCategoryViewModel
|
||||
import at.xaxa.ledger.ui.category.add.AddCategoryViewModel
|
||||
import at.xaxa.ledger.ui.entry.add.AddViewModel
|
||||
import at.xaxa.ledger.ui.category.CategoryViewModel
|
||||
import at.xaxa.ledger.ui.category.edit.EditCategoryViewModel
|
||||
import at.xaxa.ledger.ui.entry.edit.EditViewModel
|
||||
import at.xaxa.ledger.ui.home.HomeViewModel
|
||||
@ -26,10 +27,13 @@ object AppViewModelProvider {
|
||||
EditViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
|
||||
}
|
||||
initializer {
|
||||
CategoryViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
|
||||
OverviewCategoryViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
|
||||
}
|
||||
initializer {
|
||||
EditCategoryViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
|
||||
}
|
||||
initializer {
|
||||
AddCategoryViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import at.xaxa.ledger.ui.entry.add.Add
|
||||
import at.xaxa.ledger.ui.category.CategoryOverview
|
||||
import at.xaxa.ledger.ui.category.overview.CategoryOverview
|
||||
import at.xaxa.ledger.ui.category.add.AddCategory
|
||||
import at.xaxa.ledger.ui.category.edit.EditCategory
|
||||
import at.xaxa.ledger.ui.entry.edit.Edit
|
||||
|
@ -1,31 +1,10 @@
|
||||
package at.xaxa.ledger.ui.category.add
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
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.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AccountBox
|
||||
import androidx.compose.material.icons.filled.ArrowForward
|
||||
import androidx.compose.material.icons.filled.Build
|
||||
import androidx.compose.material.icons.filled.Call
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Favorite
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.LocationOn
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.Notifications
|
||||
import androidx.compose.material.icons.filled.Share
|
||||
import androidx.compose.material.icons.filled.ShoppingCart
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||
@ -34,7 +13,6 @@ import androidx.compose.material3.Icon
|
||||
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
|
||||
@ -46,7 +24,6 @@ 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.category.CategoryViewModel
|
||||
import at.xaxa.ledger.ui.category.iconNames
|
||||
import at.xaxa.ledger.ui.category.icons
|
||||
|
||||
@ -56,18 +33,13 @@ import at.xaxa.ledger.ui.category.icons
|
||||
fun AddCategory(
|
||||
onButtonClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
categoryViewModel: CategoryViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
categoryViewModel: AddCategoryViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
|
||||
var name by remember { mutableStateOf("") }
|
||||
var selectedIconIndex by remember { mutableStateOf(0) } // Store index of selected icon
|
||||
var expanded by remember { mutableStateOf(false) } // Controls dropdown visibility
|
||||
|
||||
/*
|
||||
val categories by categoryViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
||||
val category = categoryViewModel.categoryUi.category
|
||||
var expanded by remember { mutableStateOf(false) }*/
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
|
@ -1,4 +1,4 @@
|
||||
package at.xaxa.ledger.ui.category
|
||||
package at.xaxa.ledger.ui.category.add
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -6,12 +6,10 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import at.xaxa.ledger.data.Entry
|
||||
import at.xaxa.ledger.data.EntryRepository
|
||||
import at.xaxa.ledger.data.db.Category.CategoryEntity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@ -20,7 +18,7 @@ data class CategoryUIState(val category: CategoryEntity = CategoryEntity(0,"",0)
|
||||
data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList()))
|
||||
|
||||
|
||||
class CategoryViewModel(
|
||||
class AddCategoryViewModel(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
private val repository: EntryRepository
|
||||
) : ViewModel() {
|
||||
@ -29,7 +27,7 @@ class CategoryViewModel(
|
||||
private set
|
||||
|
||||
init {
|
||||
getAllCategories()
|
||||
//getAllCategories()
|
||||
}
|
||||
|
||||
fun addCategory(category: CategoryEntity) {
|
||||
@ -49,23 +47,4 @@ class CategoryViewModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllCategories() {
|
||||
viewModelScope.launch {
|
||||
val categories = withContext(Dispatchers.IO) {
|
||||
repository.getAllCategories()
|
||||
}
|
||||
categoryUiState = CategoryListUIState(categories)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun findCategoryByID(categoryId: Int) {
|
||||
viewModelScope.launch {
|
||||
val category = withContext(Dispatchers.IO) {
|
||||
repository.findCategoryById(categoryId)
|
||||
}
|
||||
categoryUi = CategoryUIState(category)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package at.xaxa.ledger.ui.category
|
||||
package at.xaxa.ledger.ui.category.overview
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
@ -1,4 +1,4 @@
|
||||
package at.xaxa.ledger.ui.category
|
||||
package at.xaxa.ledger.ui.category.overview
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
Loading…
Reference in New Issue
Block a user