use the helper function for checking notification permission

This commit is contained in:
tibbi 2022-09-11 18:59:39 +02:00
parent e6dfd2ffac
commit 8f54b59a31
2 changed files with 7 additions and 14 deletions

View File

@ -2,7 +2,6 @@ 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
@ -14,8 +13,8 @@ class BackgroundRecordActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
if (intent.action == RECORD_INTENT_ACTION) {
handlePermission(PERMISSION_POST_NOTIFICATIONS) {
if (it) {
handleNotificationPermission { granted ->
if (granted) {
Intent(this@BackgroundRecordActivity, RecorderService::class.java).apply {
try {
if (RecorderService.isRunning) {

View File

@ -8,9 +8,7 @@ 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
@ -49,17 +47,13 @@ class RecorderFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
updateRecordingDuration(0)
toggle_recording_button.setOnClickListener {
if (isTiramisuPlus()) {
(context as? BaseSimpleActivity)?.handlePermission(PERMISSION_POST_NOTIFICATIONS) {
if (it) {
(context as? BaseSimpleActivity)?.handleNotificationPermission { granted ->
if (granted) {
toggleRecording()
} else {
context.toast(R.string.no_post_notifications_permissions)
}
}
} else {
toggleRecording()
}
}
toggle_pause_button.setOnClickListener {