From 51367b360ad02a90a179bb06df9ef2b7ac62ae40 Mon Sep 17 00:00:00 2001 From: Codex Mozc Autonomy Date: Tue, 17 Nov 2026 15:23:15 -0500 Subject: [PATCH 1/2] Add assignable long-press actions to custom keys --- .../custom_keyboard/data/KeyDefinition.kt | 3 +- .../import_export/KeyboardBackupPipeline.kt | 8 + .../import_export/KeyboardLayoutExportDtos.kt | 4 +- .../KeyboardLayoutJsonExporter.kt | 3 +- .../custom_keyboard/ui/KeyEditorFragment.kt | 133 ++++++++++++----- .../database/AppDatabase.kt | 8 +- .../ime_service/di/AppModule.kt | 2 + .../repository/KeyboardRepository.kt | 51 +++---- .../main/res/layout/fragment_key_editor.xml | 34 +++++ app/src/main/res/values-ja/strings.xml | 3 + app/src/main/res/values/strings.xml | 3 + .../database/FreeFlickKeyMigrationTest.kt | 9 +- .../database/LegacyKeySchemaMigrationTest.kt | 6 +- .../database/QwertyKeyMigrationTest.kt | 6 +- .../KeyboardLayoutJsonImporterTest.kt | 6 +- .../RomajiBehaviorPersistenceTest.kt | 5 +- .../ng_word/database/NgWordMigrationTest.kt | 7 +- .../KeyboardRepositoryDeleteImpactTest.kt | 7 +- .../KeyboardRepositorySaveLayoutTest.kt | 22 +++ .../custom_keyboard/data/KeyModels.kt | 3 +- .../custom_keyboard/view/FlickKeyboardView.kt | 137 ++++++++++++++---- .../view/FlickKeyboardViewLifecycleTest.kt | 77 +++++++++- 22 files changed, 421 insertions(+), 116 deletions(-) diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/data/KeyDefinition.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/data/KeyDefinition.kt index 3f5b97e8c..b9c15bb5f 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/data/KeyDefinition.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/data/KeyDefinition.kt @@ -47,5 +47,6 @@ data class KeyDefinition( val doubleTapPolicy: String? = null, val textInputBehavior: String = KeyTextInputBehavior.NORMAL.dbValue, val popupMapConfigJson: String? = null, - val qwertyConfigJson: String? = null + val qwertyConfigJson: String? = null, + val longPressAction: String? = null ) diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardBackupPipeline.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardBackupPipeline.kt index c0c70a1d7..02e05dbea 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardBackupPipeline.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardBackupPipeline.kt @@ -326,6 +326,13 @@ object KeyboardBackupNormalizer { keyIndex = keyIndex, warnings = warnings ) + val normalizedLongPressAction = remapKeyAction( + action = keyDto.longPressAction, + stableIdsByOldLayoutId = stableIdsByOldLayoutId, + layoutIndex = layoutIndex, + keyIndex = keyIndex, + warnings = warnings + ) val isSpecialKey = keyDto.isSpecialKey ?: false val normalizedDoubleTapAction = when { !isSpecialKey -> null @@ -377,6 +384,7 @@ object KeyboardBackupNormalizer { ), keyIdentifier = identifier, action = normalizedTapAction, + longPressAction = normalizedLongPressAction, rowUnits = keyDto.rowUnits?.coerceAtLeast(0), columnUnits = keyDto.columnUnits?.coerceAtLeast(0), rowSpanUnits = keyDto.rowSpanUnits?.coerceAtLeast(1), diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutExportDtos.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutExportDtos.kt index 63e0a8c5f..9d5250702 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutExportDtos.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutExportDtos.kt @@ -116,7 +116,9 @@ data class KeyDefinitionDto( @SerializedName("freeFlick") val freeFlick: JsonElement? = null, @SerializedName("qwerty") - val qwerty: JsonElement? = null + val qwerty: JsonElement? = null, + @SerializedName("longPressAction") + val longPressAction: String? = null ) data class FlickMappingDto( diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutJsonExporter.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutJsonExporter.kt index b0e9a8717..6c2cf60b3 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutJsonExporter.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/import_export/KeyboardLayoutJsonExporter.kt @@ -124,7 +124,8 @@ internal fun KeyWithFlicks.toExportDto(): KeyWithFlicksExportDto { JsonParser.parseString(it) }, qwerty = this.key.qwertyConfigJson?.let(JsonParser::parseString), - textInputBehavior = this.key.textInputBehavior + textInputBehavior = this.key.textInputBehavior, + longPressAction = this.key.longPressAction ), flicks = this.flicks.map { FlickMappingDto( diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/ui/KeyEditorFragment.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/ui/KeyEditorFragment.kt index 6e291e6a4..5c8bef89a 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/ui/KeyEditorFragment.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/custom_keyboard/ui/KeyEditorFragment.kt @@ -97,6 +97,11 @@ private data class CustomKeyboardTargetOption( @AndroidEntryPoint class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { + private companion object { + const val STATE_EDITING_KEY = "editingKeyIdentifier" + const val STATE_LONG_PRESS_ACTION = "longPressAction" + } + @Inject lateinit var keyboardRepository: KeyboardRepository @@ -137,6 +142,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { private lateinit var specialFlickActionOptions: List private lateinit var customKeyboardTargetAdapter: ArrayAdapter private lateinit var doubleTapTargetAdapter: ArrayAdapter + private lateinit var longPressTargetAdapter: ArrayAdapter private lateinit var circularFlickAdapter: CircularFlickMappingAdapter private lateinit var circularMapAdapter: ArrayAdapter @@ -147,6 +153,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { private var customKeyboardTargetOptions: List = emptyList() private var selectedTargetCustomKeyboardStableId: String? = null private var selectedDoubleTapTargetStableId: String? = null + private var longPressAction: KeyAction? = null private var selectedIconRef: KeyIconRef? = null private var originalIconRef: KeyIconRef? = null private val pendingUserIconPaths = mutableSetOf() @@ -188,7 +195,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { _binding = FragmentKeyEditorBinding.bind(view) binding.buttonDone.isEnabled = false - restoredEditingKeyIdentifier = savedInstanceState?.getString("qwertyEditingKey") + restoredEditingKeyIdentifier = savedInstanceState?.getString(STATE_EDITING_KEY) savedQwertyDraft = QwertyKeyConfigCodec.decode(savedInstanceState?.getString("qwertyDraft"), requireOutput = false) binding.qwertyKeyEditor.onChanged = { updateDoneButtonState() } freeFlickDraft = PopupKeyConfigCodec.decode(savedInstanceState?.getString("freeFlickDraft")) ?: freeFlickDraft @@ -204,7 +211,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { setupToolbarAndMenu() setupGridEditor() setupUIListeners() - setupInitialState() + setupInitialState(savedInstanceState) } private fun setupGridEditor() { @@ -232,6 +239,24 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { false ) + val longPressActionOptions = + listOf(SpecialKeyActionOption(getString(R.string.custom_key_long_press_disabled))) + keyActionOptions + binding.longPressActionSpinner.setAdapter( + SpecialKeyActionDropdownAdapter(requireContext(), longPressActionOptions) + ) + binding.longPressActionSpinner.setOnItemClickListener { _, _, position, _ -> + val option = longPressActionOptions.getOrNull(position) ?: return@setOnItemClickListener + val selectedAction = option.action?.action + updateLongPressAction( + if (selectedAction is KeyAction.MoveToCustomKeyboard) { + longPressAction as? KeyAction.MoveToCustomKeyboard + ?: KeyAction.MoveToCustomKeyboard(customKeyboardTargets.firstOrNull()?.stableId.orEmpty()) + } else { + selectedAction + } + ) + } + // 特殊フリック用アクションスピナー(セル選択後に表示) binding.specialFlickMappingsRecyclerView.setAdapter( SpecialKeyActionDropdownAdapter(requireContext(), specialFlickActionOptions) @@ -249,6 +274,17 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { mutableListOf() ) binding.doubleTapTargetSpinner.setAdapter(doubleTapTargetAdapter) + longPressTargetAdapter = ArrayAdapter( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, + mutableListOf() + ) + binding.longPressTargetSpinner.setAdapter(longPressTargetAdapter) + binding.longPressTargetSpinner.setOnItemClickListener { _, _, position, _ -> + customKeyboardTargets.getOrNull(position)?.let { target -> + updateLongPressAction(KeyAction.MoveToCustomKeyboard(target.stableId)) + } + } circularFlickAdapter = CircularFlickMappingAdapter { updated -> val currentMap = currentCircularFlickMaps.getOrNull(currentCircularMapIndex) @@ -1056,16 +1092,38 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { private suspend fun loadCustomKeyboardTargets() { customKeyboardTargets = keyboardRepository.getLayoutsNotFlowEnsuringStableIds() refreshCustomKeyboardTargetOptions() + longPressTargetAdapter.addAll(customKeyboardTargetOptions.map { it.label }) } private fun refreshCustomKeyboardTargetOptions(deletedStableId: String? = null) { customKeyboardTargetOptions = buildTargetOptions(customKeyboardTargets, deletedStableId) - customKeyboardTargetAdapter.clear() - customKeyboardTargetAdapter.addAll(customKeyboardTargetOptions.map { it.label }) - customKeyboardTargetAdapter.notifyDataSetChanged() - doubleTapTargetAdapter.clear() - doubleTapTargetAdapter.addAll(customKeyboardTargetOptions.map { it.label }) - doubleTapTargetAdapter.notifyDataSetChanged() + val labels = customKeyboardTargetOptions.map { it.label } + for (adapter in listOf(customKeyboardTargetAdapter, doubleTapTargetAdapter)) { + adapter.clear() + adapter.addAll(labels) + adapter.notifyDataSetChanged() + } + } + + private fun updateLongPressAction(action: KeyAction?) { + longPressAction = action + val actionLabel = action?.let { + displayActionForAction(it)?.displayName ?: KeyActionMapper.fromKeyAction(it) + } + binding.longPressActionSpinner.setText( + actionLabel ?: getString(R.string.custom_key_long_press_disabled), false + ) + binding.longPressActionLayout.helperText = action?.let { + getString(R.string.custom_key_long_press_priority) + } + val targetId = (action as? KeyAction.MoveToCustomKeyboard)?.stableId + binding.longPressTargetLayout.isVisible = targetId != null + val targetLabel = targetId?.takeIf { it.isNotBlank() }?.let { id -> + customKeyboardTargetOptions.firstOrNull { it.stableId == id }?.label + ?: getString(R.string.deleted_custom_keyboard_target) + } + binding.longPressTargetSpinner.setText(targetLabel.orEmpty(), false) + updateDoneButtonState() } private fun selectTargetCustomKeyboard(stableId: String?) { @@ -1180,6 +1238,10 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { if (outputEditMode != OutputEditMode.TOGGLE) { binding.textCharInputLayout.error = null } + if (!longPressAction.isValidMoveToCustomKeyboardTarget(validTargetStableIds())) { + binding.buttonDone.isEnabled = false + return + } if (binding.keyTypeChipGroup.checkedChipId == R.id.chip_normal && binding.inputStyleChipGroup.checkedChipId == R.id.chip_free_flick) { binding.buttonDone.isEnabled = ensureFreeFlickDraft()?.let { config -> @@ -1277,7 +1339,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { binding.buttonDone.isEnabled = isEnabled && isDoubleTapValid } - private fun setupInitialState() { + private fun setupInitialState(savedInstanceState: Bundle?) { viewLifecycleOwner.lifecycleScope.launch { loadCustomKeyboardTargets() val state = viewModel.uiState.filterNotNull().first() @@ -1286,7 +1348,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { // legacy KeyData.keyId. selectedKeyIdentifier carries item.id for // flexible layouts (so half-cell keys and editor-created keys // resolve correctly even when keyData.keyId is null/blank). - val selectedId = state.selectedKeyIdentifier ?: restoredEditingKeyIdentifier.takeIf { savedQwertyDraft != null || freeFlickDraft != null } + val selectedId = state.selectedKeyIdentifier ?: restoredEditingKeyIdentifier editingKeyIdentifier = selectedId val selectedKeyItem = selectedId?.let { id -> state.layout.items @@ -1306,6 +1368,17 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { } val key = currentKeyData!! + val savedLongPress = savedInstanceState?.takeIf { + selectedId == restoredEditingKeyIdentifier && it.containsKey(STATE_LONG_PRESS_ACTION) + } + val savedAction = savedLongPress?.getString(STATE_LONG_PRESS_ACTION) + updateLongPressAction( + when { + savedLongPress == null -> key.longPressAction + savedAction == "" -> KeyAction.MoveToCustomKeyboard("") + else -> KeyActionMapper.toKeyAction(savedAction) + } + ) selectedIconRef = key.icon?.takeIf { it.isOverride() } originalIconRef = selectedIconRef key.doubleTapBinding @@ -1878,6 +1951,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { private fun onDone() { val originalKey = currentKeyData ?: return + if (!longPressAction.isValidMoveToCustomKeyboardTarget(validTargetStableIds())) return if ( binding.keyTypeChipGroup.checkedChipId == R.id.chip_normal && @@ -1928,18 +2002,6 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { if (newDrawableResId != null) "" else selectedDisplayAction?.displayName ?: "ACTION" - if (newAction == KeyAction.VoiceInput) { - val context = requireContext() - val hasPermission = ContextCompat.checkSelfPermission( - context, - Manifest.permission.RECORD_AUDIO - ) == PackageManager.PERMISSION_GRANTED - - if (!hasPermission) { - requestRecordAudioPermission.launch(Manifest.permission.RECORD_AUDIO) - } - } - newFlickMap = emptyMap() newTwoStepMap = emptyMap() newLongPressFlickMap = emptyMap() @@ -1986,18 +2048,6 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { } .toMap() - if (newAction == KeyAction.VoiceInput) { - val context = requireContext() - val hasPermission = ContextCompat.checkSelfPermission( - context, - Manifest.permission.RECORD_AUDIO - ) == PackageManager.PERMISSION_GRANTED - - if (!hasPermission) { - requestRecordAudioPermission.launch(Manifest.permission.RECORD_AUDIO) - } - } - newTwoStepMap = emptyMap() newLongPressFlickMap = emptyMap() newTwoStepLongPressMap = emptyMap() @@ -2167,7 +2217,9 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { ) ) } - if (newDoubleTapBinding?.action == KeyAction.VoiceInput) { + if (newAction == KeyAction.VoiceInput || newDoubleTapBinding?.action == KeyAction.VoiceInput || + longPressAction == KeyAction.VoiceInput + ) { val hasPermission = ContextCompat.checkSelfPermission( requireContext(), Manifest.permission.RECORD_AUDIO @@ -2205,6 +2257,7 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { SpecialKeyColorStyle.SPECIAL }, doubleTapBinding = newDoubleTapBinding, + longPressAction = longPressAction, textInputBehavior = if ( !isSpecial && newKeyType == KeyType.PETAL_FLICK && @@ -2246,15 +2299,21 @@ class KeyEditorFragment : Fragment(R.layout.fragment_key_editor) { override fun onSaveInstanceState(outState: Bundle) { + editingKeyIdentifier?.let { + outState.putString(STATE_EDITING_KEY, it) + outState.putString( + STATE_LONG_PRESS_ACTION, + KeyActionMapper.fromKeyAction(longPressAction) + ?: (longPressAction as? KeyAction.MoveToCustomKeyboard)?.stableId + ) + } freeFlickDraft?.let { outState.putString("freeFlickDraft", PopupKeyConfigCodec.encode(it)) } if (_binding != null && freeFlickDraft != null) { - outState.putString("qwertyEditingKey", editingKeyIdentifier) outState.putInt("freeFlickInputStyle", binding.inputStyleChipGroup.checkedChipId) } if (_binding != null && binding.keyTypeChipGroup.checkedChipId == R.id.chip_normal && binding.inputStyleChipGroup.checkedChipId == R.id.chip_qwerty) { outState.putString("qwertyDraft", QwertyKeyConfigCodec.encode(binding.qwertyKeyEditor.config)) - outState.putString("qwertyEditingKey", editingKeyIdentifier) } super.onSaveInstanceState(outState) } diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/database/AppDatabase.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/database/AppDatabase.kt index baf060a7a..21ba804a3 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/database/AppDatabase.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/database/AppDatabase.kt @@ -84,7 +84,7 @@ import com.kazumaproject.markdownhelperkeyboard.zeroquery.custom.CustomZeroQuery CustomZeroQueryEntry::class, TextMacro::class, ], - version = 51, + version = 52, exportSchema = false ) @TypeConverters( @@ -116,6 +116,12 @@ abstract class AppDatabase : RoomDatabase() { abstract fun textMacroDao(): TextMacroDao companion object { + val MIGRATION_51_52 = object : Migration(51, 52) { + override fun migrate(db: SupportSQLiteDatabase) { + db.execSQL("ALTER TABLE `key_definitions` ADD COLUMN `longPressAction` TEXT") + } + } + val MIGRATION_50_51 = object : Migration(50, 51) { override fun migrate(db: SupportSQLiteDatabase) { // Rebuild for SQLite versions before DROP COLUMN (Android 7+). diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/di/AppModule.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/di/AppModule.kt index 8f3455f19..1a09eb830 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/di/AppModule.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/ime_service/di/AppModule.kt @@ -62,6 +62,7 @@ import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.M import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_45_46 import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_47_48 import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_50_51 +import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_51_52 import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_49_50 import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_48_49 import com.kazumaproject.markdownhelperkeyboard.database.AppDatabase.Companion.MIGRATION_46_47 @@ -172,6 +173,7 @@ object AppModule { MIGRATION_48_49, MIGRATION_49_50, MIGRATION_50_51, + MIGRATION_51_52, ) .build() diff --git a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/repository/KeyboardRepository.kt b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/repository/KeyboardRepository.kt index 1ce8a39e8..35d95ac17 100644 --- a/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/repository/KeyboardRepository.kt +++ b/app/src/main/java/com/kazumaproject/markdownhelperkeyboard/repository/KeyboardRepository.kt @@ -566,8 +566,8 @@ class KeyboardRepository @Inject constructor( /** * 全カスタムキーボードを走査し、`MoveToCustomKeyboard(targetStableId)` に - * 該当する参照箇所を集める。tap action / petal flick / circular flick / - * two-step flick / long-press flick / two-step long-press flick のすべてを対象。 + * 該当する参照箇所を集める。タップ、ダブルタップ、長押しのアクションと、 + * フリックおよび円形フリックのアクションを対象とする。 * * 既存設計に合わせ、DB 文字列ではなく * [com.kazumaproject.custom_keyboard.data.KeyActionMapper.toKeyAction] @@ -593,35 +593,20 @@ class KeyboardRepository @Inject constructor( val keyIdentifier = key.keyIdentifier val keyLabel = key.label.takeIf { it.isNotBlank() } - // 1) tap action - val tapAction = KeyActionMapper.toKeyAction(key.action) - if (tapAction is KeyAction.MoveToCustomKeyboard && - tapAction.stableId == targetStableId - ) { - references += MoveToCustomKeyboardReference( - sourceLayoutId = sourceLayoutId, - sourceLayoutName = sourceLayoutName, - sourceKeyIdentifier = keyIdentifier, - sourceKeyLabel = keyLabel, - targetStableId = targetStableId - ) - } - - // 2) double-tap action - val doubleTapAction = KeyActionMapper.toKeyAction(key.doubleTapAction) - if (doubleTapAction is KeyAction.MoveToCustomKeyboard && - doubleTapAction.stableId == targetStableId - ) { - references += MoveToCustomKeyboardReference( - sourceLayoutId = sourceLayoutId, - sourceLayoutName = sourceLayoutName, - sourceKeyIdentifier = keyIdentifier, - sourceKeyLabel = keyLabel, - targetStableId = targetStableId - ) + for (storedAction in listOf(key.action, key.doubleTapAction, key.longPressAction)) { + val action = KeyActionMapper.toKeyAction(storedAction) + if (action is KeyAction.MoveToCustomKeyboard && action.stableId == targetStableId) { + references += MoveToCustomKeyboardReference( + sourceLayoutId = sourceLayoutId, + sourceLayoutName = sourceLayoutName, + sourceKeyIdentifier = keyIdentifier, + sourceKeyLabel = keyLabel, + targetStableId = targetStableId + ) + } } - // 3) flick mapping + // Flick mappings for (flick in keyWithFlicks.flicks) { val act = flick.toFlickAction() if (act is FlickAction.Action) { @@ -640,7 +625,7 @@ class KeyboardRepository @Inject constructor( } } - // 3) circular flick mapping + // Circular flick mappings for (cflick in keyWithFlicks.circularFlicks) { val act = cflick.toFlickAction() if (act is FlickAction.Action) { @@ -659,7 +644,7 @@ class KeyboardRepository @Inject constructor( } } - // two-step / long-press / two-step long-press は + // two-step flick / long-press flick / two-step long-press flick は // 出力テキスト (String) を保持する設計なので、KeyAction を // 持つことはなく MoveToCustomKeyboard 参照は発生しない。 // 将来的に actionType を持つ拡張があった場合はここに追加する。 @@ -923,6 +908,7 @@ class KeyboardRepository @Inject constructor( val iconRef = keyIconRefFromDb(dbKey.iconType, dbKey.iconValue) val specialKeyColorStyle = SpecialKeyColorStyle.fromDbValue(dbKey.specialKeyColorStyle) + val longPressAction = KeyActionMapper.toKeyAction(dbKey.longPressAction) val doubleTapBinding = KeyActionMapper.toKeyAction(dbKey.doubleTapAction) ?.takeIf { dbKey.isSpecialKey } ?.let { @@ -950,6 +936,7 @@ class KeyboardRepository @Inject constructor( action = null, specialKeyColorStyle = specialKeyColorStyle, doubleTapBinding = doubleTapBinding, + longPressAction = longPressAction, qwertyConfig = QwertyKeyConfigCodec.decode(dbKey.qwertyConfigJson), popupMapConfig = PopupKeyConfigCodec.decode(dbKey.popupMapConfigJson) ?.takeIf { dbKey.keyType == KeyType.FREE_FLICK }?.copy(keyId = dbKey.keyIdentifier), @@ -971,6 +958,7 @@ class KeyboardRepository @Inject constructor( action = restoredAction, specialKeyColorStyle = specialKeyColorStyle, doubleTapBinding = doubleTapBinding, + longPressAction = longPressAction, qwertyConfig = QwertyKeyConfigCodec.decode(dbKey.qwertyConfigJson), popupMapConfig = PopupKeyConfigCodec.decode(dbKey.popupMapConfigJson) ?.takeIf { dbKey.keyType == KeyType.FREE_FLICK }?.copy(keyId = dbKey.keyIdentifier), @@ -1249,6 +1237,7 @@ class KeyboardRepository @Inject constructor( doubleTapBinding?.action ), doubleTapPolicy = doubleTapBinding?.policy?.serializedName, + longPressAction = KeyActionMapper.fromKeyAction(keyData.longPressAction), popupMapConfigJson = keyData.popupMapConfig?.takeIf { keyData.keyType == KeyType.FREE_FLICK } ?.let(PopupKeyConfigCodec::encode), qwertyConfigJson = keyData.qwertyConfig?.let(QwertyKeyConfigCodec::encode), diff --git a/app/src/main/res/layout/fragment_key_editor.xml b/app/src/main/res/layout/fragment_key_editor.xml index fbc5914e5..f6503e38c 100644 --- a/app/src/main/res/layout/fragment_key_editor.xml +++ b/app/src/main/res/layout/fragment_key_editor.xml @@ -581,6 +581,40 @@ android:inputType="none" /> + + + + + + + + + +