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