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 cbb5eb6baf..95f5d7daf5 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 @@ -25,7 +25,6 @@ import org.dhis2.bindings.app import org.dhis2.commons.Constants import org.dhis2.commons.data.EventCreationType import org.dhis2.commons.data.EventViewModel -import org.dhis2.commons.data.EventViewModelType import org.dhis2.commons.data.StageSection import org.dhis2.commons.dialogs.CustomDialog import org.dhis2.commons.dialogs.DialogClickListener @@ -217,14 +216,16 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { ) } - if (sharedPreferences.getString(PREF_COMPLETED_EVENT, null) != null) { - presenter.displayGenerateEvent( - sharedPreferences.getString( - PREF_COMPLETED_EVENT, - null, - ), - ) - sharedPreferences.edit().remove(PREF_COMPLETED_EVENT).apply() + dashboardViewModel.dashboardModel.observe(viewLifecycleOwner) { + if (sharedPreferences.getString(PREF_COMPLETED_EVENT, null) != null) { + presenter.displayGenerateEvent( + sharedPreferences.getString( + PREF_COMPLETED_EVENT, + null, + ), + ) + sharedPreferences.edit().remove(PREF_COMPLETED_EVENT).apply() + } } }.root } @@ -318,10 +319,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { if (model is DashboardEnrollmentModel) { SchedulingDialog( enrollment = model.currentEnrollment, - programStages = eventAdapter?.currentList - ?.filter { it.type == EventViewModelType.STAGE && it.canAddNewEvent } - ?.mapNotNull { it.stage } - ?: emptyList(), + programStages = presenter.filterAvailableStages(model.programStages), onScheduled = { programStageUid -> showToast( resourceManager.formatWithEventLabel( @@ -331,7 +329,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { ) presenter.fetchEvents(true) }, - ).show(childFragmentManager, SCHEDULING_DIALOG) + ).show(parentFragmentManager, SCHEDULING_DIALOG) } } 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 4327fb1d80..1c90e4157a 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 @@ -101,7 +101,8 @@ class TEIDataPresenter( compositeDisposable.add( Flowable.combineLatest>( sectionFlowable, - groupingFlowable, ::Pair, + groupingFlowable, + ::Pair, ) .doOnNext { increment() } .switchMap { stageAndGrouping -> @@ -429,4 +430,10 @@ class TEIDataPresenter( fun getEnrollment(): Enrollment? { return teiDataRepository.getEnrollment().blockingGet() } + + fun filterAvailableStages(programStages: List): List = + programStages + .filter { it.repeatable() == true } + .filter { it.access().data().write() } + .filter { !stagesToHide.contains(it.uid()) } }