From f5b4b267b3f1d75849e91f2eedea838f39187849 Mon Sep 17 00:00:00 2001 From: Elisha Azaria Date: Thu, 28 Sep 2023 23:17:31 +0300 Subject: [PATCH] Small fixes (notification permissions & other bugs) --- app/proguard-rules.pro | 5 ++++ .../elishaazaria/sayboard/SettingsActivity.kt | 1 + .../sayboard/ui/GrantPermissionsUi.kt | 12 ++++----- .../sayboard/ui/ModelsSettingsUi.kt | 26 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 16bd77d..32cf25d 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,2 +1,7 @@ -keep class com.sun.jna.* { *; } -keepclassmembers class * extends com.sun.jna.* { public *; } + +-dontwarn java.awt.Component +-dontwarn java.awt.GraphicsEnvironment +-dontwarn java.awt.HeadlessException +-dontwarn java.awt.Window \ No newline at end of file diff --git a/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.kt b/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.kt index 4c74d99..7f7cb9a 100644 --- a/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.kt +++ b/app/src/main/java/com/elishaazaria/sayboard/SettingsActivity.kt @@ -145,6 +145,7 @@ class SettingsActivity : ComponentActivity() { companion object { /* Used to handle permission request */ private const val PERMISSIONS_REQUEST_RECORD_AUDIO = 1 + public const val PERMISSION_REQUEST_POST_NOTIFICATIONS = 1 } @Preview diff --git a/app/src/main/java/com/elishaazaria/sayboard/ui/GrantPermissionsUi.kt b/app/src/main/java/com/elishaazaria/sayboard/ui/GrantPermissionsUi.kt index 8bb0dcb..ab62717 100644 --- a/app/src/main/java/com/elishaazaria/sayboard/ui/GrantPermissionsUi.kt +++ b/app/src/main/java/com/elishaazaria/sayboard/ui/GrantPermissionsUi.kt @@ -22,19 +22,19 @@ public fun GrantPermissionUi( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxSize(), ) { - Button(onClick = requestMic, enabled = mic.value) { + Button(onClick = requestMic, enabled = !mic.value) { if (mic.value) { - Text(text = "Grant Microphone Permission") - } else { Text(text = "Microphone Permission Granted") + } else { + Text(text = "Grant Microphone Permission") } } - Button(onClick = requestIme, enabled = ime.value) { + Button(onClick = requestIme, enabled = !ime.value) { if (ime.value) { - Text(text = "Enable IME") - } else { Text(text = "IME enabled") + } else { + Text(text = "Enable IME") } } } diff --git a/app/src/main/java/com/elishaazaria/sayboard/ui/ModelsSettingsUi.kt b/app/src/main/java/com/elishaazaria/sayboard/ui/ModelsSettingsUi.kt index 776ddd5..ccbd54f 100644 --- a/app/src/main/java/com/elishaazaria/sayboard/ui/ModelsSettingsUi.kt +++ b/app/src/main/java/com/elishaazaria/sayboard/ui/ModelsSettingsUi.kt @@ -1,6 +1,10 @@ package com.elishaazaria.sayboard.ui +import android.Manifest +import android.content.pm.PackageManager +import android.os.Build import android.util.Log +import android.widget.Toast import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -38,6 +42,9 @@ import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.DialogProperties +import androidx.core.app.ActivityCompat +import androidx.core.app.NotificationManagerCompat +import androidx.core.content.ContextCompat import androidx.lifecycle.MutableLiveData import com.elishaazaria.sayboard.SettingsActivity import com.elishaazaria.sayboard.Tools @@ -188,6 +195,25 @@ class ModelsSettingsUi(private val activity: SettingsActivity) { ) { FloatingActionButton(onClick = { showDownloadDialog = true + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + val permissionCheck = ContextCompat.checkSelfPermission( + activity.applicationContext, + Manifest.permission.POST_NOTIFICATIONS + ) + if (permissionCheck != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions( + activity, arrayOf( + Manifest.permission.POST_NOTIFICATIONS + ), SettingsActivity.PERMISSION_REQUEST_POST_NOTIFICATIONS + ) + Toast.makeText( + activity, + "Notifications recommended for downloader to work properly", + Toast.LENGTH_LONG + ).show() + } + } }) { Icon(imageVector = Icons.Default.Download, contentDescription = null) }