show a warning dialog if app notifications are disabled by the system

This commit is contained in:
tibbi 2018-09-22 09:40:55 +02:00
parent ace2103b7f
commit 5ff3a754b5
1 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import android.app.TimePickerDialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.NotificationManagerCompat
import android.text.method.LinkMovementMethod
import android.view.Menu
import android.view.MenuItem
@ -120,12 +121,14 @@ class EventActivity : SimpleActivity() {
event_repetition_limit_holder.setOnClickListener { showRepetitionTypePicker() }
event_reminder_1.setOnClickListener {
if (config.wasAlarmWarningShown) {
showReminder1Dialog()
} else {
ConfirmationDialog(this, messageId = R.string.reminder_warning, positive = R.string.ok, negative = 0) {
config.wasAlarmWarningShown = true
handleNotificationAvailability() {
if (config.wasAlarmWarningShown) {
showReminder1Dialog()
} else {
ConfirmationDialog(this, messageId = R.string.reminder_warning, positive = R.string.ok, negative = 0) {
config.wasAlarmWarningShown = true
showReminder1Dialog()
}
}
}
}
@ -267,6 +270,16 @@ class EventActivity : SimpleActivity() {
}
}
private fun handleNotificationAvailability(callback: () -> Unit) {
if (NotificationManagerCompat.from(applicationContext).areNotificationsEnabled()) {
callback()
} else {
ConfirmationDialog(this, messageId = R.string.notifications_disabled, positive = R.string.ok, negative = 0) {
callback()
}
}
}
private fun showReminder1Dialog() {
showPickSecondsDialogHelper(mReminder1Minutes) {
mReminder1Minutes = if (it <= 0) it else it / 60