Properly update state of alarms when full screen notification is not approved
This commit is contained in:
parent
8e713bb68c
commit
04a173501d
2 changed files with 28 additions and 17 deletions
|
@ -6,22 +6,28 @@ import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
|||
import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
|
||||
import com.simplemobiletools.commons.extensions.openFullScreenIntentSettings
|
||||
|
||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(callback: (granted: Boolean) -> Unit) {
|
||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(
|
||||
fullScreenNotificationsDeniedCallback: () -> Unit = {},
|
||||
notificationsCallback: (granted: Boolean) -> Unit,
|
||||
) {
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
if (canUseFullScreenIntent()) {
|
||||
callback(true)
|
||||
notificationsCallback(true)
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity = this,
|
||||
textId = com.simplemobiletools.commons.R.string.allow_full_screen_notifications_reminders,
|
||||
positiveActionCallback = {
|
||||
openFullScreenIntentSettings(BuildConfig.APPLICATION_ID)
|
||||
},
|
||||
negativeActionCallback = {
|
||||
fullScreenNotificationsDeniedCallback()
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
callback(false)
|
||||
notificationsCallback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,23 +124,28 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||
}
|
||||
|
||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||
(activity as SimpleActivity).handleFullScreenNotificationsPermission { granted ->
|
||||
if (granted) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
(activity as SimpleActivity).handleFullScreenNotificationsPermission(
|
||||
notificationsCallback = { granted ->
|
||||
if (granted) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
} else {
|
||||
requireActivity().toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
|
||||
}
|
||||
requireContext().updateWidgets()
|
||||
} else {
|
||||
requireActivity().toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
|
||||
PermissionRequiredDialog(
|
||||
activity as SimpleActivity,
|
||||
com.simplemobiletools.commons.R.string.allow_notifications_reminders,
|
||||
{ (activity as SimpleActivity).openNotificationSettings() })
|
||||
}
|
||||
requireContext().updateWidgets()
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity as SimpleActivity,
|
||||
com.simplemobiletools.commons.R.string.allow_notifications_reminders,
|
||||
{ (activity as SimpleActivity).openNotificationSettings() })
|
||||
},
|
||||
fullScreenNotificationsDeniedCallback = {
|
||||
setupAlarms()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkAlarmState(alarm: Alarm) {
|
||||
|
|
Loading…
Reference in a new issue