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) {