aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-03-27 09:53:49 +0100
committerGitHub <noreply@github.com>2020-03-27 09:53:49 +0100
commit0153d3215ea5f3afa5076b4b5f51f98cc2482a47 (patch)
tree87ca4a4c18230c40bd5373112228db041ecbad5c /app/src/main/java
parentb21c032f3176510243e0fc73d5e81edec0634456 (diff)
Un-hack focus gain in folder creation dialog (#672)
The current way to let the folder name EditText in the folder creation dialog gain focus is... slightly hacky. This commit proposes a more conceptual solution, which, if it works reliably, could be much easier to maintain.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt30
1 files changed, 15 insertions, 15 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt
index e1262db1..bff229b9 100644
--- a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt
@@ -6,11 +6,8 @@ package com.zeapo.pwdstore.ui.dialogs
import android.app.Dialog
import android.os.Bundle
-import android.os.Handler
-import android.os.SystemClock
-import android.view.MotionEvent
+import android.view.inputmethod.InputMethodManager
import androidx.core.os.bundleOf
-import androidx.core.os.postDelayed
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.textfield.TextInputEditText
@@ -20,16 +17,6 @@ import java.io.File
class FolderCreationDialogFragment : DialogFragment() {
- override fun onResume() {
- // TODO: We really, really should not need this amount of hackery. WTF is going on?
- super.onResume()
- val editText = dialog?.findViewById<TextInputEditText>(R.id.folder_name_text)
- Handler().postDelayed(300) {
- editText?.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0f, 0f, 0))
- editText?.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0f, 0f, 0))
- }
- }
-
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val alertDialogBuilder = MaterialAlertDialogBuilder(requireContext())
alertDialogBuilder.setTitle(R.string.title_create_folder)
@@ -40,7 +27,20 @@ class FolderCreationDialogFragment : DialogFragment() {
alertDialogBuilder.setNegativeButton(getString(android.R.string.cancel)) { _, _ ->
dismiss()
}
- return alertDialogBuilder.create()
+ val dialog = alertDialogBuilder.create()
+ dialog.setOnShowListener {
+ // https://stackoverflow.com/a/13056259/297261
+ dialog.findViewById<TextInputEditText>(R.id.folder_name_text)!!.apply {
+ setOnFocusChangeListener { v, _ ->
+ v.post {
+ val imm = activity!!.getSystemService(InputMethodManager::class.java)
+ imm?.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT)
+ }
+ }
+ requestFocus()
+ }
+ }
+ return dialog
}
private fun createDirectory(currentDir: String) {