diff --git a/collect_app/src/main/java/org/odk/collect/android/analytics/AnalyticsEvents.kt b/collect_app/src/main/java/org/odk/collect/android/analytics/AnalyticsEvents.kt index 447b2238009..9c20a2b521e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/analytics/AnalyticsEvents.kt +++ b/collect_app/src/main/java/org/odk/collect/android/analytics/AnalyticsEvents.kt @@ -157,13 +157,6 @@ object AnalyticsEvents { const val TEXT_NUMBER_WIDGET = "TextNumberWidget" const val TEXT_NUMBER_WIDGET_WITH_THOUSANDS_SEPARATOR = "TextNumberWidgetWithThousandsSeparator" - /** - * Tracks how many users cancel the permission dialog vs how many go through the permissions - * request flow. - */ - const val PERMISSIONS_DIALOG_CANCEL = "PermissionsDialogCancel" - const val PERMISSIONS_DIALOG_OK = "PermissionsDialogOK" - /** * Tracks how often a form is finalized using a `ref` attribute on the `submission` element */ diff --git a/collect_app/src/main/java/org/odk/collect/android/mainmenu/PermissionsDialogFragment.kt b/collect_app/src/main/java/org/odk/collect/android/mainmenu/PermissionsDialogFragment.kt index f3d50fd6570..62ec7a96bba 100644 --- a/collect_app/src/main/java/org/odk/collect/android/mainmenu/PermissionsDialogFragment.kt +++ b/collect_app/src/main/java/org/odk/collect/android/mainmenu/PermissionsDialogFragment.kt @@ -1,16 +1,12 @@ package org.odk.collect.android.mainmenu import android.app.Dialog -import android.content.DialogInterface import android.os.Build import android.os.Bundle import androidx.annotation.RequiresApi import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder -import org.odk.collect.analytics.Analytics import org.odk.collect.android.R -import org.odk.collect.android.analytics.AnalyticsEvents.PERMISSIONS_DIALOG_CANCEL -import org.odk.collect.android.analytics.AnalyticsEvents.PERMISSIONS_DIALOG_OK import org.odk.collect.permissions.PermissionListener import org.odk.collect.permissions.PermissionsProvider @@ -21,12 +17,12 @@ class PermissionsDialogFragment( @RequiresApi(Build.VERSION_CODES.TIRAMISU) override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + isCancelable = false + return MaterialAlertDialogBuilder(requireContext()) .setTitle(org.odk.collect.strings.R.string.permission_dialog_title) .setView(R.layout.permissions_dialog_layout) .setPositiveButton(org.odk.collect.strings.R.string.ok) { _, _ -> - Analytics.log(PERMISSIONS_DIALOG_OK) - requestPermissionsViewModel.permissionsRequested() permissionsProvider.requestPermissions( requireActivity(), @@ -38,9 +34,4 @@ class PermissionsDialogFragment( } .create() } - - override fun onCancel(dialog: DialogInterface) { - Analytics.log(PERMISSIONS_DIALOG_CANCEL) - requestPermissionsViewModel.permissionsRequested() - } } diff --git a/collect_app/src/test/java/org/odk/collect/android/mainmenu/PermissionsDialogFragmentTest.kt b/collect_app/src/test/java/org/odk/collect/android/mainmenu/PermissionsDialogFragmentTest.kt index db7b3043ab9..4d51bf9b661 100644 --- a/collect_app/src/test/java/org/odk/collect/android/mainmenu/PermissionsDialogFragmentTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/mainmenu/PermissionsDialogFragmentTest.kt @@ -1,6 +1,5 @@ package org.odk.collect.android.mainmenu -import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.matcher.RootMatchers.isDialog @@ -57,17 +56,17 @@ class PermissionsDialogFragmentTest { verify(requestPermissionsViewModel).permissionsRequested() } - @Test - fun dismissing_callsPermissionRequested() { - launcherRule.launch(PermissionsDialogFragment::class.java) - - Espresso.pressBack() - verify(requestPermissionsViewModel).permissionsRequested() - } - @Test fun recreating_doesNotCallPermissionsRequested() { launcherRule.launch(PermissionsDialogFragment::class.java).recreate() verify(requestPermissionsViewModel, never()).permissionsRequested() } + + @Test + fun `The dialog should not be dismissed after clicking out of its area or on device back button`() { + val scenario = launcherRule.launch(PermissionsDialogFragment::class.java) + scenario.onFragment { + assertThat(it.isCancelable, equalTo(false)) + } + } }