From fad8dc23b51f28f6a25e36a79a1bb6a3a52979b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manu=20Mu=C3=B1oz?= Date: Thu, 11 Jan 2024 15:41:20 +0100 Subject: [PATCH] fix: [ANDROAPP-5716] responsive filters on events list (#3454) --- .../programEventDetail/eventList/EventListFragment.kt | 7 ++++--- .../filters/workingLists/WorkingListChipGroup.kt | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt index ee7e1d459f..d2151d16de 100644 --- a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt @@ -36,6 +36,7 @@ class EventListFragment : FragmentGlobalAbstract(), EventListFragmentView { lateinit var binding: FragmentProgramEventDetailListBinding private var liveAdapter: ProgramEventDetailLiveAdapter? = null private val programEventsViewModel: ProgramEventDetailViewModel by activityViewModels() + private var liveDataList: LiveData>? = null @Inject lateinit var presenter: EventListPresenter @@ -97,9 +98,9 @@ class EventListFragment : FragmentGlobalAbstract(), EventListFragmentView { } override fun setLiveData(pagedListLiveData: LiveData>) { - pagedListLiveData.observe( - this, - ) { pagedList: PagedList -> + liveDataList?.removeObservers(viewLifecycleOwner) + this.liveDataList = pagedListLiveData + liveDataList?.observe(viewLifecycleOwner) { pagedList: PagedList -> programEventsViewModel.setProgress(false) liveAdapter?.submitList(pagedList) { if ((binding.recycler.adapter?.itemCount ?: 0) == 0) { diff --git a/commons/src/main/java/org/dhis2/commons/filters/workingLists/WorkingListChipGroup.kt b/commons/src/main/java/org/dhis2/commons/filters/workingLists/WorkingListChipGroup.kt index 176adc638f..ae17255d2b 100644 --- a/commons/src/main/java/org/dhis2/commons/filters/workingLists/WorkingListChipGroup.kt +++ b/commons/src/main/java/org/dhis2/commons/filters/workingLists/WorkingListChipGroup.kt @@ -84,6 +84,13 @@ fun WorkingListChipGroup( FilterManager.getInstance().currentWorkingList(), ) } + FilterManager.getInstance().observeWorkingListScope().addOnPropertyChangedCallback( + object : Observable.OnPropertyChangedCallback() { + override fun onPropertyChanged(sender: Observable?, propertyId: Int) { + selectedWorkingList = FilterManager.getInstance().currentWorkingList() + } + }, + ) workingListFilterState.value?.let { workingListFilter -> LazyRow(modifier) { @@ -98,10 +105,9 @@ fun WorkingListChipGroup( }, ), label = workingList.label, - selected = selectedWorkingList == workingList, + selected = selectedWorkingList?.uid == workingList.uid, onSelected = { _ -> workingListFilter.onChecked(workingList.id()) - selectedWorkingList = FilterManager.getInstance().currentWorkingList() }, ) }