add handling for the Post Notifications permission on Android 13
This commit is contained in:
parent
c196d5c1f8
commit
f365e92f15
|
@ -11,6 +11,7 @@
|
|||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_NETWORK_STATE"
|
||||
|
|
|
@ -118,11 +118,17 @@ class TimerAdapter(
|
|||
|
||||
timer_play_pause.applyColorFilter(textColor)
|
||||
timer_play_pause.setOnClickListener {
|
||||
when (val state = timer.state) {
|
||||
is TimerState.Idle -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, timer.seconds.secondsToMillis))
|
||||
is TimerState.Paused -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, state.tick))
|
||||
is TimerState.Running -> EventBus.getDefault().post(TimerEvent.Pause(timer.id!!, state.tick))
|
||||
is TimerState.Finished -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, timer.seconds.secondsToMillis))
|
||||
(activity as SimpleActivity).handleNotificationPermission {
|
||||
if (it) {
|
||||
when (val state = timer.state) {
|
||||
is TimerState.Idle -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, timer.seconds.secondsToMillis))
|
||||
is TimerState.Paused -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, state.tick))
|
||||
is TimerState.Running -> EventBus.getDefault().post(TimerEvent.Pause(timer.id!!, state.tick))
|
||||
is TimerState.Finished -> EventBus.getDefault().post(TimerEvent.Start(timer.id!!, timer.seconds.secondsToMillis))
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,20 +130,26 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
|
|||
alarm.isEnabled = true
|
||||
|
||||
var alarmId = alarm.id
|
||||
if (alarm.id == 0) {
|
||||
alarmId = activity.dbHelper.insertAlarm(alarm)
|
||||
if (alarmId == -1) {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} else {
|
||||
if (!activity.dbHelper.updateAlarm(alarm)) {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
activity.handleNotificationPermission {
|
||||
if (it) {
|
||||
if (alarm.id == 0) {
|
||||
alarmId = activity.dbHelper.insertAlarm(alarm)
|
||||
if (alarmId == -1) {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} else {
|
||||
if (!activity.dbHelper.updateAlarm(alarm)) {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
|
||||
activity.config.alarmLastConfig = alarm
|
||||
callback(alarmId)
|
||||
alertDialog.dismiss()
|
||||
} else {
|
||||
activity.toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
|
||||
activity.config.alarmLastConfig = alarm
|
||||
callback(alarmId)
|
||||
alertDialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,14 +122,20 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||
}
|
||||
|
||||
override fun alarmToggled(id: Int, isEnabled: Boolean) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
} else {
|
||||
requireActivity().toast(R.string.unknown_error_occurred)
|
||||
(activity as SimpleActivity).handleNotificationPermission {
|
||||
if (it) {
|
||||
if (requireContext().dbHelper.updateAlarmEnabledState(id, isEnabled)) {
|
||||
val alarm = alarms.firstOrNull { it.id == id } ?: return@handleNotificationPermission
|
||||
alarm.isEnabled = isEnabled
|
||||
checkAlarmState(alarm)
|
||||
} else {
|
||||
requireActivity().toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
requireContext().updateWidgets()
|
||||
} else {
|
||||
activity?.toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
requireContext().updateWidgets()
|
||||
}
|
||||
|
||||
private fun checkAlarmState(alarm: Alarm) {
|
||||
|
|
|
@ -119,10 +119,15 @@ class StopwatchFragment : Fragment() {
|
|||
}
|
||||
|
||||
private fun togglePlayPause() {
|
||||
Stopwatch.toggle(true)
|
||||
(activity as SimpleActivity).handleNotificationPermission {
|
||||
if (it) {
|
||||
Stopwatch.toggle(true)
|
||||
} else {
|
||||
activity?.toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateDisplayedText(totalTime: Long, lapTime: Long, useLongerMSFormat: Boolean) {
|
||||
view.stopwatch_time.text = totalTime.formatStopwatchTime(useLongerMSFormat)
|
||||
if (Stopwatch.laps.isNotEmpty() && lapTime != -1L) {
|
||||
|
|
Loading…
Reference in New Issue