Only show relevant expense/income categories for transaction editing/creation
This commit is contained in:
parent
511cb5a376
commit
773b514e42
2 changed files with 17 additions and 7 deletions
|
@ -55,15 +55,20 @@ class TransactionFormActivity : AppCompatActivity(), CoroutineScope {
|
|||
android.R.layout.simple_list_item_1,
|
||||
accounts
|
||||
)
|
||||
|
||||
container_edit_transaction_type.setOnCheckedChangeListener { _, _ ->
|
||||
this@TransactionFormActivity.launch {
|
||||
val budget = budgetSpinner.selectedItem as Budget
|
||||
setCategories(viewModel.getCategories(budget.id!!, edit_transaction_type_expense.isChecked))
|
||||
}
|
||||
}
|
||||
budgetSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
this@TransactionFormActivity.launch {
|
||||
val account = budgetSpinner.selectedItem as Budget
|
||||
setCategories(viewModel.getCategories(account.id!!))
|
||||
val budget = budgetSpinner.selectedItem as Budget
|
||||
setCategories(viewModel.getCategories(budget.id!!, edit_transaction_type_expense.isChecked))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,16 @@ import com.wbrawner.budget.common.transaction.TransactionRepository
|
|||
import javax.inject.Inject
|
||||
|
||||
class TransactionFormViewModel : ViewModel() {
|
||||
@Inject lateinit var budgetRepository: BudgetRepository
|
||||
@Inject lateinit var categoryRepository: CategoryRepository
|
||||
@Inject lateinit var transactionRepository: TransactionRepository
|
||||
@Inject
|
||||
lateinit var budgetRepository: BudgetRepository
|
||||
@Inject
|
||||
lateinit var categoryRepository: CategoryRepository
|
||||
@Inject
|
||||
lateinit var transactionRepository: TransactionRepository
|
||||
|
||||
suspend fun getCategories(budgetId: Long) = categoryRepository.findAll(arrayOf(budgetId))
|
||||
suspend fun getCategories(budgetId: Long, expense: Boolean) = categoryRepository.findAll(arrayOf(budgetId)).filter {
|
||||
it.expense == expense
|
||||
}
|
||||
|
||||
suspend fun getTransaction(id: Long) = transactionRepository.findById(id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue