Skip to content

Commit 2e63fa6

Browse files
committed
Merge remote-tracking branch 'origin/claude/issue-2106-auto-switch-ime-dialog' into develop
2 parents 96e5033 + bfb0d8a commit 2e63fa6

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,27 @@ class KeyMapListViewModel(
907907
}
908908

909909
fun showInputMethodPicker() {
910-
showInputMethodPickerUseCase.show(fromForeground = true)
910+
coroutineScope.launch {
911+
val autoSwitchEnabled = showInputMethodPickerUseCase.isAutoSwitchImeEnabled.first()
912+
913+
if (autoSwitchEnabled) {
914+
val response = showDialog(
915+
"disable_auto_switch_ime_dialog",
916+
DialogModel.Alert(
917+
title = getString(R.string.dialog_title_disable_auto_switch_ime),
918+
message = getString(R.string.dialog_message_disable_auto_switch_ime),
919+
positiveButtonText = getString(R.string.pos_ok),
920+
negativeButtonText = getString(R.string.neg_cancel),
921+
),
922+
)
923+
924+
if (response != DialogResponse.POSITIVE) return@launch
925+
926+
showInputMethodPickerUseCase.disableAutoSwitch()
927+
}
928+
929+
showInputMethodPickerUseCase.show(fromForeground = true)
930+
}
911931
}
912932

913933
private suspend fun onAutomaticBackupResult(result: KMResult<*>) {
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
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,4 +1901,7 @@
19011901
<string name="dialog_bug_report_discord_button">Open Discord</string>
19021902
<string name="dialog_bug_report_email_button">Email us</string>
19031903

1904+
<string name="dialog_title_disable_auto_switch_ime">Disable auto-switch keyboard?</string>
1905+
<string name="dialog_message_disable_auto_switch_ime">Choosing a keyboard here will disable the automatic keyboard switching feature. You can re-enable it in Settings.</string>
1906+
19041907
</resources>

0 commit comments

Comments
 (0)