diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt index 4303dde0fe..8904f2c2d4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt @@ -848,13 +848,28 @@ private fun FolderSheet( renaming = false } val firstApp = remember { FocusRequester() } + val title = remember { FocusRequester() } + var toTitle by remember { mutableStateOf(false) } + var titleFocused by remember { mutableStateOf(false) } + val sheetView = androidx.compose.ui.platform.LocalView.current + val leaveName = { + if (renaming) { + (ctx.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager) + ?.hideSoftInputFromWindow(sheetView.windowToken, 0) + toTitle = true + commit() + } + } val inputMode = LocalInputModeManager.current.inputMode val ff = LocalFrontFocus.current val grid = rememberLazyGridState() var closing by remember { mutableStateOf(false) } var inside by remember { mutableStateOf(false) } LaunchedEffect(renaming, inputMode) { - if (!renaming && !closing && inputMode == InputMode.Keyboard && apps.isNotEmpty()) { + if (!renaming && !closing && toTitle) { + focusWithinFrames({ titleFocused || closing }) { title } + toTitle = false + } else if (!renaming && !closing && inputMode == InputMode.Keyboard && apps.isNotEmpty()) { grid.scrollToItem(0) androidx.compose.runtime.withFrameNanos { } // After touch, focus starts outside the page and the first request is turned to the page's own entry, behind the sheet. Ask until it is in here. @@ -885,6 +900,12 @@ private fun FolderSheet( .clip(Shape16).background(pal.surfaceVariant.copy(alpha = 0.97f)) .glideBorder(false, Shape16, pal.signal, pal.signal.copy(alpha = 0.22f)) .pointerInput(Unit) { awaitEachGesture { awaitFirstDown(requireUnconsumed = false).consume() } } + .onPreviewKeyEvent { event -> + val k = event.nativeKeyEvent + if (!renaming || k.keyCode != KeyEvent.KEYCODE_BUTTON_B) return@onPreviewKeyEvent false + if (k.action == KeyEvent.ACTION_DOWN && k.repeatCount == 0) leaveName() + true + } .controllerBack(close) .onFocusChanged { inside = it.hasFocus } .focusProperties { @@ -901,7 +922,7 @@ private fun FolderSheet( AdbTextField( value = name, onValueChange = { name = it.take(40) }, label = stringResource(R.string.apps_folder_name), keyboardType = KeyboardType.Text, imeAction = ImeAction.Done, compact = true, showLabel = false, - placeholder = folder.name, focusOnShow = true, onDone = { commit() }, + placeholder = folder.name, focusOnShow = true, onDone = { commit() }, onBack = leaveName, ) } else { val src = remember { MutableInteractionSource() } @@ -914,6 +935,8 @@ private fun FolderSheet( modifier = Modifier.clip(Shape12) .background(if (hot) pal.signal.copy(alpha = 0.12f) else colors.onBackground.copy(alpha = 0.07f)) .glideBorder(hot, Shape12, pal.signal) + .focusRequester(title) + .onFocusChanged { titleFocused = it.isFocused } .hoverable(src) .clickable(interactionSource = src, indication = LocalIndication.current, onClickLabel = stringResource(R.string.apps_folder_rename), role = Role.Button, onClick = rename) .controllerConfirm(onClick = rename) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt index a685e414f3..276f82f79f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt @@ -365,8 +365,10 @@ internal fun AdbTextField( onDone: (() -> Unit)? = null, focusOnShow: Boolean = false, showLabel: Boolean = true, + onBack: (() -> Unit)? = null, ) { val context = LocalContext.current + val onBackLatest = rememberUpdatedState(onBack) val focusAsked = remember { booleanArrayOf(false) } val palette = LocalPalette.current val onValueChangeLatest = rememberUpdatedState(onValueChange) @@ -384,7 +386,8 @@ internal fun AdbTextField( fun typeOnBottom(editText: EditText): Boolean { if (!bottomTypingLatest.value || !DualScreenPanel.attached) return false val text = editText.text.toString() - val request = TypingRequest( + lateinit var request: TypingRequest + request = TypingRequest( TextFieldValue(text, TextRange(editText.selectionStart.coerceIn(0, text.length), editText.selectionEnd.coerceIn(0, text.length))), ImeOptions(singleLine = true, keyboardType = keyboardType, imeAction = imeAction), { next -> @@ -392,7 +395,7 @@ internal fun AdbTextField( editText.setSelection(next.selection.start.coerceIn(0, next.text.length), next.selection.end.coerceIn(0, next.text.length)) }, { action -> editText.onEditorAction(imeActionFlag(action)) }, - { editText.post { editText.clearFocus() } }, + { editText.post { if (typingRequest[0] === request) onBackLatest.value?.invoke() ?: editText.clearFocus() } }, ) typingRequest[0] = request DualScreenPanel.startTyping(request) @@ -463,6 +466,7 @@ internal fun AdbTextField( ?.isVisible(androidx.core.view.WindowInsetsCompat.Type.ime()) == true if (hidingKeyboard) (view.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager) ?.hideSoftInputFromWindow(view.windowToken, 0) + onBackLatest.value?.let { hidingKeyboard = true; it() } } hidingKeyboard }