From 127c62a9c9ec41e5d1183bc83bd63508cab2f4df Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 7 Feb 2022 21:23:48 +0100 Subject: [PATCH] add a Settings button for quick redirection to app settings --- .../calendar/pro/activities/EventActivity.kt | 4 +- .../pro/dialogs/ReminderWarningDialog.kt | 47 +++++++++++++++++++ .../res/layout/dialog_reminder_warning.xml | 12 +++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ReminderWarningDialog.kt create mode 100644 app/src/main/res/layout/dialog_reminder_warning.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 260d89c37..b87b91161 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -187,7 +187,7 @@ class EventActivity : SimpleActivity() { if (config.wasAlarmWarningShown) { showReminder1Dialog() } else { - ConfirmationDialog(this, messageId = R.string.reminder_warning, positive = R.string.ok, negative = 0) { + ReminderWarningDialog(this) { config.wasAlarmWarningShown = true showReminder1Dialog() } @@ -1058,7 +1058,7 @@ class EventActivity : SimpleActivity() { saveEvent() } } else { - ConfirmationDialog(this, messageId = R.string.reminder_warning, positive = R.string.ok, negative = 0) { + ReminderWarningDialog(this) { config.wasAlarmWarningShown = true ensureBackgroundThread { saveEvent() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ReminderWarningDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ReminderWarningDialog.kt new file mode 100644 index 000000000..a56ec878e --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ReminderWarningDialog.kt @@ -0,0 +1,47 @@ +package com.simplemobiletools.calendar.pro.dialogs + +import android.app.Activity +import android.content.Intent +import android.net.Uri +import android.provider.Settings +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.calendar.pro.R +import com.simplemobiletools.commons.extensions.hideKeyboard +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.showErrorToast + +class ReminderWarningDialog(val activity: Activity, val callback: () -> Unit) { + var dialog: AlertDialog + + init { + val view = activity.layoutInflater.inflate(R.layout.dialog_reminder_warning, null) + + dialog = AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNeutralButton(R.string.settings, null) + .create().apply { + activity.setupDialogStuff(view, this, cancelOnTouchOutside = false) + getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener { + redirectToSettings() + } + } + } + + private fun dialogConfirmed() { + dialog.dismiss() + callback() + } + + private fun redirectToSettings() { + activity.hideKeyboard() + Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply { + data = Uri.fromParts("package", activity.packageName, null) + + try { + activity.startActivity(this) + } catch (e: Exception) { + activity.showErrorToast(e) + } + } + } +} diff --git a/app/src/main/res/layout/dialog_reminder_warning.xml b/app/src/main/res/layout/dialog_reminder_warning.xml new file mode 100644 index 000000000..929e638b7 --- /dev/null +++ b/app/src/main/res/layout/dialog_reminder_warning.xml @@ -0,0 +1,12 @@ + +