Skip to content

Commit bfb0d8a

Browse files
committed
#2106 refactor: move auto-switch IME logic to ShowInputMethodPickerUseCase
Move isAutoSwitchImeEnabled flow and disableAutoSwitch() out of FixKeyEventActionDelegate (where they don't belong) and into ShowInputMethodPickerUseCase which owns all IME picker concerns. KeyMapListViewModel now reads/writes through the use case. https://claude.ai/code/session_01AdijnJnpbsCqPDTYobwnLa
1 parent 08ea2c4 commit bfb0d8a

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

base/src/main/java/io/github/sds100/keymapper/base/actions/keyevent/FixKeyEventActionDelegate.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ class FixKeyEventActionDelegateImpl @Inject constructor(
6363
preferenceRepository.get(Keys.keyEventActionsUseSystemBridge)
6464
.map { it ?: PreferenceDefaults.KEY_EVENT_ACTIONS_USE_SYSTEM_BRIDGE }
6565

66-
override val isAutoSwitchImeEnabled: Flow<Boolean> =
67-
preferenceRepository.get(Keys.changeImeOnInputFocus)
68-
.map { it ?: PreferenceDefaults.CHANGE_IME_ON_INPUT_FOCUS }
69-
7066
private val showBottomSheet: MutableStateFlow<Boolean> = MutableStateFlow(false)
7167

7268
@OptIn(ExperimentalCoroutinesApi::class)
@@ -170,7 +166,6 @@ class FixKeyEventActionDelegateImpl @Inject constructor(
170166

171167
interface FixKeyEventActionDelegate {
172168
val fixKeyEventActionState: StateFlow<FixKeyEventActionState?>
173-
val isAutoSwitchImeEnabled: Flow<Boolean>
174169

175170
fun showFixKeyEventActionBottomSheet()
176171
fun dismissFixKeyEventActionBottomSheet()

base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ class KeyMapListViewModel(
908908

909909
fun showInputMethodPicker() {
910910
coroutineScope.launch {
911-
val autoSwitchEnabled = isAutoSwitchImeEnabled.first()
911+
val autoSwitchEnabled = showInputMethodPickerUseCase.isAutoSwitchImeEnabled.first()
912912

913913
if (autoSwitchEnabled) {
914914
val response = showDialog(
@@ -923,7 +923,7 @@ class KeyMapListViewModel(
923923

924924
if (response != DialogResponse.POSITIVE) return@launch
925925

926-
onAutoSwitchImeCheckedChange(false)
926+
showInputMethodPickerUseCase.disableAutoSwitch()
927927
}
928928

929929
showInputMethodPickerUseCase.show(fromForeground = true)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
package io.github.sds100.keymapper.base.system.inputmethod
22

3+
import io.github.sds100.keymapper.data.Keys
4+
import io.github.sds100.keymapper.data.PreferenceDefaults
5+
import io.github.sds100.keymapper.data.repositories.PreferenceRepository
36
import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter
47
import javax.inject.Inject
8+
import kotlinx.coroutines.flow.Flow
9+
import kotlinx.coroutines.flow.map
510

611
class ShowInputMethodPickerUseCaseImpl @Inject constructor(
712
private val inputMethodAdapter: InputMethodAdapter,
13+
private val preferenceRepository: PreferenceRepository,
814
) : ShowInputMethodPickerUseCase {
15+
override val isAutoSwitchImeEnabled: Flow<Boolean> =
16+
preferenceRepository.get(Keys.changeImeOnInputFocus)
17+
.map { it ?: PreferenceDefaults.CHANGE_IME_ON_INPUT_FOCUS }
18+
19+
override fun disableAutoSwitch() {
20+
preferenceRepository.set(Keys.changeImeOnInputFocus, false)
21+
}
22+
923
override fun show(fromForeground: Boolean) {
1024
inputMethodAdapter.showImePicker(fromForeground = fromForeground)
1125
}
1226
}
1327

1428
interface ShowInputMethodPickerUseCase {
29+
val isAutoSwitchImeEnabled: Flow<Boolean>
30+
31+
fun disableAutoSwitch()
1532
fun show(fromForeground: Boolean)
1633
}

0 commit comments

Comments
 (0)