Skip to content

Commit

Permalink
Updating transactions when deleting through budget details screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuppan committed Nov 19, 2023
1 parent 4402a44 commit 064ba7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
Expand Down Expand Up @@ -135,8 +133,8 @@ fun BudgetDetailScreen(
textAlign = TextAlign.Center
)
} else {
LazyColumn(modifier = Modifier.padding(top = 16.dp)) {
items(transactions) { item ->
Column(modifier = Modifier.padding(top = 16.dp)) {
transactions.forEach { item ->
TransactionItem(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -159,13 +157,11 @@ fun BudgetDetailScreen(
toAccountColor = item.toAccountColor,
)
}
item {
Spacer(
modifier = Modifier
.fillMaxWidth()
.padding(36.dp)
)
}
Spacer(
modifier = Modifier
.fillMaxWidth()
.padding(36.dp)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.naveenapps.expensemanager.core.domain.usecase.budget.BudgetUiModel
import com.naveenapps.expensemanager.core.domain.usecase.budget.GetBudgetDetailUseCase
import com.naveenapps.expensemanager.core.domain.usecase.transaction.GetTransactionWithFilterUseCase
import com.naveenapps.expensemanager.core.model.Resource
import com.naveenapps.expensemanager.core.navigation.AppComposeNavigator
import com.naveenapps.expensemanager.core.navigation.ExpenseManagerScreens
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class BudgetDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val getBudgetDetailUseCase: GetBudgetDetailUseCase,
getTransactionWithFilterUseCase: GetTransactionWithFilterUseCase,
private val appComposeNavigator: AppComposeNavigator
) : ViewModel() {

Expand All @@ -26,6 +30,10 @@ class BudgetDetailViewModel @Inject constructor(

init {
loadBudget(savedStateHandle.get<String>(ExpenseManagerScreens.BudgetDetails.KEY_BUDGET_ID))

getTransactionWithFilterUseCase.invoke().onEach {
loadBudget(savedStateHandle.get<String>(ExpenseManagerScreens.BudgetDetails.KEY_BUDGET_ID))
}.launchIn(viewModelScope)
}

private fun loadBudget(budgetId: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
Expand Down Expand Up @@ -134,6 +136,9 @@ private fun TransactionListScreen(
it, onItemClick
)
}
item {
Spacer(modifier = Modifier.height(64.dp))
}
}
}
}
Expand Down

0 comments on commit 064ba7c

Please sign in to comment.