@@ -44,7 +44,9 @@ import io.github.sds100.keymapper.base.R
4444import io.github.sds100.keymapper.base.compose.KeyMapperTheme
4545import io.github.sds100.keymapper.base.compose.LocalCustomColorsPalette
4646import io.github.sds100.keymapper.base.trigger.AccessibilityServiceRequirementRow
47+ import io.github.sds100.keymapper.base.trigger.InputMethodRequirementRow
4748import io.github.sds100.keymapper.base.trigger.ProModeStatus
49+ import io.github.sds100.keymapper.base.utils.ui.compose.CheckBoxText
4850import io.github.sds100.keymapper.base.utils.ui.compose.HeaderText
4951import io.github.sds100.keymapper.base.utils.ui.compose.icons.KeyMapperIcons
5052import io.github.sds100.keymapper.base.utils.ui.compose.icons.ProModeIcon
@@ -63,6 +65,7 @@ fun FixKeyEventActionBottomSheet(
6365 onEnableInputMethodClick : () -> Unit = {},
6466 onChooseInputMethodClick : () -> Unit = {},
6567 onDoneClick : () -> Unit = {},
68+ onAutoSwitchImeCheckedChange : (Boolean ) -> Unit = {},
6669) {
6770 ModalBottomSheet (
6871 modifier = modifier,
@@ -96,7 +99,7 @@ fun FixKeyEventActionBottomSheet(
9699 FixKeyEventActionOptionCard (
97100 onClick = onSelectInputMethod,
98101 selected = state is FixKeyEventActionState .InputMethod ,
99- title = stringResource(R .string.trigger_setup_input_method_title ),
102+ title = stringResource(R .string.fix_key_event_action_input_method_title ),
100103 icon = Icons .Rounded .Keyboard ,
101104 ) {
102105 val annotatedText = buildAnnotatedString {
@@ -111,64 +114,74 @@ fun FixKeyEventActionBottomSheet(
111114 Placeholder (
112115 width = MaterialTheme .typography.bodyLarge.fontSize,
113116 height = MaterialTheme .typography.bodyLarge.fontSize,
114- placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter
115- )
117+ placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter ,
118+ ),
116119 ) {
117120 Icon (
118121 imageVector = Icons .Rounded .Remove ,
119122 contentDescription = null ,
120- tint = MaterialTheme .colorScheme.error
123+ tint = MaterialTheme .colorScheme.error,
121124 )
122- }
123- )
125+ },
126+ ),
124127 )
125128 Text (
126129 annotatedText,
127130 inlineContent = inlineContent,
128- style = MaterialTheme .typography.bodyMedium
131+ style = MaterialTheme .typography.bodyMedium,
129132 )
130133 }
131134
132- // TODO show disabled state on < Android Q
135+ val isProModeUnsupported = state.proModeStatus == ProModeStatus .UNSUPPORTED
136+
133137 FixKeyEventActionOptionCard (
134138 onClick = onSelectProMode,
135139 selected = state is FixKeyEventActionState .ProMode ,
136140 title = stringResource(R .string.pro_mode_app_bar_title),
137141 icon = KeyMapperIcons .ProModeIcon ,
142+ enabled = ! isProModeUnsupported,
138143 ) {
139- val annotatedText = buildAnnotatedString {
140- appendInlineContent(" icon" , " [icon]" )
141- append(" " )
142- append(stringResource(R .string.fix_key_event_action_pro_mode_text))
143- }
144- val inlineContent = mapOf (
145- Pair (
146- " icon" ,
147- InlineTextContent (
148- Placeholder (
149- width = MaterialTheme .typography.bodyLarge.fontSize,
150- height = MaterialTheme .typography.bodyLarge.fontSize,
151- placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter
152- )
153- ) {
154- Icon (
155- imageVector = Icons .Rounded .Add ,
156- contentDescription = null ,
157- tint = LocalCustomColorsPalette .current.green
158- )
159- }
144+ if (isProModeUnsupported) {
145+ Text (
146+ stringResource(R .string.trigger_setup_pro_mode_unsupported),
147+ style = MaterialTheme .typography.bodyMedium,
148+ color = MaterialTheme .colorScheme.error,
160149 )
161- )
162- Text (
163- annotatedText,
164- inlineContent = inlineContent,
165- style = MaterialTheme .typography.bodyMedium
166- )
150+ } else {
151+ val annotatedText = buildAnnotatedString {
152+ appendInlineContent(" icon" , " [icon]" )
153+ append(" " )
154+ append(stringResource(R .string.fix_key_event_action_pro_mode_text))
155+ }
156+ val inlineContent = mapOf (
157+ Pair (
158+ " icon" ,
159+ InlineTextContent (
160+ Placeholder (
161+ width = MaterialTheme .typography.bodyLarge.fontSize,
162+ height = MaterialTheme .typography.bodyLarge.fontSize,
163+ placeholderVerticalAlign = PlaceholderVerticalAlign .TextCenter ,
164+ ),
165+ ) {
166+ Icon (
167+ imageVector = Icons .Rounded .Add ,
168+ contentDescription = null ,
169+ tint = LocalCustomColorsPalette .current.green,
170+ )
171+ },
172+ ),
173+ )
174+ Text (
175+ annotatedText,
176+ inlineContent = inlineContent,
177+ style = MaterialTheme .typography.bodyMedium,
178+ )
179+ }
167180 }
168181
169182 Text (
170183 stringResource(R .string.fix_key_event_action_change_in_settings_caption),
171- style = MaterialTheme .typography.labelMedium
184+ style = MaterialTheme .typography.labelMedium,
172185 )
173186 }
174187
@@ -177,16 +190,31 @@ fun FixKeyEventActionBottomSheet(
177190 AccessibilityServiceRequirementRow (
178191 modifier = Modifier .fillMaxWidth(),
179192 isServiceEnabled = state.isAccessibilityServiceEnabled,
180- onClick = onEnableAccessibilityServiceClick
193+ onClick = onEnableAccessibilityServiceClick,
181194 )
182195
183196 when (state) {
184197 is FixKeyEventActionState .InputMethod -> {
198+ InputMethodRequirementRow (
199+ modifier = Modifier .fillMaxWidth(),
200+ isChosen = state.isChosen,
201+ isEnabled = state.isEnabled,
202+ enablingRequiresUserInput = state.enablingRequiresUserInput,
203+ onEnableClick = onEnableInputMethodClick,
204+ onChooseClick = onChooseInputMethodClick,
205+ )
185206
207+ HeaderText (text = stringResource(R .string.fix_key_event_action_options_title))
208+
209+ CheckBoxText (
210+ modifier = Modifier .fillMaxWidth(),
211+ text = stringResource(R .string.fix_key_event_action_auto_switch_ime_text),
212+ isChecked = state.isAutoSwitchImeEnabled,
213+ onCheckedChange = onAutoSwitchImeCheckedChange,
214+ )
186215 }
187216
188217 is FixKeyEventActionState .ProMode -> {
189-
190218 }
191219 }
192220
@@ -204,21 +232,26 @@ private fun FixKeyEventActionOptionCard(
204232 selected : Boolean ,
205233 title : String ,
206234 icon : ImageVector ,
207- content : @Composable ColumnScope .() -> Unit
235+ enabled : Boolean = true,
236+ content : @Composable ColumnScope .() -> Unit ,
208237) {
209- OutlinedCard (modifier = modifier.fillMaxWidth(), onClick = onClick) {
238+ OutlinedCard (
239+ modifier = modifier.fillMaxWidth(),
240+ onClick = onClick,
241+ enabled = enabled,
242+ ) {
210243 Row (
211244 modifier = Modifier
212245 .fillMaxWidth()
213- .padding(start = 16 .dp, top = 16 .dp, end = 8 .dp, bottom = 16 .dp)
246+ .padding(start = 16 .dp, top = 16 .dp, end = 8 .dp, bottom = 16 .dp),
214247 ) {
215248 Column (modifier = Modifier .weight(1f )) {
216249 Row (verticalAlignment = Alignment .CenterVertically ) {
217250 Icon (icon, contentDescription = null )
218251 Spacer (modifier = Modifier .width(8 .dp))
219252 Text (
220253 text = title,
221- style = MaterialTheme .typography.titleMedium
254+ style = MaterialTheme .typography.titleMedium,
222255 )
223256 }
224257 Spacer (modifier = Modifier .height(8 .dp))
@@ -227,7 +260,8 @@ private fun FixKeyEventActionOptionCard(
227260 RadioButton (
228261 modifier = Modifier .align(Alignment .CenterVertically ),
229262 selected = selected,
230- onClick = onClick
263+ onClick = onClick,
264+ enabled = enabled,
231265 )
232266 }
233267 }
@@ -251,6 +285,8 @@ private fun InputMethodPreview() {
251285 isChosen = true ,
252286 enablingRequiresUserInput = true ,
253287 isAccessibilityServiceEnabled = true ,
288+ isAutoSwitchImeEnabled = true ,
289+ proModeStatus = ProModeStatus .ENABLED ,
254290 ),
255291 )
256292 }
@@ -275,4 +311,29 @@ private fun ProModePreview() {
275311 ),
276312 )
277313 }
278- }
314+ }
315+
316+ @OptIn(ExperimentalMaterial3Api ::class )
317+ @Preview
318+ @Composable
319+ private fun ProModeUnsupportedPreview () {
320+ KeyMapperTheme {
321+ val sheetState = SheetState (
322+ skipPartiallyExpanded = true ,
323+ density = LocalDensity .current,
324+ initialValue = SheetValue .Expanded ,
325+ )
326+
327+ FixKeyEventActionBottomSheet (
328+ sheetState = sheetState,
329+ state = FixKeyEventActionState .InputMethod (
330+ proModeStatus = ProModeStatus .UNSUPPORTED ,
331+ isEnabled = true ,
332+ isChosen = true ,
333+ enablingRequiresUserInput = true ,
334+ isAutoSwitchImeEnabled = false ,
335+ isAccessibilityServiceEnabled = true ,
336+ ),
337+ )
338+ }
339+ }
0 commit comments