Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no notification permission issue #221

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
addImportIdsToTasks {
refreshViewPager()
}

handlePermission(PERMISSION_POST_NOTIFICATIONS) {}
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 24 additions & 3 deletions app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Comment on lines +187 to +188
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with the extension function used in all Fossify apps:

hasPermission(PERMISSION_POST_NOTIFICATIONS)

return prefs.getInt(reminder, defValue)
} else {
return REMINDER_OFF
}
}

val defaultReminders: Triple<Int, Int, Int>
get() {
val hasPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with the extension function used in all Fossify apps:

hasPermission(PERMISSION_POST_NOTIFICATIONS)

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
Expand Down