@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding
1313import androidx.compose.material3.HorizontalDivider
1414import androidx.compose.material3.LocalTextStyle
1515import androidx.compose.material3.MaterialTheme
16+ import androidx.compose.material3.Switch
1617import androidx.compose.material3.Text
1718import androidx.compose.runtime.Composable
1819import androidx.compose.runtime.getValue
@@ -29,8 +30,10 @@ import androidx.compose.ui.unit.em
2930import helium314.keyboard.compat.locale
3031import helium314.keyboard.latin.dictionary.Dictionary
3132import helium314.keyboard.latin.R
33+ import helium314.keyboard.latin.common.LocaleUtils
3234import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
3335import helium314.keyboard.latin.utils.DictionaryInfoUtils
36+ import helium314.keyboard.latin.utils.prefs
3437import helium314.keyboard.latin.utils.createDictionaryTextAnnotated
3538import helium314.keyboard.settings.DeleteButton
3639import helium314.keyboard.settings.ExpandButton
@@ -62,16 +65,51 @@ fun DictionaryDialog(
6265 content = {
6366 Column {
6467 if (hasInternal) {
68+ val internalDicts = DictionaryInfoUtils .getAssetsDictionaryList(ctx)
69+ val best = internalDicts?.let {
70+ LocaleUtils .getBestMatch(locale, it.toList()) { dict ->
71+ DictionaryInfoUtils .extractLocaleFromAssetsDictionaryFile(dict)
72+ }
73+ }
74+ val internalId = best?.let { " main:" + it.substringAfter(" _" ).substringBefore(" ." ) }
75+
6576 val color = if (mainDict == null ) MaterialTheme .typography.titleSmall.color
6677 else MaterialTheme .colorScheme.onSurface.copy(alpha = 0.38f ) // for disabled look
6778 val bottomPadding = if (mainDict == null ) 12 .dp else 0 .dp
68- Text (stringResource(R .string.internal_dictionary_summary),
69- modifier = Modifier
70- .fillMaxWidth()
71- .padding(bottom = bottomPadding),
72- color = color,
73- style = MaterialTheme .typography.titleSmall
74- )
79+
80+ if (internalId != null ) {
81+ val prefs = ctx.prefs()
82+ val prefKey = " pref_dict_enabled_$internalId "
83+ var enabled by remember { mutableStateOf(prefs.getBoolean(prefKey, true )) }
84+ Row (
85+ verticalAlignment = Alignment .CenterVertically ,
86+ modifier = Modifier
87+ .fillMaxWidth()
88+ .padding(bottom = bottomPadding)
89+ ) {
90+ Switch (
91+ checked = enabled && (mainDict == null ),
92+ enabled = mainDict == null ,
93+ onCheckedChange = { isChecked ->
94+ enabled = isChecked
95+ prefs.edit().putBoolean(prefKey, isChecked).apply ()
96+ },
97+ modifier = Modifier .padding(end = 8 .dp)
98+ )
99+ Text (stringResource(R .string.internal_dictionary_summary),
100+ color = color,
101+ style = MaterialTheme .typography.titleSmall
102+ )
103+ }
104+ } else {
105+ Text (stringResource(R .string.internal_dictionary_summary),
106+ modifier = Modifier
107+ .fillMaxWidth()
108+ .padding(bottom = bottomPadding),
109+ color = color,
110+ style = MaterialTheme .typography.titleSmall
111+ )
112+ }
75113 }
76114 if (mainDict != null )
77115 DictionaryDetails (mainDict)
@@ -113,11 +151,24 @@ private fun DictionaryDetails(dict: File) {
113151 var showDetails by remember { mutableStateOf(false ) }
114152 val title = if (type != DictionaryInfoUtils .DEFAULT_MAIN_DICT ) type
115153 else stringResource(R .string.main_dictionary)
154+ val ctx = LocalContext .current
155+ val prefs = ctx.prefs()
156+ val prefKey = " pref_dict_enabled_${header.mIdString} "
157+ var enabled by remember { mutableStateOf(prefs.getBoolean(prefKey, true )) }
158+
116159 Row (
117160 horizontalArrangement = Arrangement .SpaceBetween ,
118161 verticalAlignment = Alignment .CenterVertically ,
119162 modifier = Modifier .fillMaxWidth()
120163 ) {
164+ Switch (
165+ checked = enabled,
166+ onCheckedChange = { isChecked ->
167+ enabled = isChecked
168+ prefs.edit().putBoolean(prefKey, isChecked).apply ()
169+ },
170+ modifier = Modifier .padding(end = 8 .dp)
171+ )
121172 Text (title, style = MaterialTheme .typography.titleSmall, modifier = Modifier .weight(1f ))
122173 DeleteButton { showDeleteDialog = true }
123174 ExpandButton { showDetails = ! showDetails }
0 commit comments