diff --git a/app/src/main/kotlin/org/fossify/calendar/activities/EventActivity.kt b/app/src/main/kotlin/org/fossify/calendar/activities/EventActivity.kt index 61c9e5c18..ea0fe7470 100644 --- a/app/src/main/kotlin/org/fossify/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/org/fossify/calendar/activities/EventActivity.kt @@ -1,9 +1,11 @@ package org.fossify.calendar.activities +import android.Manifest import android.app.Activity import android.app.DatePickerDialog import android.app.TimePickerDialog import android.content.Intent +import android.content.pm.PackageManager.PERMISSION_GRANTED import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable @@ -264,9 +266,10 @@ class EventActivity : SimpleActivity() { } else { mEvent = Event(null) config.apply { - mReminder1Minutes = if (usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes1 else defaultReminder1 - mReminder2Minutes = if (usePreviousEventReminders && lastEventReminderMinutes2 >= -1) lastEventReminderMinutes2 else defaultReminder2 - mReminder3Minutes = if (usePreviousEventReminders && lastEventReminderMinutes3 >= -1) lastEventReminderMinutes3 else defaultReminder3 + val reminders = defaultReminders + mReminder1Minutes = reminders.first + mReminder2Minutes = reminders.second + mReminder3Minutes = reminders.third } if (savedInstanceState == null) { diff --git a/app/src/main/kotlin/org/fossify/calendar/activities/MainActivity.kt b/app/src/main/kotlin/org/fossify/calendar/activities/MainActivity.kt index bfd5b87e6..01680d5fa 100644 --- a/app/src/main/kotlin/org/fossify/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/org/fossify/calendar/activities/MainActivity.kt @@ -145,6 +145,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { addImportIdsToTasks { refreshViewPager() } + + handlePermission(PERMISSION_POST_NOTIFICATIONS) {} } override fun onResume() { diff --git a/app/src/main/kotlin/org/fossify/calendar/activities/TaskActivity.kt b/app/src/main/kotlin/org/fossify/calendar/activities/TaskActivity.kt index 5a8598a91..0af3d3b6f 100644 --- a/app/src/main/kotlin/org/fossify/calendar/activities/TaskActivity.kt +++ b/app/src/main/kotlin/org/fossify/calendar/activities/TaskActivity.kt @@ -1,8 +1,10 @@ package org.fossify.calendar.activities +import android.Manifest import android.app.DatePickerDialog import android.app.TimePickerDialog import android.content.Intent +import android.content.pm.PackageManager import android.graphics.Color import android.os.Bundle import android.view.WindowManager @@ -240,9 +242,10 @@ class TaskActivity : SimpleActivity() { } else { mTask = Event(null) config.apply { - mReminder1Minutes = if (usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes1 else defaultReminder1 - mReminder2Minutes = if (usePreviousEventReminders && lastEventReminderMinutes2 >= -1) lastEventReminderMinutes2 else defaultReminder2 - mReminder3Minutes = if (usePreviousEventReminders && lastEventReminderMinutes3 >= -1) lastEventReminderMinutes3 else defaultReminder3 + val reminders = defaultReminders + mReminder1Minutes = reminders.first + mReminder2Minutes = reminders.second + mReminder3Minutes = reminders.third } if (savedInstanceState == null) { diff --git a/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt b/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt index 86c75ba10..539228efc 100644 --- a/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt @@ -1,8 +1,11 @@ package org.fossify.calendar.helpers +import android.Manifest import android.content.Context +import android.content.pm.PackageManager import android.media.AudioManager import android.media.RingtoneManager +import androidx.core.content.ContextCompat import org.fossify.calendar.R import org.fossify.calendar.extensions.config import org.fossify.calendar.extensions.scheduleCalDAVSync @@ -180,16 +183,34 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(USE_PREVIOUS_EVENT_REMINDERS, true) set(usePreviousEventReminders) = prefs.edit().putBoolean(USE_PREVIOUS_EVENT_REMINDERS, usePreviousEventReminders).apply() + fun getDefault(reminder: String, defValue: Int): Int { + val hasPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED + if (hasPermission) { + return prefs.getInt(reminder, defValue) + } else { + return REMINDER_OFF + } + } + + val defaultReminders: Triple + get() { + val hasPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED + val defaultRem1 = if (hasPermission && usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes1 else defaultReminder1 + val defaultRem2 = if (hasPermission && usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes2 else defaultReminder2 + val defaultRem3 = if (hasPermission && usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes3 else defaultReminder3 + return Triple(defaultRem1, defaultRem2, defaultRem3) + } + var defaultReminder1: Int - get() = prefs.getInt(DEFAULT_REMINDER_1, 10) + get() = getDefault(DEFAULT_REMINDER_1, 10) set(defaultReminder1) = prefs.edit().putInt(DEFAULT_REMINDER_1, defaultReminder1).apply() var defaultReminder2: Int - get() = prefs.getInt(DEFAULT_REMINDER_2, REMINDER_OFF) + get() = getDefault(DEFAULT_REMINDER_2, REMINDER_OFF) set(defaultReminder2) = prefs.edit().putInt(DEFAULT_REMINDER_2, defaultReminder2).apply() var defaultReminder3: Int - get() = prefs.getInt(DEFAULT_REMINDER_3, REMINDER_OFF) + get() = getDefault(DEFAULT_REMINDER_3, REMINDER_OFF) set(defaultReminder3) = prefs.edit().putInt(DEFAULT_REMINDER_3, defaultReminder3).apply() var pullToRefresh: Boolean