diff --git a/base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListViewModel.kt b/base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListViewModel.kt index 414dfc2ac2..6a2100b5a0 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListViewModel.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListViewModel.kt @@ -907,7 +907,27 @@ class KeyMapListViewModel( } fun showInputMethodPicker() { - showInputMethodPickerUseCase.show(fromForeground = true) + coroutineScope.launch { + val autoSwitchEnabled = showInputMethodPickerUseCase.isAutoSwitchImeEnabled.first() + + if (autoSwitchEnabled) { + val response = showDialog( + "disable_auto_switch_ime_dialog", + DialogModel.Alert( + title = getString(R.string.dialog_title_disable_auto_switch_ime), + message = getString(R.string.dialog_message_disable_auto_switch_ime), + positiveButtonText = getString(R.string.pos_ok), + negativeButtonText = getString(R.string.neg_cancel), + ), + ) + + if (response != DialogResponse.POSITIVE) return@launch + + showInputMethodPickerUseCase.disableAutoSwitch() + } + + showInputMethodPickerUseCase.show(fromForeground = true) + } } private suspend fun onAutomaticBackupResult(result: KMResult<*>) { diff --git a/base/src/main/java/io/github/sds100/keymapper/base/system/inputmethod/ShowInputMethodPickerUseCase.kt b/base/src/main/java/io/github/sds100/keymapper/base/system/inputmethod/ShowInputMethodPickerUseCase.kt index 38caa71748..d2f2e6c846 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/system/inputmethod/ShowInputMethodPickerUseCase.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/system/inputmethod/ShowInputMethodPickerUseCase.kt @@ -1,16 +1,33 @@ package io.github.sds100.keymapper.base.system.inputmethod +import io.github.sds100.keymapper.data.Keys +import io.github.sds100.keymapper.data.PreferenceDefaults +import io.github.sds100.keymapper.data.repositories.PreferenceRepository import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter import javax.inject.Inject +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map class ShowInputMethodPickerUseCaseImpl @Inject constructor( private val inputMethodAdapter: InputMethodAdapter, + private val preferenceRepository: PreferenceRepository, ) : ShowInputMethodPickerUseCase { + override val isAutoSwitchImeEnabled: Flow = + preferenceRepository.get(Keys.changeImeOnInputFocus) + .map { it ?: PreferenceDefaults.CHANGE_IME_ON_INPUT_FOCUS } + + override fun disableAutoSwitch() { + preferenceRepository.set(Keys.changeImeOnInputFocus, false) + } + override fun show(fromForeground: Boolean) { inputMethodAdapter.showImePicker(fromForeground = fromForeground) } } interface ShowInputMethodPickerUseCase { + val isAutoSwitchImeEnabled: Flow + + fun disableAutoSwitch() fun show(fromForeground: Boolean) } diff --git a/base/src/main/res/values/strings.xml b/base/src/main/res/values/strings.xml index 9bb7dc5d2f..8f820b1af2 100644 --- a/base/src/main/res/values/strings.xml +++ b/base/src/main/res/values/strings.xml @@ -1901,4 +1901,7 @@ Open Discord Email us + Disable auto-switch keyboard? + Choosing a keyboard here will disable the automatic keyboard switching feature. You can re-enable it in Settings. +