Skip to content

Commit

Permalink
fix: [ANDROAPP-6047] crash when updating dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Apr 29, 2024
1 parent 478b159 commit e22f516
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DashboardViewModel(

private val eventUid = MutableLiveData<String>()

val updateEnrollment = MutableLiveData(false)
val showStatusErrorMessages = MutableLiveData(StatusChangeResultCode.CHANGED)

private var _showFollowUpBar = MutableStateFlow(false)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -387,7 +384,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
programStageUid,
),
)
presenter.fetchEvents(true)
presenter.fetchEvents()
},
).show(parentFragmentManager, SCHEDULING_DIALOG)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class DashboardViewModelTest {
assertTrue(showStatusBar.value == EnrollmentStatus.COMPLETED)
assertTrue(syncNeeded.value)
assertTrue(state.value == State.TO_UPDATE)
assertTrue(updateEnrollment.value == true)
}
}

Expand Down

0 comments on commit e22f516

Please sign in to comment.