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() }, ) }