Skip to content

Commit

Permalink
Merge pull request getodk#5792 from grzesiek2010/COLLECT-5758
Browse files Browse the repository at this point in the history
Block closing the notification permission dialog by tapping outside the bounds
  • Loading branch information
grzesiek2010 authored and seadowg committed Oct 26, 2023
1 parent 54d2b90 commit e8a74ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 form-level auto-delete setting is used
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(),
Expand All @@ -38,9 +34,4 @@ class PermissionsDialogFragment(
}
.create()
}

override fun onCancel(dialog: DialogInterface) {
Analytics.log(PERMISSIONS_DIALOG_CANCEL)
requestPermissionsViewModel.permissionsRequested()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
}
}
}

0 comments on commit e8a74ad

Please sign in to comment.