mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
Add handling for fullScreenIntentPermission
This commit is contained in:
@ -154,7 +154,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
alarm.isEnabled = true
|
||||
|
||||
var alarmId = alarm.id
|
||||
activity.handleNotificationPermission { granted ->
|
||||
activity.handleFullScreenNotificationsPermission { granted ->
|
||||
if (granted) {
|
||||
if (alarm.id == 0) {
|
||||
alarmId = activity.dbHelper.insertAlarm(alarm)
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.simplemobiletools.clock.extensions
|
||||
|
||||
import com.simplemobiletools.clock.R
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
||||
import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
|
||||
|
||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(callback: (granted: Boolean) -> Unit) {
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
if (canUseFullScreenIntent()) {
|
||||
callback(true)
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity = this,
|
||||
textId = R.string.allow_full_screen_notifications_reminders,
|
||||
positiveActionCallback = {
|
||||
callback(true)
|
||||
},
|
||||
negativeActionCallback = {
|
||||
// It is not critical to have full screen intents, so we should allow users to continue using the app
|
||||
callback(true)
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
@ -127,10 +127,10 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
}
|
||||
|
||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||
(activity as SimpleActivity).handleNotificationPermission { granted ->
|
||||
(activity as SimpleActivity).handleFullScreenNotificationsPermission { granted ->
|
||||
if (granted) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleNotificationPermission
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user