add handling for the new Post Notifications permission

This commit is contained in:
tibbi 2022-08-29 10:48:19 +02:00
parent 89ff5cdb1f
commit dc9cd511a8
7 changed files with 43 additions and 12 deletions

View file

@ -63,7 +63,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b2a2c40a27'
implementation 'com.github.SimpleMobileTools:Simple-Commons:7cfc56e855'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.github.Armen101:AudioRecordView:1.0.4'
implementation 'androidx.documentfile:documentfile:1.0.1'

View file

@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />

View file

@ -1,6 +1,9 @@
package com.simplemobiletools.voicerecorder.activities
import android.content.Intent
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_POST_NOTIFICATIONS
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.services.RecorderService
class BackgroundRecordActivity : SimpleActivity() {
@ -11,14 +14,20 @@ class BackgroundRecordActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
if (intent.action == RECORD_INTENT_ACTION) {
Intent(this@BackgroundRecordActivity, RecorderService::class.java).apply {
try {
if (RecorderService.isRunning) {
stopService(this)
} else {
startService(this)
handlePermission(PERMISSION_POST_NOTIFICATIONS) {
if (it) {
Intent(this@BackgroundRecordActivity, RecorderService::class.java).apply {
try {
if (RecorderService.isRunning) {
stopService(this)
} else {
startService(this)
}
} catch (ignored: Exception) {
}
}
} catch (ignored: Exception) {
} else {
toast(R.string.no_post_notifications_permissions)
}
}
}

View file

@ -6,8 +6,11 @@ import android.graphics.drawable.Drawable
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_POST_NOTIFICATIONS
import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.helpers.isTiramisuPlus
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.helpers.*
import com.simplemobiletools.voicerecorder.models.Events
@ -25,7 +28,10 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
override fun onResume() {
setupColors()
if (!RecorderService.isRunning) status = RECORDING_STOPPED
if (!RecorderService.isRunning) {
status = RECORDING_STOPPED
}
refreshView()
}
@ -43,7 +49,17 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
updateRecordingDuration(0)
toggle_recording_button.setOnClickListener {
toggleRecording()
if (isTiramisuPlus()) {
(context as? BaseSimpleActivity)?.handlePermission(PERMISSION_POST_NOTIFICATIONS) {
if (it) {
toggleRecording()
} else {
context.toast(R.string.no_post_notifications_permissions)
}
}
} else {
toggleRecording()
}
}
toggle_pause_button.setOnClickListener {

View file

@ -50,7 +50,8 @@ class MyWidgetRecordDisplayProvider : AppWidgetProvider() {
private fun setupAppOpenIntent(context: Context, views: RemoteViews) {
Intent(context, BackgroundRecordActivity::class.java).apply {
action = BackgroundRecordActivity.RECORD_INTENT_ACTION
val pendingIntent = PendingIntent.getActivity(context, OPEN_APP_INTENT_ID, this, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val pendingIntent =
PendingIntent.getActivity(context, OPEN_APP_INTENT_ID, this, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.record_display_btn, pendingIntent)
}
}

View file

@ -13,7 +13,9 @@ import android.provider.MediaStore
import android.provider.MediaStore.Audio.Media
import androidx.core.app.NotificationCompat
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.activities.SplashActivity
import com.simplemobiletools.voicerecorder.extensions.config

View file

@ -66,6 +66,7 @@
android:layout_centerVertical="true"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin" />
</RelativeLayout>
<Button
@ -75,6 +76,7 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/small_margin"
android:text="@string/ok" />
</RelativeLayout>