Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block closing the notification permission dialog by tapping outside the bounds #5792

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 a form is finalized using a `ref` attribute on the `submission` element
*/
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))
}
}
}