Merge pull request #693 from wilsonrc/feature/AddExactAlarmPermissionDialog

add asking for Exact alarm permission before scheduling
This commit is contained in:
Tibor Kaputa 2023-07-19 07:28:59 +02:00 committed by GitHub
commit 4501e2fe6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 6 deletions

View File

@ -63,7 +63,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b4cc381943'
implementation 'com.github.SimpleMobileTools:Simple-Commons:57a5db1ef3'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'com.github.tibbi:android-smsmms:5657799572'

View File

@ -251,7 +251,10 @@ class MainActivity : SimpleActivity() {
handlePermission(PERMISSION_READ_CONTACTS) {
handleNotificationPermission { granted ->
if (!granted) {
PermissionRequiredDialog(this, R.string.allow_notifications_incoming_messages)
PermissionRequiredDialog(
activity = this,
textId = R.string.allow_notifications_incoming_messages,
positiveActionCallback = { openNotificationSettings() })
}
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.activities
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlarmManager
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.res.ColorStateList
@ -9,9 +10,11 @@ import android.graphics.BitmapFactory
import android.graphics.drawable.LayerDrawable
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.ContactsContract
import android.provider.MediaStore
import android.provider.Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
import android.provider.Telephony
import android.provider.Telephony.Sms.MESSAGE_TYPE_QUEUED
import android.provider.Telephony.Sms.STATUS_NONE
@ -44,6 +47,7 @@ import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
@ -51,6 +55,7 @@ import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.smsmessenger.BuildConfig
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.AttachmentsAdapter
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
@ -75,6 +80,7 @@ import org.joda.time.DateTime
import java.io.File
import java.io.InputStream
import java.io.OutputStream
import java.security.acl.Permission
class ThreadActivity : SimpleActivity() {
private val MIN_DATE_TIME_DIFF_SECS = 300
@ -710,6 +716,25 @@ class ThreadActivity : SimpleActivity() {
setupScheduleSendUi()
}
private fun askForExactAlarmPermissionIfNeeded(callback: () -> Unit = {}) {
if (isSPlus()) {
val alarmManager: AlarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
if (alarmManager.canScheduleExactAlarms()) {
callback()
} else {
PermissionRequiredDialog(
activity = this,
textId = R.string.allow_alarm_scheduled_messages,
positiveActionCallback = {
openRequestExactAlarmSettings(BuildConfig.APPLICATION_ID)
},
)
}
} else {
callback()
}
}
private fun setupAttachmentSizes() {
messages.filter { it.attachment != null }.forEach { message ->
message.attachment!!.attachments.forEach {
@ -1529,6 +1554,7 @@ class ThreadActivity : SimpleActivity() {
}
private fun launchScheduleSendDialog(originalDateTime: DateTime? = null) {
askForExactAlarmPermissionIfNeeded {
ScheduleMessageDialog(this, originalDateTime) { newDateTime ->
if (newDateTime != null) {
scheduledDateTime = newDateTime
@ -1536,6 +1562,7 @@ class ThreadActivity : SimpleActivity() {
}
}
}
}
private fun setupScheduleSendUi() {
val textColor = getProperTextColor()