Skip to content

Commit

Permalink
identify when it does not require request permission
Browse files Browse the repository at this point in the history
  • Loading branch information
mebarbosa committed Dec 11, 2024
1 parent fb5425b commit 9d8c877
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ class MainActivity :
settings.setNotificationsDisabledMessageShown(true)
},
onPermissionGranted = onPermissionGranted,
onPermissionHandlingNotRequired = {},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package au.com.shiftyjelly.pocketcasts.podcasts.view.podcast

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
Expand Down Expand Up @@ -500,31 +499,28 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener {

private val onNotificationsClicked: () -> Unit = {
context?.let { context ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
NotificationPermissionHelper.checkForNotificationPermission(
requireActivity(),
launcher = notificationPermissionLauncher,
onShowRequestPermissionRationale = {
(activity as? FragmentHostListener)?.snackBarView()?.let { snackBarView ->
Snackbar.make(snackBarView, getString(LR.string.notifications_blocked_warning), Snackbar.LENGTH_LONG)
.setAction(
getString(LR.string.notifications_blocked_warning_snackbar_action)
.uppercase(Locale.getDefault()),
) {
// Open app settings for the user to enable permissions
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val uri: Uri = Uri.fromParts("package", requireContext().packageName, null)
intent.data = uri
startActivity(intent)
}.show()
}
},
onPermissionGranted = { viewModel.toggleNotifications(context) },
)
} else {
viewModel.toggleNotifications(context)
}
NotificationPermissionHelper.checkForNotificationPermission(
requireActivity(),
launcher = notificationPermissionLauncher,
onShowRequestPermissionRationale = {
(activity as? FragmentHostListener)?.snackBarView()?.let { snackBarView ->
Snackbar.make(snackBarView, getString(LR.string.notifications_blocked_warning), Snackbar.LENGTH_LONG)
.setAction(
getString(LR.string.notifications_blocked_warning_snackbar_action)
.uppercase(Locale.getDefault()),
) {
// Open app settings for the user to enable permissions
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val uri: Uri = Uri.fromParts("package", requireContext().packageName, null)
intent.data = uri
startActivity(intent)
}.show()
}
},
onPermissionGranted = { viewModel.toggleNotifications(context) },
onPermissionHandlingNotRequired = { viewModel.toggleNotifications(context) },
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object NotificationPermissionHelper {
launcher: ActivityResultLauncher<String>,
onShowRequestPermissionRationale: () -> Unit = {},
onPermissionGranted: () -> Unit = {},
onPermissionHandlingNotRequired: () -> Unit = {},
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
when {
Expand All @@ -32,7 +33,7 @@ object NotificationPermissionHelper {
}
}
} else {
onPermissionGranted()
onPermissionHandlingNotRequired()
}
}
}

0 comments on commit 9d8c877

Please sign in to comment.