Skip to content

Commit

Permalink
Add "Don't show again" checkbox to autostart dialog
Browse files Browse the repository at this point in the history
Resolves part of #149
  • Loading branch information
pilot51 committed Jan 3, 2025
1 parent 6ae859e commit 9b157e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
41 changes: 32 additions & 9 deletions app/src/main/java/com/pilot51/voicenotify/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2024 Mark Injerd
* Copyright 2011-2025 Mark Injerd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,16 +20,21 @@ import android.content.Intent
import android.os.Build
import android.provider.Settings
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand All @@ -40,6 +45,7 @@ import com.judemanutd.autostarter.AutoStartPermissionHelper
import com.pilot51.voicenotify.NotifyList.NotificationLogDialog
import com.pilot51.voicenotify.PermissionHelper.RationaleDialog
import com.pilot51.voicenotify.PermissionHelper.requestPermission
import com.pilot51.voicenotify.PreferenceHelper.KEY_DISABLE_AUTOSTART_MSG
import com.pilot51.voicenotify.db.App
import com.pilot51.voicenotify.db.Settings.Companion.DEFAULT_AUDIO_FOCUS
import com.pilot51.voicenotify.db.Settings.Companion.DEFAULT_IGNORE_EMPTY
Expand Down Expand Up @@ -97,8 +103,10 @@ fun MainScreen(
var showLog by remember { mutableStateOf(false) }
var showBackupRestore by remember { mutableStateOf(false) }
var showSupport by remember { mutableStateOf(false) }
var showAutostartDialog by remember {
mutableStateOf(!Service.isRunning.value && autoStartHelper.isAutoStartPermissionAvailable(context))
val disableAutostartMsg by PreferenceHelper.getPrefFlow(KEY_DISABLE_AUTOSTART_MSG, false).collectAsState(null)
var showAutostartDialog by remember(disableAutostartMsg?.run { true }) {
mutableStateOf(disableAutostartMsg == false && !isRunning &&
autoStartHelper.isAutoStartPermissionAvailable(context))
}
var showReadPhoneStateRationale by remember { mutableStateOf(false) }
var showPostNotificationRationale by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -365,13 +373,28 @@ fun MainScreen(
}
},
text = {
Text(stringResource(R.string.autostart_message) +
stringResource(
if (canOpenDirect) R.string.autostart_message_direct
else R.string.autostart_message_manual,
stringResource(android.R.string.ok)
Column {
Text(
stringResource(R.string.autostart_message) +
stringResource(
if (canOpenDirect) R.string.autostart_message_direct
else R.string.autostart_message_manual,
stringResource(android.R.string.ok)
)
)
)
Row(
modifier = Modifier.padding(top = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Checkbox(
checked = disableAutostartMsg!!,
onCheckedChange = {
PreferenceHelper.setPref(KEY_DISABLE_AUTOSTART_MSG, it)
}
)
Text(stringResource(R.string.dont_show_again))
}
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2024 Mark Injerd
* Copyright 2011-2025 Mark Injerd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,8 @@ import java.util.zip.ZipOutputStream
import kotlin.math.roundToInt

object PreferenceHelper {
val KEY_DISABLE_AUTOSTART_MSG = booleanPreferencesKey("disable_autostart_msg")

// Main
val KEY_SHAKE_THRESHOLD = intPreferencesKey("shake_threshold")

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2011-2024 Mark Injerd
<!-- Copyright 2011-2025 Mark Injerd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,8 +28,9 @@
<string name="permission_rationale_read_phone_state">The phone calls permission is required to prevent Voice Notify from speaking during a call.</string>
<string name="permission_rationale_post_notifications">The post notifications permission is required for Voice Notify to post a test notification.</string>
<string name="autostart_message">For Voice Notify to work reliably on this device, it must be allowed to autostart or run in the background.</string>
<string name="autostart_message_direct">\n\nPress %s to go to the relevant settings screen and enable Voice Notify.</string>
<string name="autostart_message_manual">\n\nSearch in Android Settings for \'autostart\', \'auto-launch\', \'startup\', \'background\', or \'never sleep\' and enable Voice Notify.\n\nThe setting has different names depending on the OS. If you are unable to find it, please contact the developer.\n\nPress %s to open Android Settings.</string>
<string name="autostart_message_direct">\n\nPress %s to go to the relevant settings screen and enable Voice Notify if it isn\'t already.</string>
<string name="autostart_message_manual">\n\nSearch in Android Settings for \'autostart\', \'auto-launch\', \'startup\', \'background\', or \'never sleep\' and enable Voice Notify if it isn\'t already.\n\nThe setting has different names depending on the OS. If you are unable to find it, please contact the developer.\n\nPress %s to open Android Settings.</string>
<string name="dont_show_again">Don\'t show again</string>
<string name="service_disabled">Voice Notify service is disabled</string>
<string name="status_summary_notification_access_enabled">Tap to suspend Voice Notify.\nLong press to open the Android notification access settings to disable the service.</string>
<string name="status_summary_notification_access_disabled">Tap to open the Android notification access settings to enable the service.</string>
Expand Down

0 comments on commit 9b157e7

Please sign in to comment.