feat: customNotifText
Some checks are pending
Build-Apk / build (push) Waiting to run

This commit is contained in:
lisonge 2024-08-05 01:43:47 +08:00
parent fdde05edaa
commit 6747d87459
7 changed files with 97 additions and 39 deletions

View File

@ -16,7 +16,6 @@ import li.songe.gkd.notif.abNotif
import li.songe.gkd.notif.createNotif
import li.songe.gkd.notif.defaultChannel
import li.songe.gkd.util.clickCountFlow
import li.songe.gkd.util.map
import li.songe.gkd.util.ruleSummaryFlow
import li.songe.gkd.util.storeFlow
@ -29,11 +28,14 @@ class ManageService : CompositionService({
combine(
ruleSummaryFlow,
clickCountFlow,
storeFlow.map(scope) { it.enableService },
storeFlow,
GkdAbService.isRunning
) { allRules, clickCount, enableService, abRunning ->
) { allRules, clickCount, store, abRunning ->
if (!abRunning) return@combine "无障碍未授权"
if (!enableService) return@combine "服务已暂停"
if (!store.enableService) return@combine "服务已暂停"
if (store.useCustomNotifText) {
return@combine store.customNotifText.replace("$" + "{count}", clickCount.toString())
}
allRules.numText + if (clickCount > 0) {
"/${clickCount}点击"
} else {

View File

@ -27,6 +27,7 @@ import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
@ -51,7 +52,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ClipboardUtils
@ -477,12 +477,12 @@ fun AppItemPage(
.focusRequester(focusRequester),
placeholder = {
Text(
fontSize = 12.sp,
text = "请填入需要禁用的 activityId\n以换行或英文逗号分割"
text = "请填入需要禁用的 activityId\n以换行或英文逗号分割",
style = LocalTextStyle.current.copy(fontSize = MaterialTheme.typography.bodySmall.fontSize)
)
},
maxLines = 10,
textStyle = MaterialTheme.typography.bodySmall.copy(fontSize = 12.sp)
textStyle = LocalTextStyle.current.copy(fontSize = MaterialTheme.typography.bodySmall.fontSize)
)
LaunchedEffect(null) {
focusRequester.requestFocus()

View File

@ -30,6 +30,7 @@ import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.RadioButton
@ -55,7 +56,6 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
import com.google.accompanist.drawablepainter.rememberDrawablePainter
@ -377,11 +377,12 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
.focusRequester(focusRequester),
placeholder = {
Text(
fontSize = 12.sp,
text = tipText
text = tipText,
style = LocalTextStyle.current.copy(fontSize = MaterialTheme.typography.bodySmall.fontSize)
)
},
maxLines = 10,
textStyle = LocalTextStyle.current.copy(fontSize = MaterialTheme.typography.bodySmall.fontSize)
)
LaunchedEffect(null) {
focusRequester.requestFocus()

View File

@ -27,23 +27,18 @@ fun TextSwitch(
modifier = modifier.itemPadding(),
verticalAlignment = Alignment.CenterVertically
) {
if (desc != null) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = name,
style = MaterialTheme.typography.bodyLarge,
)
Column(modifier = Modifier.weight(1f)) {
Text(
text = name,
style = MaterialTheme.typography.bodyLarge,
)
if (desc != null) {
Text(
text = desc,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
} else {
Text(
text = name,
style = MaterialTheme.typography.bodyLarge,
)
}
Spacer(modifier = Modifier.width(10.dp))
Switch(

View File

@ -88,6 +88,9 @@ fun useSettingsPage(): ScaffoldExt {
var showToastInputDlg by remember {
mutableStateOf(false)
}
var showNotifTextInputDlg by remember {
mutableStateOf(false)
}
var showShareLogDlg by remember {
mutableStateOf(false)
@ -104,7 +107,9 @@ fun useSettingsPage(): ScaffoldExt {
OutlinedTextField(
value = value,
placeholder = {
Text(text = "请输入提示内容")
Text(
text = "请输入提示内容",
)
},
onValueChange = {
value = it.take(maxCharLen)
@ -120,9 +125,7 @@ fun useSettingsPage(): ScaffoldExt {
)
}, onDismissRequest = { showToastInputDlg = false }, confirmButton = {
TextButton(enabled = value.isNotEmpty(), onClick = {
storeFlow.value = store.copy(
clickToast = value
)
storeFlow.update { it.copy(clickToast = value) }
showToastInputDlg = false
}) {
Text(
@ -137,6 +140,46 @@ fun useSettingsPage(): ScaffoldExt {
}
})
}
if (showNotifTextInputDlg) {
var value by remember {
mutableStateOf(store.customNotifText)
}
val maxCharLen = 64
AlertDialog(title = { Text(text = "通知文案") }, text = {
OutlinedTextField(
value = value,
placeholder = {
Text(text = "请输入文案内容")
},
onValueChange = {
value = it.take(maxCharLen)
},
singleLine = true,
supportingText = {
Text(
text = "${value.length} / $maxCharLen",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
)
},
)
}, onDismissRequest = { showNotifTextInputDlg = false }, confirmButton = {
TextButton(enabled = value.isNotEmpty(), onClick = {
storeFlow.update { it.copy(customNotifText = value) }
showNotifTextInputDlg = false
}) {
Text(
text = "确认",
)
}
}, dismissButton = {
TextButton(onClick = { showNotifTextInputDlg = false }) {
Text(
text = "取消",
)
}
})
}
if (showShareLogDlg) {
Dialog(onDismissRequest = { showShareLogDlg = false }) {
@ -289,13 +332,29 @@ fun useSettingsPage(): ScaffoldExt {
)
})
if (store.toastWhenClick) {
TextSwitch(
name = "系统提示",
desc = "系统样式触发提示,频率较高时不显示",
checked = store.useSystemToast,
onCheckedChange = {
storeFlow.value = store.copy(
useSystemToast = it
)
})
}
val subsStatus by vm.subsStatusFlow.collectAsState()
TextSwitch(
name = "系统提示",
desc = "系统样式触发提示,频率较高时不显示",
checked = store.useSystemToast,
name = "通知文案",
desc = if (store.useCustomNotifText) store.customNotifText else subsStatus,
checked = store.useCustomNotifText,
modifier = Modifier.clickable {
showNotifTextInputDlg = true
},
onCheckedChange = {
storeFlow.value = store.copy(
useSystemToast = it
useCustomNotifText = it
)
})
@ -309,6 +368,13 @@ fun useSettingsPage(): ScaffoldExt {
)
})
Text(
text = "主题",
modifier = Modifier.titleItemPadding(),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.primary,
)
TextMenu(
title = "深色模式",
option = DarkThemeOption.allSubObject.findOption(store.enableDarkTheme)

View File

@ -23,8 +23,6 @@ import androidx.compose.material.icons.automirrored.filled.FormatListBulleted
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.Upgrade
import androidx.compose.material.icons.filled.Upload
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material3.AlertDialog
@ -34,7 +32,6 @@ import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
@ -55,7 +52,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope
@ -143,13 +139,9 @@ fun useSubsManagePage(): ScaffoldExt {
value = link,
onValueChange = { link = it.trim() },
maxLines = 8,
textStyle = LocalTextStyle.current.copy(fontSize = 14.sp),
modifier = Modifier.fillMaxWidth(),
placeholder = {
Text(
text = "请输入订阅链接",
style = LocalTextStyle.current.copy(fontSize = 14.sp)
)
Text(text = "请输入订阅链接")
},
isError = link.isNotEmpty() && !URLUtil.isNetworkUrl(link),
)

View File

@ -64,6 +64,8 @@ data class Store(
val showHiddenApp: Boolean = false,
val showSaveSnapshotToast: Boolean = true,
val useSystemToast: Boolean = false,
val useCustomNotifText: Boolean = false,
val customNotifText: String = "GKD",
)
val storeFlow by lazy {