mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-02-08 07:58:38 +01:00
Simplify handling full screen notifications
This commit is contained in:
parent
c50dc814ac
commit
ca2b14263c
@ -159,7 +159,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
||||
alarm.isEnabled = true
|
||||
|
||||
var alarmId = alarm.id
|
||||
activity.handleFullScreenNotificationsPermission { granted ->
|
||||
activity.handleFullScreenNotificationsPermission { granted, _ ->
|
||||
if (granted) {
|
||||
if (alarm.id == 0) {
|
||||
alarmId = activity.dbHelper.insertAlarm(alarm)
|
||||
|
@ -7,13 +7,12 @@ import com.simplemobiletools.commons.extensions.canUseFullScreenIntent
|
||||
import com.simplemobiletools.commons.extensions.openFullScreenIntentSettings
|
||||
|
||||
fun BaseSimpleActivity.handleFullScreenNotificationsPermission(
|
||||
fullScreenNotificationsDeniedCallback: () -> Unit = {},
|
||||
notificationsCallback: (granted: Boolean) -> Unit,
|
||||
notificationsCallback: (granted: Boolean, fullScreenGranted: Boolean) -> Unit,
|
||||
) {
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
if (canUseFullScreenIntent()) {
|
||||
notificationsCallback(true)
|
||||
notificationsCallback(true, true)
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity = this,
|
||||
@ -22,12 +21,12 @@ fun BaseSimpleActivity.handleFullScreenNotificationsPermission(
|
||||
openFullScreenIntentSettings(BuildConfig.APPLICATION_ID)
|
||||
},
|
||||
negativeActionCallback = {
|
||||
fullScreenNotificationsDeniedCallback()
|
||||
notificationsCallback(true, false)
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
notificationsCallback(false)
|
||||
notificationsCallback(false, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,28 +124,25 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||
}
|
||||
|
||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||
(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()
|
||||
(activity as SimpleActivity).handleFullScreenNotificationsPermission { granted, fullScreenGranted ->
|
||||
if (granted && fullScreenGranted) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleFullScreenNotificationsPermission
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity as SimpleActivity,
|
||||
com.simplemobiletools.commons.R.string.allow_notifications_reminders,
|
||||
{ (activity as SimpleActivity).openNotificationSettings() })
|
||||
requireActivity().toast(com.simplemobiletools.commons.R.string.unknown_error_occurred)
|
||||
}
|
||||
},
|
||||
fullScreenNotificationsDeniedCallback = {
|
||||
requireContext().updateWidgets()
|
||||
} else if (!fullScreenGranted) {
|
||||
setupAlarms()
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity as SimpleActivity,
|
||||
com.simplemobiletools.commons.R.string.allow_notifications_reminders,
|
||||
{ (activity as SimpleActivity).openNotificationSettings() })
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAlarmState(alarm: Alarm) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user