Skip to content

Commit

Permalink
Fix bug where not all budgets are shown in budget listing
Browse files Browse the repository at this point in the history
  • Loading branch information
emansih committed Jan 8, 2022
1 parent e52813e commit 8e59e19
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package xyz.hisname.fireflyiii.repository.models.budget

data class IndividualBudget(
val sourceBudgetId: Long,
val budgetName: String,
val listOfChildIndividualBudget: List<ChildIndividualBudget>
)
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ class AddBudgetFragment: BaseAddObjectFragment() {
dialog.findViewById<TextView>(android.R.id.message)?.movementMethod = LinkMovementMethod.getInstance()
}
}
if(budgetId != 0L){
if(budgetId != 0L && currencySymbol.isNotBlank()){
updateBudgetUi()
}
if(currencySymbol.isEmpty()){
updateBudgetUiWithoutCurrency()
}
}

private fun updateBudgetUiWithoutCurrency(){
addBudgetViewModel.getBudgetByIdWithoutSymbol(budgetId).observe(viewLifecycleOwner){ budget ->
binding.budgetNameEditText.setText(budget.budgetListAttributes.name)
}
}

private fun updateBudgetUi(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ class AddBudgetViewModel(application: Application): BaseViewModel(application) {
return budgetAttributesLiveData
}

fun getBudgetByIdWithoutSymbol(budgetId: Long): LiveData<BudgetListData>{
val budgetAttributesLiveData = MutableLiveData<BudgetListData>()
viewModelScope.launch(Dispatchers.IO){
val budgetListData = budgetRepository.getBudgetListIdById(budgetId)
budgetAttributesLiveData.postValue(budgetListData)
}
return budgetAttributesLiveData
}

private fun checkVersion(){
if(!AppPref(sharedPref()).budgetIssue4394){
val systemInfoRepository = SystemInfoRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import xyz.hisname.fireflyiii.R
import xyz.hisname.fireflyiii.databinding.BaseSwipeLayoutBinding
import xyz.hisname.fireflyiii.databinding.BudgetListItemBinding
import xyz.hisname.fireflyiii.databinding.FragmentBudgetListBinding
import xyz.hisname.fireflyiii.repository.models.budget.ChildIndividualBudget
import xyz.hisname.fireflyiii.ui.base.BaseFragment
import xyz.hisname.fireflyiii.util.extension.*
import xyz.hisname.fireflyiii.util.extension.getImprovedViewModel
Expand Down Expand Up @@ -158,11 +159,18 @@ class BudgetListFragment: BaseFragment(){
private fun setRecyclerView(){
baseSwipeBinding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
budgetListViewModel.individualBudget.observe(viewLifecycleOwner){ budgetData ->
val budgetRecyclerAdapter = BudgetRecyclerAdapter(budgetData){ cid ->
val budgetRecyclerAdapter = BudgetRecyclerAdapter(budgetData, { child: ChildIndividualBudget ->
parentFragmentManager.commit {
replace(R.id.bigger_fragment_container, AddBudgetFragment().apply {
arguments = bundleOf("budgetId" to cid.budgetLimitId,
"currencySymbol" to cid.currencySymbol)
arguments = bundleOf("budgetId" to child.budgetLimitId,
"currencySymbol" to child.currencySymbol)
})
addToBackStack(null)
}
}){ adult: Long ->
parentFragmentManager.commit {
replace(R.id.bigger_fragment_container, AddBudgetFragment().apply {
arguments = bundleOf("budgetId" to adult)
})
addToBackStack(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ class BudgetListViewModel(application: Application): BaseViewModel(application)
childBudgetList.add(ChildIndividualBudget(budgetListId, spentAmount, userBudgetAmount, uniqueSymbol))
}
}
if(childBudgetList.isNotEmpty()){
individualBudgetList.add(IndividualBudget(budgetName, childBudgetList))
}
individualBudgetList.add(IndividualBudget(budgetId, budgetName, childBudgetList))
}
individualBudget.postValue(individualBudgetList)
isLoading.postValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package xyz.hisname.fireflyiii.ui.budget

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -28,7 +29,8 @@ import xyz.hisname.fireflyiii.repository.models.budget.ChildIndividualBudget
import xyz.hisname.fireflyiii.repository.models.budget.IndividualBudget

class BudgetRecyclerAdapter(private val budgetData: List<IndividualBudget>,
private val clickListener:(ChildIndividualBudget) -> Unit):
private val clickListener:(ChildIndividualBudget) -> Unit,
private val emptyChildListener: (Long) -> Unit):
RecyclerView.Adapter<BudgetRecyclerAdapter.BudgetHolder>() {

private var budgetListItemBinding: BudgetListItemBinding? = null
Expand All @@ -51,6 +53,12 @@ class BudgetRecyclerAdapter(private val budgetData: List<IndividualBudget>,
if(budgetData[position].listOfChildIndividualBudget.size > 1){
childRecyclerView.addItemDecoration(DividerItemDecoration(childRecyclerView.context, DividerItemDecoration.VERTICAL))
}

if(budgetData[position].listOfChildIndividualBudget.isEmpty()){
binding.headerIndicator.isGone = true
binding.budgetItemList.setOnClickListener { emptyChildListener(budgetData[position].sourceBudgetId) }
}

childRecyclerView.layoutManager = layoutManager
childRecyclerView.adapter = childItemAdapter
}
Expand Down

0 comments on commit 8e59e19

Please sign in to comment.