1
1
package li.songe.gkd.ui.home
2
2
3
+ import androidx.activity.compose.LocalActivity
3
4
import androidx.compose.animation.AnimatedVisibility
4
5
import androidx.compose.foundation.clickable
5
6
import androidx.compose.foundation.layout.Arrangement
6
7
import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.PaddingValues
7
9
import androidx.compose.foundation.layout.Row
8
10
import androidx.compose.foundation.layout.Spacer
9
11
import androidx.compose.foundation.layout.fillMaxWidth
@@ -32,12 +34,15 @@ import androidx.compose.ui.Alignment
32
34
import androidx.compose.ui.Modifier
33
35
import androidx.compose.ui.input.nestedscroll.nestedScroll
34
36
import androidx.compose.ui.text.style.TextAlign
37
+ import androidx.compose.ui.unit.dp
35
38
import androidx.compose.ui.window.DialogProperties
36
39
import androidx.lifecycle.viewmodel.compose.viewModel
40
+ import com.blankj.utilcode.util.KeyboardUtils
37
41
import com.ramcosta.composedestinations.generated.destinations.AboutPageDestination
38
42
import com.ramcosta.composedestinations.generated.destinations.AdvancedPageDestination
39
43
import kotlinx.coroutines.flow.update
40
44
import li.songe.gkd.store.storeFlow
45
+ import li.songe.gkd.ui.component.CustomOutlinedTextField
41
46
import li.songe.gkd.ui.component.SettingItem
42
47
import li.songe.gkd.ui.component.TextMenu
43
48
import li.songe.gkd.ui.component.TextSwitch
@@ -50,10 +55,12 @@ import li.songe.gkd.ui.theme.supportDynamicColor
50
55
import li.songe.gkd.util.DarkThemeOption
51
56
import li.songe.gkd.util.findOption
52
57
import li.songe.gkd.util.throttle
58
+ import li.songe.gkd.util.toast
53
59
54
60
@Composable
55
61
fun useSettingsPage (): ScaffoldExt {
56
62
val mainVm = LocalMainViewModel .current
63
+ val activity = LocalActivity .current
57
64
val store by storeFlow.collectAsState()
58
65
val vm = viewModel<HomeVm >()
59
66
@@ -64,7 +71,6 @@ fun useSettingsPage(): ScaffoldExt {
64
71
mutableStateOf(false )
65
72
}
66
73
67
-
68
74
if (showToastInputDlg) {
69
75
var value by remember {
70
76
mutableStateOf(store.clickToast)
@@ -116,9 +122,8 @@ fun useSettingsPage(): ScaffoldExt {
116
122
)
117
123
}
118
124
if (showNotifTextInputDlg) {
119
- var value by remember {
120
- mutableStateOf(store.customNotifText)
121
- }
125
+ var titleValue by remember { mutableStateOf(store.customNotifTitle) }
126
+ var textValue by remember { mutableStateOf(store.customNotifText) }
122
127
AlertDialog (
123
128
properties = DialogProperties (dismissOnClickOutside = false ),
124
129
title = {
@@ -129,9 +134,17 @@ fun useSettingsPage(): ScaffoldExt {
129
134
) {
130
135
Text (text = " 通知文案" )
131
136
IconButton (onClick = throttle {
137
+ KeyboardUtils .hideSoftInput(activity)
138
+ showNotifTextInputDlg = false
139
+ val confirmAction = {
140
+ mainVm.dialogFlow.value = null
141
+ showNotifTextInputDlg = true
142
+ }
132
143
mainVm.dialogFlow.updateDialogOptions(
133
144
title = " 文案规则" ,
134
- text = " 通知文案支持变量替换,规则如下\n \$ {i} 全局规则数\n \$ {k} 应用数\n \$ {u} 应用规则组数\n \$ {n} 触发次数\n\n 示例模板\n \$ {i}全局/\$ {k}应用/\$ {u}规则组/\$ {n}触发\n\n 替换结果\n 0全局/1应用/2规则组/3触发" ,
145
+ text = " 通知文案支持变量替换,规则如下\n \$ {i} 全局规则数\n \$ {k} 应用数\n \$ {u} 应用规则组数\n \$ {n} 触发次数\n\n 示例模板\n \$ {i}全局/\$ {k}应用/\$ {u}规则组/\$ {n}触发\n\n 替换结果\n 0全局/1应用/2规则组/3触发" ,
146
+ confirmAction = confirmAction,
147
+ onDismissRequest = confirmAction,
135
148
)
136
149
}) {
137
150
Icon (
@@ -142,35 +155,67 @@ fun useSettingsPage(): ScaffoldExt {
142
155
}
143
156
},
144
157
text = {
145
- val maxCharLen = 64
146
- OutlinedTextField (
147
- value = value,
148
- placeholder = {
149
- Text (text = " 请输入文案内容,支持变量替换" )
150
- },
151
- onValueChange = {
152
- value = if (it.length > maxCharLen) it.take(maxCharLen) else it
153
- },
154
- maxLines = 4 ,
155
- supportingText = {
156
- Text (
157
- text = " ${value.length} / $maxCharLen " ,
158
- modifier = Modifier .fillMaxWidth(),
159
- textAlign = TextAlign .End ,
160
- )
161
- },
162
- modifier = Modifier
163
- .fillMaxWidth()
164
- .autoFocus()
165
- )
158
+ val titleMaxLen = 32
159
+ val textMaxLen = 64
160
+ Column (
161
+ modifier = Modifier .fillMaxWidth(),
162
+ ) {
163
+ CustomOutlinedTextField (
164
+ label = { Text (" 主标题" ) },
165
+ value = titleValue,
166
+ placeholder = { Text (text = " 请输入内容,支持变量替换" ) },
167
+ onValueChange = {
168
+ titleValue = (if (it.length > titleMaxLen) it.take(titleMaxLen) else it)
169
+ .filter { c -> c !in " \n\r " }
170
+ },
171
+ supportingText = {
172
+ Text (
173
+ text = " ${titleValue.length} / $titleMaxLen " ,
174
+ modifier = Modifier .fillMaxWidth(),
175
+ textAlign = TextAlign .End ,
176
+ )
177
+ },
178
+ singleLine = true ,
179
+ modifier = Modifier .fillMaxWidth(),
180
+ contentPadding = PaddingValues (12 .dp),
181
+ )
182
+ Spacer (modifier = Modifier .height(4 .dp))
183
+ CustomOutlinedTextField (
184
+ label = { Text (" 副标题" ) },
185
+ value = textValue,
186
+ placeholder = { Text (text = " 请输入内容,支持变量替换" ) },
187
+ onValueChange = {
188
+ textValue = if (it.length > textMaxLen) it.take(textMaxLen) else it
189
+ },
190
+ supportingText = {
191
+ Text (
192
+ text = " ${textValue.length} / $textMaxLen " ,
193
+ modifier = Modifier .fillMaxWidth(),
194
+ textAlign = TextAlign .End ,
195
+ )
196
+ },
197
+ maxLines = 4 ,
198
+ modifier = Modifier
199
+ .fillMaxWidth()
200
+ .autoFocus(),
201
+ contentPadding = PaddingValues (12 .dp),
202
+ )
203
+ }
166
204
},
167
205
onDismissRequest = {
168
206
showNotifTextInputDlg = false
169
207
},
170
208
confirmButton = {
171
- TextButton (enabled = value.isNotEmpty(), onClick = {
172
- storeFlow.update { it.copy(customNotifText = value) }
209
+ TextButton (onClick = {
210
+ KeyboardUtils .hideSoftInput(activity)
211
+ storeFlow.update {
212
+ it.copy(
213
+ customNotifTitle = titleValue,
214
+ customNotifText = textValue
215
+ )
216
+ }
173
217
showNotifTextInputDlg = false
218
+ toast(" 更新成功" )
174
219
}) {
175
220
Text (
176
221
text = " 确认" ,
@@ -247,7 +292,11 @@ fun useSettingsPage(): ScaffoldExt {
247
292
val subsStatus by vm.subsStatusFlow.collectAsState()
248
293
TextSwitch (
249
294
title = " 通知文案" ,
250
- subtitle = if (store.useCustomNotifText) store.customNotifText else subsStatus,
295
+ subtitle = if (store.useCustomNotifText) {
296
+ store.customNotifTitle + " / " + store.customNotifText
297
+ } else {
298
+ subsStatus
299
+ },
251
300
checked = store.useCustomNotifText,
252
301
modifier = Modifier .clickable {
253
302
showNotifTextInputDlg = true
0 commit comments