mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 13:52:58 -08:00
Workaround to fill OTP token in multiple fields with Magikeyboard (long press) #1158
This commit is contained in:
1 parent
b0e722acce
commit
b561db3a67
5 files changed
+39
-13
No files matched your search
@@ -18,6 +18,8 @@ package com.kunzisoft.keepass.magikeyboard;
|
||||
|
||||
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_BACK_KEYBOARD;
|
||||
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_CHANGE_KEYBOARD;
|
||||
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP;
|
||||
import static com.kunzisoft.keepass.magikeyboard.MagikeyboardService.KEY_OTP_ALT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -1047,6 +1049,9 @@ public class KeyboardView extends View implements View.OnClickListener {
|
||||
if (popupKey.codes[0] == KEY_BACK_KEYBOARD) {
|
||||
mKeyboardActionListener.onKey(KEY_CHANGE_KEYBOARD, popupKey.codes);
|
||||
return true;
|
||||
} else if (popupKey.codes[0] == KEY_OTP) {
|
||||
mKeyboardActionListener.onKey(KEY_OTP_ALT, popupKey.codes);
|
||||
return true;
|
||||
} else {
|
||||
int popupKeyboardId = popupKey.popupResId;
|
||||
if (popupKeyboardId != 0) {
|
||||
|
||||
@@ -245,35 +245,52 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
|
||||
dismissCustomKeys()
|
||||
}
|
||||
KEY_USERNAME -> {
|
||||
if (entryInfoKey != null) {
|
||||
currentInputConnection.commitText(entryInfoKey!!.username, 1)
|
||||
entryInfoKey?.username?.let { username ->
|
||||
currentInputConnection.commitText(username, 1)
|
||||
}
|
||||
actionTabAutomatically()
|
||||
}
|
||||
KEY_PASSWORD -> {
|
||||
if (entryInfoKey != null) {
|
||||
currentInputConnection.commitText(entryInfoKey!!.password, 1)
|
||||
entryInfoKey?.password?.let { password ->
|
||||
currentInputConnection.commitText(password, 1)
|
||||
}
|
||||
val otpFieldExists = entryInfoKey?.containsCustomField(OTP_TOKEN_FIELD) ?: false
|
||||
actionGoAutomatically(!otpFieldExists)
|
||||
}
|
||||
KEY_OTP -> {
|
||||
if (entryInfoKey != null) {
|
||||
entryInfoKey?.let { entryInfo ->
|
||||
currentInputConnection.commitText(
|
||||
entryInfoKey!!.getGeneratedFieldValue(OTP_TOKEN_FIELD), 1)
|
||||
entryInfo.getGeneratedFieldValue(OTP_TOKEN_FIELD), 1)
|
||||
}
|
||||
actionGoAutomatically()
|
||||
}
|
||||
KEY_OTP_ALT -> {
|
||||
entryInfoKey?.let { entryInfo ->
|
||||
val otpToken = entryInfo.getGeneratedFieldValue(OTP_TOKEN_FIELD)
|
||||
if (otpToken.isNotEmpty()) {
|
||||
// Cut to fill each digit separatelyKeyEvent.KEYCODE_TAB
|
||||
val otpTokenChars = otpToken.chunked(1)
|
||||
otpTokenChars.forEachIndexed { index, char ->
|
||||
currentInputConnection.commitText(char, 1)
|
||||
if (index < (otpTokenChars.size-1))
|
||||
currentInputConnection.sendKeyEvent(
|
||||
KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
actionGoAutomatically()
|
||||
}
|
||||
KEY_URL -> {
|
||||
if (entryInfoKey != null) {
|
||||
currentInputConnection.commitText(entryInfoKey!!.url, 1)
|
||||
entryInfoKey?.url?.let { url ->
|
||||
currentInputConnection.commitText(url, 1)
|
||||
}
|
||||
actionGoAutomatically()
|
||||
}
|
||||
KEY_FIELDS -> {
|
||||
if (entryInfoKey != null) {
|
||||
entryInfoKey?.customFields?.let { customFields ->
|
||||
fieldsAdapter?.apply {
|
||||
setFields(entryInfoKey!!.customFields.filter { it.name != OTP_TOKEN_FIELD})
|
||||
setFields(customFields.filter { it.name != OTP_TOKEN_FIELD})
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
@@ -347,7 +364,8 @@ class MagikeyboardService : InputMethodService(), KeyboardView.OnKeyboardActionL
|
||||
private const val KEY_ENTRY = 620
|
||||
private const val KEY_USERNAME = 500
|
||||
private const val KEY_PASSWORD = 510
|
||||
private const val KEY_OTP = 515
|
||||
const val KEY_OTP = 515
|
||||
const val KEY_OTP_ALT = 516
|
||||
private const val KEY_URL = 520
|
||||
private const val KEY_FIELDS = 530
|
||||
|
||||
|
||||
Reference in new issue
Block a user