Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<*>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> =
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<Boolean>

fun disableAutoSwitch()
fun show(fromForeground: Boolean)
}
3 changes: 3 additions & 0 deletions base/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1901,4 +1901,7 @@
<string name="dialog_bug_report_discord_button">Open Discord</string>
<string name="dialog_bug_report_email_button">Email us</string>

<string name="dialog_title_disable_auto_switch_ime">Disable auto-switch keyboard?</string>
<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>

</resources>
Loading