Skip to content

Commit

Permalink
feat: customNotifText
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Aug 4, 2024
1 parent fdde05e commit 6747d87
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 39 deletions.
10 changes: 6 additions & 4 deletions app/src/main/kotlin/li/songe/gkd/service/ManageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRuleExcludePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 6 additions & 11 deletions app/src/main/kotlin/li/songe/gkd/ui/component/TextSwitch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
82 changes: 74 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/home/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -104,7 +107,9 @@ fun useSettingsPage(): ScaffoldExt {
OutlinedTextField(
value = value,
placeholder = {
Text(text = "请输入提示内容")
Text(
text = "请输入提示内容",
)
},
onValueChange = {
value = it.take(maxCharLen)
Expand All @@ -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(
Expand All @@ -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 }) {
Expand Down Expand Up @@ -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
)
})

Expand All @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/kotlin/li/songe/gkd/ui/home/SubsManagePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/util/Store.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6747d87

Please sign in to comment.