From e22f51613cd70e2c63db3a44aeb277ea000c985f Mon Sep 17 00:00:00 2001 From: manu Date: Mon, 29 Apr 2024 12:37:29 +0200 Subject: [PATCH] fix: [ANDROAPP-6047] crash when updating dashboard --- .../teiDashboard/DashboardViewModel.kt | 3 +-- .../teidata/TEIDataContracts.kt | 1 - .../teidata/TEIDataFragment.kt | 18 ++++-------------- .../teidata/TEIDataPresenter.kt | 8 +++----- .../teiDashboard/DashboardViewModelTest.kt | 1 - 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt index 22649f3b1d..7523decc33 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt @@ -27,7 +27,6 @@ class DashboardViewModel( private val eventUid = MutableLiveData() - val updateEnrollment = MutableLiveData(false) val showStatusErrorMessages = MutableLiveData(StatusChangeResultCode.CHANGED) private var _showFollowUpBar = MutableStateFlow(false) @@ -141,7 +140,7 @@ class DashboardViewModel( _showStatusBar.value = status _syncNeeded.value = true _state.value = State.TO_UPDATE - updateEnrollment.postValue(true) + fetchDashboardModel() } else { showStatusErrorMessages.postValue(result) } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt index 27893cf19d..7928e18686 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt @@ -35,7 +35,6 @@ class TEIDataContracts { fun showProgramRuleErrorMessage() fun goToEventInitial(eventCreationType: EventCreationType, programStage: ProgramStage) - fun updateEnrollment(update: Boolean) fun displayOrgUnitSelectorForNewEvent(programUid: String, programStageUid: String) fun goToEventDetails( diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index 49daa770b8..102d1c164b 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -134,9 +134,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { with(dashboardViewModel) { eventUid().observe(viewLifecycleOwner, ::displayGenerateEvent) - updateEnrollment.observe(viewLifecycleOwner) { update -> - updateEnrollment(update) - } noEnrollmentSelected.observe(viewLifecycleOwner) { noEnrollmentSelected -> if (noEnrollmentSelected) { showAllEnrollment = true @@ -387,7 +384,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { programStageUid, ), ) - presenter.fetchEvents(true) + presenter.fetchEvents() }, ).show(parentFragmentManager, SCHEDULING_DIALOG) } @@ -469,17 +466,17 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { override fun openEventDetails(intent: Intent, options: ActivityOptionsCompat) = contractHandler.scheduleEvent(intent, options).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun openEventInitial(intent: Intent) = contractHandler.editEvent(intent).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun openEventCapture(intent: Intent) = contractHandler.editEvent(intent).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun goToEventInitial( @@ -576,13 +573,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { } } - override fun updateEnrollment(update: Boolean) { - if (update) { - presenter.fetchEvents(update) - dashboardViewModel.updateDashboard() - } - } - companion object { const val RC_EVENTS_COMPLETED = 1601 const val PREF_COMPLETED_EVENT = "COMPLETED_EVENT" diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt index 7216e851ba..84dd97073a 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt @@ -285,7 +285,7 @@ class TEIDataPresenter( val intent = Intent(view.context, ProgramStageSelectionActivity::class.java) intent.putExtras(bundle) contractHandler.createEvent(intent).observe(view.viewLifecycleOwner()) { - view.updateEnrollment(true) + fetchEvents() } } @@ -395,10 +395,8 @@ class TEIDataPresenter( return options?.let { eventCreationOptionsMapper.mapToEventsByStage(it) } ?: emptyList() } - fun fetchEvents(updateEnrollment: Boolean) { - if (updateEnrollment) { - groupingProcessor.onNext(dashboardRepository.getGrouping()) - } + fun fetchEvents() { + groupingProcessor.onNext(dashboardRepository.getGrouping()) } fun getEnrollment(): Enrollment? { diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt index c40aef0da8..a10a2c3531 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt @@ -126,7 +126,6 @@ class DashboardViewModelTest { assertTrue(showStatusBar.value == EnrollmentStatus.COMPLETED) assertTrue(syncNeeded.value) assertTrue(state.value == State.TO_UPDATE) - assertTrue(updateEnrollment.value == true) } }