From 070744ebfbb8092691df8ecd56ac20302474f4a0 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Thu, 11 Jan 2024 17:08:32 +0530 Subject: [PATCH 1/6] show confirmation dialog show confirmation dialog before deleting TEI or removing enrolments --- .../TeiDashboardMobileActivity.kt | 39 ++++++++++++++++++- app/src/main/res/values/strings.xml | 4 ++ .../dialogs/bottomsheet/DialogButtonStyle.kt | 6 +++ ui-components/src/main/res/values/strings.xml | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index b6ddd5bcde..1d29a0b5b6 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -33,6 +33,9 @@ import org.dhis2.commons.sync.OnDismissListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityDashboardMobileBinding import org.dhis2.ui.ThemeManager +import org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialog +import org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialogUiModel +import org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle import org.dhis2.usescases.enrollment.EnrollmentActivity import org.dhis2.usescases.enrollment.EnrollmentActivity.Companion.getIntent import org.dhis2.usescases.general.ActivityGlobalAbstract @@ -133,6 +136,7 @@ class TeiDashboardMobileActivity : } } } + override fun onCreate(savedInstanceState: Bundle?) { if (savedInstanceState != null && savedInstanceState.containsKey(Constants.TRACKED_ENTITY_INSTANCE)) { teiUid = savedInstanceState.getString(Constants.TRACKED_ENTITY_INSTANCE) @@ -586,9 +590,10 @@ class TeiDashboardMobileActivity : analyticsHelper.setEvent(SHOW_HELP, CLICK, SHOW_HELP) showTutorial(true) } + R.id.markForFollowUp -> dashboardViewModel.onFollowUp(programModel) - R.id.deleteTei -> presenter.deleteTei() - R.id.deleteEnrollment -> presenter.deleteEnrollment() + R.id.deleteTei -> showDeleteTEIConfirmationDialog() + R.id.deleteEnrollment -> showRemoveEnrollmentConfirmationDialog() R.id.programSelector -> presenter.onEnrollmentSelectorClick() R.id.groupEvents -> groupByStage?.setValue(true) R.id.showTimeline -> groupByStage?.setValue(false) @@ -654,6 +659,36 @@ class TeiDashboardMobileActivity : } } + private fun showDeleteTEIConfirmationDialog() { + BottomSheetDialog( + bottomSheetDialogUiModel = BottomSheetDialogUiModel( + title = getString(R.string.delete_tei_dialog_title).format(presenter.teType), + message = getString(R.string.delete_tei_dialog_message).format(presenter.teType), + iconResource = R.drawable.ic_error_outline, + mainButton = DialogButtonStyle.RemoveButton(), + secondaryButton = DialogButtonStyle.NeutralButton(R.string.cancel), + ), + onMainButtonClicked = { + presenter.deleteTei() + }, + ).show(supportFragmentManager, BottomSheetDialogUiModel::class.java.simpleName) + } + + private fun showRemoveEnrollmentConfirmationDialog() { + BottomSheetDialog( + bottomSheetDialogUiModel = BottomSheetDialogUiModel( + title = getString(R.string.remove_enrollment_dialog_title).format(programModel.currentProgram.displayName()), + message = getString(R.string.remove_enrollment_dialog_message).format(programModel.currentProgram.displayName()), + iconResource = R.drawable.ic_error_outline, + mainButton = DialogButtonStyle.RemoveButton(), + secondaryButton = DialogButtonStyle.NeutralButton(R.string.cancel), + ), + onMainButtonClicked = { + presenter.deleteEnrollment() + }, + ).show(supportFragmentManager, BottomSheetDialogUiModel::class.java.simpleName) + } + override fun onRelationshipMapLoaded() { binding.toolbarProgress.hide() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a6240e2fb7..1fd729cee1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -975,4 +975,8 @@ Remove Coordinates You don’t have access to data.\nContact your administrator. + Delete this %s? + This %s and all its data across all programs will be deleted. This action cannot be undone. + Remove from %s? + Data from %s will de deleted. This action cannot be undone. diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt index 36f85fe461..5103f1daaa 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt @@ -3,6 +3,7 @@ package org.dhis2.ui.dialogs.bottomsheet import androidx.compose.ui.graphics.Color import org.dhis2.ui.R import org.dhis2.ui.theme.colorPrimary +import org.dhis2.ui.theme.errorColor import org.dhis2.ui.theme.warningColor sealed class DialogButtonStyle( @@ -42,6 +43,11 @@ sealed class DialogButtonStyle( colorResource = warningColor, ) + class RemoveButton : DialogButtonStyle( + textResource = R.string.remove, + colorResource = errorColor, + ) + class NeutralButton(override val textResource: Int) : DialogButtonStyle( textResource = textResource, colorResource = colorPrimary, diff --git a/ui-components/src/main/res/values/strings.xml b/ui-components/src/main/res/values/strings.xml index d799973f57..ddaec08482 100644 --- a/ui-components/src/main/res/values/strings.xml +++ b/ui-components/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ Keep editing Review Cancel + Remove Save Clear Draw here From d0e7cf5fe56361d4676c463f4a37bbbf4fac20b6 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 5 Feb 2024 14:20:50 +0530 Subject: [PATCH 2/6] show/hide menu items Show TEI Dashboard menu items based on correspondent authorities --- .../teiDashboard/DashboardRepository.kt | 8 +- .../teiDashboard/DashboardRepositoryImpl.kt | 94 +++++++++---------- .../teiDashboard/TeiDashboardContracts.java | 4 + .../TeiDashboardMobileActivity.kt | 14 ++- .../teiDashboard/TeiDashboardPresenter.java | 19 ++-- .../teiDashboard/TeiDashboardPresenterTest.kt | 8 +- 6 files changed, 82 insertions(+), 65 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepository.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepository.kt index f889920e6d..8668e16fe9 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepository.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepository.kt @@ -74,9 +74,13 @@ interface DashboardRepository { fun saveCatOption(eventUid: String?, catOptionComboUid: String?) - fun deleteTeiIfPossible(): Single + fun checkIfDeleteTeiIsPossible(): Boolean - fun deleteEnrollmentIfPossible(enrollmentUid: String): Single + fun deleteTei(): Single + + fun checkIfDeleteEnrollmentIsPossible(enrollmentUid: String): Boolean + + fun deleteEnrollment(enrollmentUid: String): Single fun getNoteCount(): Single diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt index 30ea10c103..f96dd2b5b5 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt @@ -7,7 +7,6 @@ import io.reactivex.Single import io.reactivex.functions.Function import org.dhis2.commons.data.tuples.Pair import org.dhis2.commons.resources.ResourceManager -import org.dhis2.utils.AuthorityException import org.dhis2.utils.DateUtils import org.dhis2.utils.ValueUtils import org.hisp.dhis.android.core.D2 @@ -386,58 +385,53 @@ class DashboardRepositoryImpl( } } - override fun deleteTeiIfPossible(): Single { - return Single.fromCallable { - val local = d2.trackedEntityModule() - .trackedEntityInstances() - .uid(teiUid) - .blockingGet() - ?.state() == State.TO_POST - val hasAuthority = d2.userModule() - .authorities() - .byName().eq("F_TEI_CASCADE_DELETE") - .one().blockingExists() - local || hasAuthority - }.flatMap { canDelete: Boolean -> - if (canDelete) { - return@flatMap d2.trackedEntityModule() - .trackedEntityInstances() - .uid(teiUid) - .delete() - .andThen(Single.fromCallable { true }) - } else { - return@flatMap Single.fromCallable { false } - } - } + override fun checkIfDeleteTeiIsPossible(): Boolean { + val local = d2.trackedEntityModule() + .trackedEntityInstances() + .uid(teiUid) + .blockingGet() + ?.state() == State.TO_POST + val hasAuthority = d2.userModule() + .authorities() + .byName().eq("F_TEI_CASCADE_DELETE") + .one().blockingExists() + + return local || hasAuthority + } + + override fun deleteTei(): Single { + return d2.trackedEntityModule() + .trackedEntityInstances() + .uid(teiUid) + .delete() + .andThen(Single.fromCallable { true }) } - override fun deleteEnrollmentIfPossible(enrollmentUid: String): Single { + override fun checkIfDeleteEnrollmentIsPossible(enrollmentUid: String): Boolean { + val local = d2.enrollmentModule() + .enrollments() + .uid(enrollmentUid) + .blockingGet()!!.state() == State.TO_POST + val hasAuthority = d2.userModule() + .authorities() + .byName().eq("F_ENROLLMENT_CASCADE_DELETE") + .one().blockingExists() + + return local || hasAuthority + } + + override fun deleteEnrollment(enrollmentUid: String): Single { return Single.fromCallable { - val local = d2.enrollmentModule() - .enrollments() - .uid(enrollmentUid) - .blockingGet()!!.state() == State.TO_POST - val hasAuthority = d2.userModule() - .authorities() - .byName().eq("F_ENROLLMENT_CASCADE_DELETE") - .one().blockingExists() - local || hasAuthority - }.flatMap { canDelete: Boolean -> - if (canDelete) { - return@flatMap Single.fromCallable { - val enrollmentObjectRepository = d2.enrollmentModule() - .enrollments().uid(enrollmentUid) - enrollmentObjectRepository.setStatus( - enrollmentObjectRepository.blockingGet()!!.status()!!, - ) - enrollmentObjectRepository.blockingDelete() - d2.enrollmentModule().enrollments().byTrackedEntityInstance().eq(teiUid) - .byDeleted().isFalse - .byStatus().eq(EnrollmentStatus.ACTIVE).blockingGet().isNotEmpty() - } - } else { - return@flatMap Single.error(AuthorityException(null)) - } + val enrollmentObjectRepository = + d2.enrollmentModule() + .enrollments().uid(enrollmentUid) + enrollmentObjectRepository.setStatus( + enrollmentObjectRepository.blockingGet()!!.status()!! + ) + enrollmentObjectRepository.blockingDelete() + !d2.enrollmentModule().enrollments().byTrackedEntityInstance().eq(teiUid) + .byDeleted().isFalse + .byStatus().eq(EnrollmentStatus.ACTIVE).blockingGet().isEmpty() } } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java index fe971a8eb5..2d6fd31544 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardContracts.java @@ -74,5 +74,9 @@ public interface Presenter { void trackDashboardRelationships(); void trackDashboardNotes(); + + Boolean checkIfTEICanBeDeleted(); + + Boolean checkIfEnrollmentCanBeDeleted(String enrollmentUid); } } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index 1d29a0b5b6..e0bdc4c384 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -567,8 +567,18 @@ class TeiDashboardMobileActivity : .menu(this, menu) .onMenuInflated { popupMenu: PopupMenu -> val deleteTeiItem = popupMenu.menu.findItem(R.id.deleteTei) - deleteTeiItem.title = - String.format(deleteTeiItem.title.toString(), presenter.teType) + val showDeleteTeiItem = presenter.checkIfTEICanBeDeleted() + if (showDeleteTeiItem) { + deleteTeiItem.isVisible = true + deleteTeiItem.title = + String.format(deleteTeiItem.title.toString(), presenter.teType) + } else { + deleteTeiItem.isVisible = false + } + + val deleteEnrollmentItem = popupMenu.menu.findItem(R.id.deleteEnrollment) + deleteEnrollmentItem.isVisible = presenter.checkIfEnrollmentCanBeDeleted(enrollmentUid) + if (enrollmentUid != null) { val status = presenter.getEnrollmentStatus(enrollmentUid) if (status == EnrollmentStatus.COMPLETED) { diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java index 38279d8d09..93abcbf0c5 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenter.java @@ -1,10 +1,7 @@ package org.dhis2.usescases.teiDashboard; -import static androidx.core.content.ContextCompat.getString; - import com.google.gson.reflect.TypeToken; -import org.dhis2.R; import org.dhis2.commons.prefs.Preference; import org.dhis2.commons.prefs.PreferenceProvider; import org.dhis2.commons.schedulers.SchedulerProvider; @@ -26,13 +23,11 @@ import static org.dhis2.commons.matomo.Actions.OPEN_NOTES; import static org.dhis2.commons.matomo.Actions.OPEN_RELATIONSHIPS; -import static org.dhis2.utils.analytics.AnalyticsConstants.ACTIVE_FOLLOW_UP; import static org.dhis2.utils.analytics.AnalyticsConstants.CLICK; import static org.dhis2.utils.analytics.AnalyticsConstants.DELETE_ENROLL; import static org.dhis2.utils.analytics.AnalyticsConstants.DELETE_TEI; import static org.dhis2.commons.matomo.Actions.OPEN_ANALYTICS; import static org.dhis2.commons.matomo.Categories.DASHBOARD; -import static org.dhis2.utils.analytics.AnalyticsConstants.FOLLOW_UP; public class TeiDashboardPresenter implements TeiDashboardContracts.Presenter { @@ -135,6 +130,16 @@ public void trackDashboardNotes() { matomoAnalyticsController.trackEvent(DASHBOARD, OPEN_NOTES, CLICK); } + @Override + public Boolean checkIfTEICanBeDeleted() { + return dashboardRepository.checkIfDeleteTeiIsPossible(); + } + + @Override + public Boolean checkIfEnrollmentCanBeDeleted(String enrollmentUid) { + return dashboardRepository.checkIfDeleteEnrollmentIsPossible(enrollmentUid); + } + @Override public void onEnrollmentSelectorClick() { view.goToEnrollmentList(); @@ -150,7 +155,7 @@ public void setProgram(Program program) { @Override public void deleteTei() { compositeDisposable.add( - dashboardRepository.deleteTeiIfPossible() + dashboardRepository.deleteTei() .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.ui()) .subscribe( @@ -170,7 +175,7 @@ public void deleteTei() { @Override public void deleteEnrollment() { compositeDisposable.add( - dashboardRepository.deleteEnrollmentIfPossible( + dashboardRepository.deleteEnrollment( dashboardProgramModel.getCurrentEnrollment().uid() ) .subscribeOn(schedulerProvider.io()) diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt index 5a2efdb169..4412b7b482 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/TeiDashboardPresenterTest.kt @@ -224,7 +224,7 @@ class TeiDashboardPresenterTest { ) presenter.dashboardProgramModel = dashboardProgramModel whenever( - repository.deleteEnrollmentIfPossible(dashboardProgramModel.currentEnrollment.uid()), + repository.deleteEnrollment(dashboardProgramModel.currentEnrollment.uid()), ) doReturn Single.error(AuthorityException(null)) presenter.deleteEnrollment() @@ -246,7 +246,7 @@ class TeiDashboardPresenterTest { ) presenter.dashboardProgramModel = dashboardProgramModel whenever( - repository.deleteEnrollmentIfPossible(dashboardProgramModel.currentEnrollment.uid()), + repository.deleteEnrollment(dashboardProgramModel.currentEnrollment.uid()), ) doReturn Single.just(true) presenter.deleteEnrollment() @@ -256,7 +256,7 @@ class TeiDashboardPresenterTest { @Test fun `Should not deleteTei if it doesn't has permission`() { - whenever(repository.deleteTeiIfPossible()) doReturn Single.just(false) + whenever(repository.deleteTei()) doReturn Single.just(false) presenter.deleteTei() verify(view).authorityErrorMessage() @@ -264,7 +264,7 @@ class TeiDashboardPresenterTest { @Test fun `Should deleteTei if it has permission`() { - whenever(repository.deleteTeiIfPossible()) doReturn Single.just(true) + whenever(repository.deleteTei()) doReturn Single.just(true) presenter.deleteTei() verify(analyticsHelper).setEvent(DELETE_TEI, CLICK, DELETE_TEI) From 2e7829d9515ab5ac98737fe33ea76278c2b26cd5 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Tue, 16 Jan 2024 12:08:04 +0530 Subject: [PATCH 3/6] update confirm delete dialog design Older BottomSheetDialog has now been replaced by mobile-ui library `BottomSheetSheel` component --- .../TeiDashboardMobileActivity.kt | 49 +++++---- .../bottomsheet/DeleteBottomSheetDialog.kt | 99 +++++++++++++++++++ .../dialogs/bottomsheet/DialogButtonStyle.kt | 5 - ui-components/src/main/res/values/strings.xml | 1 - 4 files changed, 123 insertions(+), 31 deletions(-) create mode 100644 ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index e0bdc4c384..fe06c8f7a1 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -13,7 +13,11 @@ import android.view.MenuItem import android.view.View import android.view.WindowManager import android.widget.PopupMenu +import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.databinding.DataBindingUtil @@ -33,9 +37,7 @@ import org.dhis2.commons.sync.OnDismissListener import org.dhis2.commons.sync.SyncContext import org.dhis2.databinding.ActivityDashboardMobileBinding import org.dhis2.ui.ThemeManager -import org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialog -import org.dhis2.ui.dialogs.bottomsheet.BottomSheetDialogUiModel -import org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle +import org.dhis2.ui.dialogs.bottomsheet.DeleteBottomSheetDialog import org.dhis2.usescases.enrollment.EnrollmentActivity import org.dhis2.usescases.enrollment.EnrollmentActivity.Companion.getIntent import org.dhis2.usescases.general.ActivityGlobalAbstract @@ -670,33 +672,30 @@ class TeiDashboardMobileActivity : } private fun showDeleteTEIConfirmationDialog() { - BottomSheetDialog( - bottomSheetDialogUiModel = BottomSheetDialogUiModel( - title = getString(R.string.delete_tei_dialog_title).format(presenter.teType), - message = getString(R.string.delete_tei_dialog_message).format(presenter.teType), - iconResource = R.drawable.ic_error_outline, - mainButton = DialogButtonStyle.RemoveButton(), - secondaryButton = DialogButtonStyle.NeutralButton(R.string.cancel), - ), - onMainButtonClicked = { + DeleteBottomSheetDialog( + title = getString(R.string.delete_tei_dialog_title).format(presenter.teType), + description = getString(R.string.delete_tei_dialog_message).format(presenter.teType), + mainButtonText = getString(R.string.delete), + deleteForever = true, + onMainButtonClick = { presenter.deleteTei() - }, - ).show(supportFragmentManager, BottomSheetDialogUiModel::class.java.simpleName) + } + ).show( + supportFragmentManager, DeleteBottomSheetDialog.TAG + ) } private fun showRemoveEnrollmentConfirmationDialog() { - BottomSheetDialog( - bottomSheetDialogUiModel = BottomSheetDialogUiModel( - title = getString(R.string.remove_enrollment_dialog_title).format(programModel.currentProgram.displayName()), - message = getString(R.string.remove_enrollment_dialog_message).format(programModel.currentProgram.displayName()), - iconResource = R.drawable.ic_error_outline, - mainButton = DialogButtonStyle.RemoveButton(), - secondaryButton = DialogButtonStyle.NeutralButton(R.string.cancel), - ), - onMainButtonClicked = { + DeleteBottomSheetDialog( + title = getString(R.string.remove_enrollment_dialog_title).format(programModel.currentProgram.displayName()), + description = getString(R.string.remove_enrollment_dialog_message).format(programModel.currentProgram.displayName()), + mainButtonText = getString(R.string.remove), + onMainButtonClick = { presenter.deleteEnrollment() - }, - ).show(supportFragmentManager, BottomSheetDialogUiModel::class.java.simpleName) + } + ).show( + supportFragmentManager, DeleteBottomSheetDialog.TAG + ) } override fun onRelationshipMapLoaded() { diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt new file mode 100644 index 0000000000..ed0eaf9979 --- /dev/null +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt @@ -0,0 +1,99 @@ +package org.dhis2.ui.dialogs.bottomsheet + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.DeleteForever +import androidx.compose.material.icons.outlined.Info +import androidx.compose.material3.Icon +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import org.dhis2.ui.R +import org.hisp.dhis.mobile.ui.designsystem.component.BottomSheetShell +import org.hisp.dhis.mobile.ui.designsystem.component.Button +import org.hisp.dhis.mobile.ui.designsystem.component.ButtonBlock +import org.hisp.dhis.mobile.ui.designsystem.component.ButtonStyle +import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor + +class +DeleteBottomSheetDialog( + private val title: String, + private val description: String, + private val mainButtonText: String, + private val deleteForever: Boolean = false, + private val onMainButtonClick: () -> Unit, + + ) : BottomSheetDialogFragment() { + + companion object { + const val TAG: String = "DELETE_DIALOG" + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { + return ComposeView(requireContext()).apply { + setViewCompositionStrategy( + ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed, + ) + setContent { + BottomSheetShell( + title = title, + description = description, + icon = { + Icon( + imageVector = Icons.Outlined.Info, + contentDescription = "Button", + tint = SurfaceColor.Error, + ) + }, + buttonBlock = { + ButtonBlock( + primaryButton = { + Button( + style = ButtonStyle.OUTLINED, + text = getString(R.string.cancel), + onClick = { dismiss() }, + modifier = Modifier.fillMaxWidth(), + ) + }, + secondaryButton = { + Button( + style = ButtonStyle.FILLED, + icon = { + Icon( + imageVector = if (deleteForever) { + Icons.Filled.DeleteForever + } else { + Icons.Filled.Delete + }, + contentDescription = "Button", + ) + }, + text = mainButtonText, + onClick = { + onMainButtonClick + }, + modifier = Modifier + .fillMaxWidth(), + ) + }, + ) + }, + onDismiss = { + dismiss() + }, + ) + } + } + } +} \ No newline at end of file diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt index 5103f1daaa..1d7fbb7bf8 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt @@ -43,11 +43,6 @@ sealed class DialogButtonStyle( colorResource = warningColor, ) - class RemoveButton : DialogButtonStyle( - textResource = R.string.remove, - colorResource = errorColor, - ) - class NeutralButton(override val textResource: Int) : DialogButtonStyle( textResource = textResource, colorResource = colorPrimary, diff --git a/ui-components/src/main/res/values/strings.xml b/ui-components/src/main/res/values/strings.xml index ddaec08482..d799973f57 100644 --- a/ui-components/src/main/res/values/strings.xml +++ b/ui-components/src/main/res/values/strings.xml @@ -6,7 +6,6 @@ Keep editing Review Cancel - Remove Save Clear Draw here From 5b98a67f8305799aa74261901acb6e9da6bc29e0 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 5 Feb 2024 15:47:49 +0530 Subject: [PATCH 4/6] Set button color style in delete bottom sheet dialog --- .../ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt index ed0eaf9979..71d86ea3d0 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt @@ -20,6 +20,7 @@ import org.hisp.dhis.mobile.ui.designsystem.component.BottomSheetShell import org.hisp.dhis.mobile.ui.designsystem.component.Button import org.hisp.dhis.mobile.ui.designsystem.component.ButtonBlock import org.hisp.dhis.mobile.ui.designsystem.component.ButtonStyle +import org.hisp.dhis.mobile.ui.designsystem.component.ColorStyle import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor class @@ -80,6 +81,7 @@ DeleteBottomSheetDialog( ) }, text = mainButtonText, + colorStyle = ColorStyle.ERROR, onClick = { onMainButtonClick }, @@ -92,8 +94,12 @@ DeleteBottomSheetDialog( onDismiss = { dismiss() }, + content = { + // no-op + }, + showSectionDivider = false ) } } } -} \ No newline at end of file +} From a3e34a3b88466326e33282050174c2aee2c05fe6 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 5 Feb 2024 15:47:57 +0530 Subject: [PATCH 5/6] Run code formatting --- .../teiDashboard/DashboardRepositoryImpl.kt | 2 +- .../teiDashboard/TeiDashboardMobileActivity.kt | 14 ++++++-------- .../dialogs/bottomsheet/DeleteBottomSheetDialog.kt | 7 +++---- .../ui/dialogs/bottomsheet/DialogButtonStyle.kt | 1 - 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt index f96dd2b5b5..e00e0d579d 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardRepositoryImpl.kt @@ -426,7 +426,7 @@ class DashboardRepositoryImpl( d2.enrollmentModule() .enrollments().uid(enrollmentUid) enrollmentObjectRepository.setStatus( - enrollmentObjectRepository.blockingGet()!!.status()!! + enrollmentObjectRepository.blockingGet()!!.status()!!, ) enrollmentObjectRepository.blockingDelete() !d2.enrollmentModule().enrollments().byTrackedEntityInstance().eq(teiUid) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index fe06c8f7a1..a5df046799 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -13,11 +13,7 @@ import android.view.MenuItem import android.view.View import android.view.WindowManager import android.widget.PopupMenu -import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts -import androidx.compose.material.Icon -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Delete import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.databinding.DataBindingUtil @@ -679,9 +675,10 @@ class TeiDashboardMobileActivity : deleteForever = true, onMainButtonClick = { presenter.deleteTei() - } + }, ).show( - supportFragmentManager, DeleteBottomSheetDialog.TAG + supportFragmentManager, + DeleteBottomSheetDialog.TAG, ) } @@ -692,9 +689,10 @@ class TeiDashboardMobileActivity : mainButtonText = getString(R.string.remove), onMainButtonClick = { presenter.deleteEnrollment() - } + }, ).show( - supportFragmentManager, DeleteBottomSheetDialog.TAG + supportFragmentManager, + DeleteBottomSheetDialog.TAG, ) } diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt index 71d86ea3d0..5920408cfe 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Delete @@ -31,7 +30,7 @@ DeleteBottomSheetDialog( private val deleteForever: Boolean = false, private val onMainButtonClick: () -> Unit, - ) : BottomSheetDialogFragment() { +) : BottomSheetDialogFragment() { companion object { const val TAG: String = "DELETE_DIALOG" @@ -95,9 +94,9 @@ DeleteBottomSheetDialog( dismiss() }, content = { - // no-op + // no-op }, - showSectionDivider = false + showSectionDivider = false, ) } } diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt index 1d7fbb7bf8..36f85fe461 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DialogButtonStyle.kt @@ -3,7 +3,6 @@ package org.dhis2.ui.dialogs.bottomsheet import androidx.compose.ui.graphics.Color import org.dhis2.ui.R import org.dhis2.ui.theme.colorPrimary -import org.dhis2.ui.theme.errorColor import org.dhis2.ui.theme.warningColor sealed class DialogButtonStyle( From b328daf81379eaed7b4154f4f577fa94cbc4a98a Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Thu, 8 Feb 2024 10:36:47 +0530 Subject: [PATCH 6/6] Fix delete button callback not working in `DeleteBottomSheetDialog` --- .../dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt index 5920408cfe..06e2cd2d87 100644 --- a/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt +++ b/ui-components/src/main/java/org/dhis2/ui/dialogs/bottomsheet/DeleteBottomSheetDialog.kt @@ -81,9 +81,7 @@ DeleteBottomSheetDialog( }, text = mainButtonText, colorStyle = ColorStyle.ERROR, - onClick = { - onMainButtonClick - }, + onClick = onMainButtonClick, modifier = Modifier .fillMaxWidth(), )