Merge pull request #12014 from nextcloud/fix/softkeyboard

Fix softKeyboard not appearing
This commit is contained in:
Andy Scherzinger 2023-10-13 17:40:43 +02:00 committed by GitHub
commit 303950d9a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 23 deletions

View file

@ -138,7 +138,7 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
@Override
public void onResume() {
super.onResume();
keyboardUtils.showKeyboardForEditText(binding.filename);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.filename);
}
@NonNull

View file

@ -119,7 +119,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
override fun onResume() {
super.onResume()
keyboardUtils.showKeyboardForEditText(binding.filename)
keyboardUtils.showKeyboardForEditText(dialog?.window, binding.filename)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

View file

@ -116,7 +116,7 @@ public class CreateFolderDialogFragment
super.onResume();
bindButton();
keyboardUtils.showKeyboardForEditText(binding.userInput);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.userInput);
}
@NonNull

View file

@ -90,7 +90,7 @@ public class NoteDialogFragment extends DialogFragment implements DialogInterfac
@Override
public void onResume() {
super.onResume();
keyboardUtils.showKeyboardForEditText(binding.noteText);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.noteText);
}
@NonNull

View file

@ -103,7 +103,7 @@ public class RenameFileDialogFragment
@Override
public void onResume() {
super.onResume();
keyboardUtils.showKeyboardForEditText(binding.userInput);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.userInput);
}
@NonNull

View file

@ -83,7 +83,7 @@ public class RenamePublicShareDialogFragment
@Override
public void onResume() {
super.onResume();
keyboardUtils.showKeyboardForEditText(binding.userInput);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.userInput);
}
@NonNull

View file

@ -99,7 +99,7 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
@Override
public void onResume() {
super.onResume();
keyboardUtils.showKeyboardForEditText(binding.sharePassword);
keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.sharePassword);
}
/**

View file

@ -1,7 +1,9 @@
/*
* Nextcloud Android client application
*
* @author ZetaTom
* @author Álvaro Brey
* Copyright (C) 2023 ZetaTom
* Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Nextcloud GmbH
*
@ -22,26 +24,18 @@
package com.owncloud.android.utils
import android.content.Context
import android.view.inputmethod.InputMethodManager
import android.view.Window
import android.widget.EditText
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import javax.inject.Inject
class KeyboardUtils @Inject constructor() {
fun showKeyboardForEditText(editText: EditText) {
editText.requestFocus()
// needs 100ms delay to account for focus animations
editText.postDelayed({
val context = editText.context
if (context != null) {
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
}, SHOW_INPUT_DELAY_MILLIS)
}
companion object {
private const val SHOW_INPUT_DELAY_MILLIS = 100L
fun showKeyboardForEditText(window: Window?, editText: EditText) {
if (window != null) {
editText.requestFocus()
WindowCompat.getInsetsController(window, editText).show(WindowInsetsCompat.Type.ime())
}
}
}