require the permission to post notifications in some scenarios on Android 13+
This commit is contained in:
parent
252d4cb9f2
commit
b4c7c8cd7a
8 changed files with 55 additions and 39 deletions
|
@ -70,7 +70,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:b2a2c40a27'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:15c753bd01'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
|
|
|
@ -559,16 +559,6 @@ class EventActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleNotificationAvailability(callback: () -> Unit) {
|
||||
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
|
||||
callback()
|
||||
} else {
|
||||
ConfirmationDialog(this, messageId = R.string.notifications_disabled, positive = R.string.ok, negative = 0) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showReminder1Dialog() {
|
||||
showPickSecondsDialogHelper(mReminder1Minutes, showDuringDayOption = mIsAllDayEvent) {
|
||||
mReminder1Minutes = if (it == -1 || it == 0) it else it / 60
|
||||
|
|
|
@ -1065,17 +1065,23 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
|
||||
private fun tryImportEvents() {
|
||||
if (isQPlus()) {
|
||||
hideKeyboard()
|
||||
Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "text/calendar"
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
hideKeyboard()
|
||||
Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "text/calendar"
|
||||
|
||||
try {
|
||||
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
try {
|
||||
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.system_service_disabled, Toast.LENGTH_LONG)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -250,7 +250,11 @@ class SettingsActivity : SimpleActivity() {
|
|||
if (it) {
|
||||
handlePermission(PERMISSION_READ_CALENDAR) {
|
||||
if (it) {
|
||||
toggleCaldavSync(true)
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
toggleCaldavSync(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,13 @@ import android.content.Context
|
|||
import android.database.ContentObserver
|
||||
import android.os.Handler
|
||||
import android.provider.CalendarContract
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.refreshCalDAVCalendars
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
|
@ -69,4 +72,20 @@ open class SimpleActivity : BaseSimpleActivity() {
|
|||
private fun unregisterObserver() {
|
||||
contentResolver.unregisterContentObserver(calDAVSyncObserver)
|
||||
}
|
||||
|
||||
protected fun handleNotificationAvailability(callback: () -> Unit) {
|
||||
handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
|
||||
callback()
|
||||
} else {
|
||||
ConfirmationDialog(this, messageId = R.string.notifications_disabled, positive = R.string.ok, negative = 0) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -656,16 +656,6 @@ class TaskActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleNotificationAvailability(callback: () -> Unit) {
|
||||
if (NotificationManagerCompat.from(this).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 == -1 || it == 0) it else it / 60
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.simplemobiletools.calendar.pro.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.ANNIVERSARY_EVENT
|
||||
import com.simplemobiletools.calendar.pro.helpers.BIRTHDAY_EVENT
|
||||
|
@ -11,7 +11,7 @@ import com.simplemobiletools.calendar.pro.helpers.REMINDER_OFF
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.dialog_set_reminders.view.*
|
||||
|
||||
class SetRemindersDialog(val activity: Activity, val eventType: Int, val callback: (reminders: ArrayList<Int>) -> Unit) {
|
||||
class SetRemindersDialog(val activity: SimpleActivity, val eventType: Int, val callback: (reminders: ArrayList<Int>) -> Unit) {
|
||||
private var mReminder1Minutes = REMINDER_OFF
|
||||
private var mReminder2Minutes = REMINDER_OFF
|
||||
private var mReminder3Minutes = REMINDER_OFF
|
||||
|
@ -25,11 +25,17 @@ class SetRemindersDialog(val activity: Activity, val eventType: Int, val callbac
|
|||
set_reminders_3.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||
|
||||
set_reminders_1.setOnClickListener {
|
||||
activity.showPickSecondsDialogHelper(mReminder1Minutes, showDuringDayOption = true) {
|
||||
mReminder1Minutes = if (it == -1 || it == 0) it else it / 60
|
||||
set_reminders_1.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||
if (mReminder1Minutes != REMINDER_OFF) {
|
||||
set_reminders_2.beVisible()
|
||||
activity.handleNotificationPermission { granted ->
|
||||
if (granted) {
|
||||
activity.showPickSecondsDialogHelper(mReminder1Minutes, showDuringDayOption = true) {
|
||||
mReminder1Minutes = if (it == -1 || it == 0) it else it / 60
|
||||
set_reminders_1.text = activity.getFormattedMinutes(mReminder1Minutes)
|
||||
if (mReminder1Minutes != REMINDER_OFF) {
|
||||
set_reminders_2.beVisible()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.no_post_notifications_permissions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue