Skip to content

Commit

Permalink
Allow long press on status row to open notification access settings
Browse files Browse the repository at this point in the history
Add version name to bottom of Help & Support dialog.
Fix preference rows not resizing if summary changes to 3+ lines.
Fix PreferenceRowCheckbox previews.
  • Loading branch information
pilot51 committed Jan 1, 2024
1 parent 78525ab commit 467a088
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 115 deletions.
13 changes: 5 additions & 8 deletions app/src/main/java/com/pilot51/voicenotify/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,16 @@ private fun MainScreen(
} else null
var statusTitle by remember { mutableStateOf("") }
var statusSummary by remember { mutableStateOf("") }
var statusIntent by remember { mutableStateOf<Intent?>(null) }
val statusIntent = remember { Common.notificationListenerSettingsIntent }
if (isPreview) {
statusTitle = context.getString(R.string.service_running)
statusSummary = context.getString(R.string.status_summary_notification_access_enabled)
statusIntent = null
}
val isRunning by Service.isRunning.collectAsState()
val isSuspended by Service.isSuspended.collectAsState()
if (isSuspended && isRunning) {
statusTitle = stringResource(R.string.service_suspended)
statusSummary = stringResource(R.string.status_summary_suspended)
statusIntent = null
} else {
statusTitle = stringResource(
if (isRunning) R.string.service_running else R.string.service_disabled
Expand All @@ -184,7 +182,6 @@ private fun MainScreen(
R.string.status_summary_notification_access_disabled
}
)
statusIntent = Common.notificationListenerSettingsIntent
}
var showShakeToSilence by remember { mutableStateOf(false) }
var showRequireText by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -222,10 +219,10 @@ private fun MainScreen(
title = statusTitle,
subtitle = statusSummary,
onClick = {
if (!isRunning) {
statusIntent?.let { context.startActivity(it) }
} else Service.toggleSuspend()
}
if (isRunning) Service.toggleSuspend()
else context.startActivity(statusIntent)
},
onLongClick = { context.startActivity(statusIntent) }
)
PreferenceRowLink(
title = R.string.app_list,
Expand Down
148 changes: 79 additions & 69 deletions app/src/main/java/com/pilot51/voicenotify/PreferenceDialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -450,83 +450,93 @@ fun SupportDialog(onDismiss: () -> Unit) {
title = { Text(stringResource(R.string.support)) },
text = {
val items = stringArrayResource(R.array.support_items)
LazyColumn {
items(items) { item ->
Text(
text = item,
modifier = Modifier
.clickable {
when (item) {
rate -> {
val iMarket = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.pilot51.voicenotify")
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(iMarket)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
Toast
.makeText(
context, R.string.error_market, Toast.LENGTH_LONG
)
.show()
}
}
contact -> {
val iEmail = Intent(Intent.ACTION_SEND).apply {
type = "plain/text"
putExtra(Intent.EXTRA_EMAIL, arrayOf(devEmail))
putExtra(Intent.EXTRA_SUBJECT, emailSubject)
putExtra(Intent.EXTRA_TEXT, emailBody)
Column {
LazyColumn {
items(items) { item ->
Text(
text = item,
modifier = Modifier
.clickable {
when (item) {
rate -> {
val iMarket = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.pilot51.voicenotify")
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(iMarket)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
Toast
.makeText(
context, R.string.error_market, Toast.LENGTH_LONG
)
.show()
}
}
try {
context.startActivity(iEmail)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
Toast
.makeText(
context, R.string.error_email, Toast.LENGTH_LONG
)
.show()
contact -> {
val iEmail = Intent(Intent.ACTION_SEND).apply {
type = "plain/text"
putExtra(Intent.EXTRA_EMAIL, arrayOf(devEmail))
putExtra(Intent.EXTRA_SUBJECT, emailSubject)
putExtra(Intent.EXTRA_TEXT, emailBody)
}
try {
context.startActivity(iEmail)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
Toast
.makeText(
context, R.string.error_email, Toast.LENGTH_LONG
)
.show()
}
}
}
discord -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://discord.gg/W6XxGT8WG3")
discord -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://discord.gg/W6XxGT8WG3")
)
)
)
matrix -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://matrix.to/#/#voicenotify:p51.me")
matrix -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://matrix.to/#/#voicenotify:p51.me")
)
)
)
translations -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://hosted.weblate.org/projects/voice-notify")
translations -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://hosted.weblate.org/projects/voice-notify")
)
)
)
source -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/pilot51/voicenotify")
source -> context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/pilot51/voicenotify")
)
)
)
privacy -> showPrivacy = true
privacy -> showPrivacy = true
}
}
}
.fillMaxWidth()
.heightIn(min = 56.dp)
.wrapContentHeight(align = Alignment.CenterVertically)
.padding(horizontal = 16.dp),
fontSize = 16.sp
)
.wrapContentWidth()
.heightIn(min = 56.dp)
.wrapContentHeight(align = Alignment.CenterVertically)
.padding(horizontal = 16.dp),
fontSize = 16.sp
)
}
}
Text(
text = BuildConfig.VERSION_NAME,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(top = 10.dp)
,
fontSize = 12.sp
)
}
}
)
Expand Down
59 changes: 24 additions & 35 deletions app/src/main/java/com/pilot51/voicenotify/PreferenceRows.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
package com.pilot51.voicenotify

import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material3.*
Expand All @@ -33,7 +34,6 @@ import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import com.pilot51.voicenotify.PreferenceHelper.KEY_IGNORE_GROUPS
import com.pilot51.voicenotify.PreferenceHelper.prefs
import kotlin.reflect.KProperty

Expand All @@ -44,36 +44,37 @@ fun PreferenceRowLink(
@StringRes title: Int,
@StringRes subtitle: Int,
onClick: () -> Unit
) {
PreferenceRowLink(
title = stringResource(title),
subtitle = stringResource(subtitle),
onClick = onClick
)
}
) = PreferenceRowLink(
title = stringResource(title),
subtitle = stringResource(subtitle),
onClick = onClick
)

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PreferenceRowLink(
enabled: Boolean = true,
title: String,
subtitle: String,
onClick: () -> Unit
onClick: () -> Unit,
onLongClick: (() -> Unit)? = null
) {
Surface {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(
.height(IntrinsicSize.Min)
.combinedClickable(
enabled = enabled,
onClick = onClick
onClick = onClick,
onLongClick = onLongClick
),
verticalAlignment = Alignment.CenterVertically
) {
PreferenceRowScaffold(
title = title,
enabled = enabled,
subtitle = subtitle,
actionDivider = true
subtitle = subtitle
)
}
}
Expand All @@ -92,6 +93,7 @@ fun PreferenceRowCheckbox(
Row(
modifier = Modifier
.fillMaxWidth()
.height(IntrinsicSize.Min)
.toggleable(
value = prefValue,
role = Role.Checkbox,
Expand All @@ -117,13 +119,10 @@ private fun PreferenceRowScaffold(
enabled: Boolean = true,
title: String,
subtitle: String,
action: (@Composable (Boolean) -> Unit)? = null,
actionDivider: Boolean = false
action: (@Composable (Boolean) -> Unit)? = null
) {
ListItem(
modifier = Modifier
.height(IntrinsicSize.Min)
.defaultMinSize(minHeight = 88.dp),
modifier = Modifier.defaultMinSize(minHeight = 88.dp),
headlineContent = {
ColorWrap(enabled) {
Text(title)
Expand All @@ -140,18 +139,6 @@ private fun PreferenceRowScaffold(
modifier = Modifier.fillMaxHeight(),
verticalAlignment = Alignment.CenterVertically
) {
if (actionDivider) {
Divider(
color = DividerDefaults.color.let {
if (enabled) it else it.copy(alpha = 0.6f)
},
modifier = Modifier
.padding(vertical = 4.dp)
.fillMaxHeight()
.width(1.dp),
)
Spacer(modifier = Modifier.width(2.dp))
}
action(enabled)
}
}
Expand All @@ -172,11 +159,13 @@ private fun ColorWrap(
}
}

class PreferenceBooleanState(
private class PreferenceBooleanState(
val key: String,
val defaultValue: Boolean
) {
private var _value by mutableStateOf(prefs.getBoolean(key, defaultValue))
private var _value by mutableStateOf(
if (key == "isPreview") defaultValue else prefs.getBoolean(key, defaultValue)
)
var value: Boolean
set(value) {
_value = value
Expand Down Expand Up @@ -219,7 +208,7 @@ private fun SettingsCheckboxCheckedPreview() {
PreferenceRowCheckbox(
title = R.string.ignore_groups,
subtitle = R.string.ignore_groups_summary_on,
key = KEY_IGNORE_GROUPS,
key = "isPreview",
default = true
)
}
Expand All @@ -232,7 +221,7 @@ private fun SettingsCheckboxUncheckedPreview() {
PreferenceRowCheckbox(
title = R.string.ignore_groups,
subtitle = R.string.ignore_groups_summary_off,
key = KEY_IGNORE_GROUPS,
key = "isPreview",
default = false
)
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,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="service_disabled">Voice Notify service is disabled</string>
<string name="status_summary_notification_access_enabled">Open the Android notification access settings to disable Voice Notify</string>
<string name="status_summary_notification_access_disabled">Open the Android notification access settings to enable Voice Notify</string>
<string name="status_summary_suspended">Select to activate Voice Notify.</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>
<string name="status_summary_suspended">Tap to activate Voice Notify.\nLong press to open the Android notification access settings to disable the service.</string>
<string name="app_list">App List</string>
<string name="app_list_summary">List installed apps which can be ignored</string>
<string name="tts">Text-To-Speech</string>
Expand Down

0 comments on commit 467a088

Please sign in to comment.