Skip to content

Commit be366d6

Browse files
committed
禁止编辑系统预置特性的名称
- 新增 `ConfigMergeManager.isFeatureInSystemBaseline` 方法,用于判断特性是否为系统基线中存在的特性。 - 在编辑特性对话框中,如果特性为系统预置特性,则特性名称输入框设为只读,禁止编辑。 - 添加相关字符串资源 `system_feature_name_readonly_hint`。
1 parent a94f1a6 commit be366d6

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

app/src/main/java/com/itosfish/colorfeatureenhance/config/ConfigMergeManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ object ConfigMergeManager {
205205
* @param isAppFeature 是否为app-features模式
206206
* @return true表示存在于系统基线中
207207
*/
208-
private suspend fun isFeatureInSystemBaseline(featureName: String, isAppFeature: Boolean): Boolean = withContext(Dispatchers.IO) {
208+
suspend fun isFeatureInSystemBaseline(featureName: String, isAppFeature: Boolean): Boolean = withContext(Dispatchers.IO) {
209209
return@withContext try {
210210
if (isAppFeature) {
211211
val systemFile = File(configPaths.systemBaselineDir, configPaths.appFeaturesFile)

app/src/main/java/com/itosfish/colorfeatureenhance/utils/DialogUtil.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.material3.Switch
2020
import androidx.compose.material3.Text
2121
import androidx.compose.material3.TextButton
2222
import androidx.compose.runtime.Composable
23+
import androidx.compose.runtime.LaunchedEffect
2324
import androidx.compose.runtime.getValue
2425
import androidx.compose.runtime.mutableStateOf
2526
import androidx.compose.runtime.remember
@@ -31,6 +32,7 @@ import androidx.compose.ui.unit.dp
3132
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3233
import com.itosfish.colorfeatureenhance.FeatureMode
3334
import com.itosfish.colorfeatureenhance.R
35+
import com.itosfish.colorfeatureenhance.config.ConfigMergeManager
3436
import com.itosfish.colorfeatureenhance.data.model.AppFeature
3537
import com.itosfish.colorfeatureenhance.data.model.AppFeatureMappings
3638
import com.itosfish.colorfeatureenhance.data.model.FeatureSubNode
@@ -257,6 +259,15 @@ fun EditFeatureDialog(
257259
var featureDescription by remember { mutableStateOf(originalDescription) }
258260
var featureEnabled by remember { mutableStateOf(originalEnabled) }
259261
var argValue by remember { mutableStateOf(originalArgs ?: "") }
262+
var isSystemFeature by remember { mutableStateOf(false) }
263+
264+
// 检查是否为系统存在的特性配置
265+
LaunchedEffect(originalName) {
266+
isSystemFeature = ConfigMergeManager.isFeatureInSystemBaseline(
267+
originalName,
268+
currentMode == FeatureMode.APP
269+
)
270+
}
260271

261272
// 检查是否为预设描述
262273
val isPresetDesc = if (currentMode == FeatureMode.APP) {
@@ -292,11 +303,23 @@ fun EditFeatureDialog(
292303
Spacer(modifier = Modifier.height(16.dp))
293304
OutlinedTextField(
294305
value = featureName,
295-
onValueChange = { featureName = it },
306+
onValueChange = { if (!isSystemFeature) featureName = it },
296307
label = { Text(stringResource(id = R.string.feature_name)) },
297308
modifier = Modifier.fillMaxWidth(),
298-
singleLine = true
309+
singleLine = true,
310+
enabled = !isSystemFeature,
311+
readOnly = isSystemFeature
299312
)
313+
314+
// // 显示系统特性提示
315+
// if (isSystemFeature) {
316+
// Text(
317+
// text = stringResource(id = R.string.system_feature_name_readonly_hint),
318+
// style = MaterialTheme.typography.bodySmall,
319+
// color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
320+
// modifier = Modifier.fillMaxWidth()
321+
// )
322+
// }
300323
Spacer(modifier = Modifier.height(16.dp))
301324
// 检查是否为复杂特性
302325
val tempFeature = AppFeature(

app/src/main/res/values-en/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@
289289
<string name="oplus_feature_rhythm_eyeprotect_2_0_support">[Soft] One-swipe eye-protection 2.0</string>
290290
<string name="oplus_feature_super_volume_5x">[Soft] Super volume (5×)</string>
291291

292+
<!-- Edit feature dialog related strings -->
293+
<string name="system_feature_name_readonly_hint">System feature configuration, name cannot be edited</string>
294+
292295
<!-- Disclaimer related strings -->
293296
<string name="disclaimer_title">Disclaimer</string>
294297
<string name="disclaimer_accept">I have read and agree</string>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@
349349
<string name="oplus_feature_rhythm_eyeprotect_2_0_support">[软] 单扫护眼</string>
350350
<string name="oplus_feature_super_volume_5x">[软] 超级音量(5×)</string>
351351

352+
<!-- Edit feature dialog related strings -->
353+
<string name="system_feature_name_readonly_hint">系统存在的特性配置,名称不可编辑</string>
354+
352355
<!-- Disclaimer related strings -->
353356
<string name="disclaimer_title">免责声明</string>
354357
<string name="disclaimer_accept">我已阅读并同意</string>

0 commit comments

Comments
 (0)