From b8a8e0f86fe842f003f56425cfb7f24371bb064c Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 24 Oct 2023 11:04:42 +0200 Subject: [PATCH 1/4] Added failing test --- .../android/mainmenu/PermissionsDialogFragmentTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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..c6a7b222ce9 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 @@ -70,4 +70,12 @@ class PermissionsDialogFragmentTest { 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)) + } + } } From ca33a719fed522f63742490838e0adb1f6859ff2 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 24 Oct 2023 11:05:20 +0200 Subject: [PATCH 2/4] PermissionsDialogFragment should not be cancelable --- .../odk/collect/android/mainmenu/PermissionsDialogFragment.kt | 2 ++ 1 file changed, 2 insertions(+) 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..d93119202e2 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 @@ -21,6 +21,8 @@ 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) From 371b318ef45f15e65f74ed0167e03c01f10f9bd1 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 24 Oct 2023 11:07:09 +0200 Subject: [PATCH 3/4] Removed redundant onCancel implementation --- .../android/mainmenu/PermissionsDialogFragment.kt | 7 ------- .../android/mainmenu/PermissionsDialogFragmentTest.kt | 9 --------- 2 files changed, 16 deletions(-) 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 d93119202e2..75825e3bb9d 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,7 +1,6 @@ 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 @@ -9,7 +8,6 @@ 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 @@ -40,9 +38,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 c6a7b222ce9..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,14 +56,6 @@ 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() From 42e6af84dd2800e671101acd295c4f53db184f34 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 24 Oct 2023 11:08:01 +0200 Subject: [PATCH 4/4] Removed redundnt analytics --- .../org/odk/collect/android/analytics/AnalyticsEvents.kt | 7 ------- .../collect/android/mainmenu/PermissionsDialogFragment.kt | 4 ---- 2 files changed, 11 deletions(-) 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 75825e3bb9d..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 @@ -6,9 +6,7 @@ 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_OK import org.odk.collect.permissions.PermissionListener import org.odk.collect.permissions.PermissionsProvider @@ -25,8 +23,6 @@ class PermissionsDialogFragment( .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(),