mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
Properly update state of alarms when full screen notification is not approved
This commit is contained in:
@@ -6,22 +6,28 @@ import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
|||||||
import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
|
import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
|
||||||
import com.simplemobiletools.commons.extensions.openFullScreenIntentSettings
|
import com.simplemobiletools.commons.extensions.openFullScreenIntentSettings
|
||||||
|
|
||||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(callback: (granted: Boolean) -> Unit) {
|
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(
|
||||||
|
fullScreenNotificationsDeniedCallback: () -> Unit = {},
|
||||||
|
notificationsCallback: (granted: Boolean) -> Unit,
|
||||||
|
) {
|
||||||
handleNotificationPermission { granted ->
|
handleNotificationPermission { granted ->
|
||||||
if (granted) {
|
if (granted) {
|
||||||
if (canUseFullScreenIntent()) {
|
if (canUseFullScreenIntent()) {
|
||||||
callback(true)
|
notificationsCallback(true)
|
||||||
} else {
|
} else {
|
||||||
PermissionRequiredDialog(
|
PermissionRequiredDialog(
|
||||||
activity = this,
|
activity = this,
|
||||||
textId = com.simplemobiletools.commons.R.string.allow_full_screen_notifications_reminders,
|
textId = com.simplemobiletools.commons.R.string.allow_full_screen_notifications_reminders,
|
||||||
positiveActionCallback = {
|
positiveActionCallback = {
|
||||||
openFullScreenIntentSettings(BuildConfig.APPLICATION_ID)
|
openFullScreenIntentSettings(BuildConfig.APPLICATION_ID)
|
||||||
|
},
|
||||||
|
negativeActionCallback = {
|
||||||
|
fullScreenNotificationsDeniedCallback()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(false)
|
notificationsCallback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -124,23 +124,28 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||||
(activity as SimpleActivity).handleFullScreenNotificationsPermission { granted ->
|
(activity as SimpleActivity).handleFullScreenNotificationsPermission(
|
||||||
if (granted) {
|
notificationsCallback = { granted ->
|
||||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
if (granted) {
|
||||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||||
alarm.isEnabled = isEnabled
|
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
||||||
checkAlarmState(alarm)
|
alarm.isEnabled = isEnabled
|
||||||
|
checkAlarmState(alarm)
|
||||||
|
} else {
|
||||||
|
requireActivity().toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
|
||||||
|
}
|
||||||
|
requireContext().updateWidgets()
|
||||||
} else {
|
} 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 {
|
fullScreenNotificationsDeniedCallback = {
|
||||||
PermissionRequiredDialog(
|
setupAlarms()
|
||||||
activity as SimpleActivity,
|
|
||||||
com.simplemobiletools.commons.R.string.allow_notifications_reminders,
|
|
||||||
{ (activity as SimpleActivity).openNotificationSettings() })
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAlarmState(alarm: Alarm) {
|
private fun checkAlarmState(alarm: Alarm) {
|
||||||
|
Reference in New Issue
Block a user