aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-02-10 09:47:07 +0530
committerGitHub <noreply@github.com>2020-02-10 09:47:07 +0530
commitbcdc43b1f1d4dbfbf3014a084c0b0c0ee5aa8207 (patch)
treedd97bb0c43050104ea2f4569179706fe1f53bbd3
parent085b946c7d3df2a7a24183b2949d4bacd5d16c5e (diff)
Gain focus in folder creation dialog (#624)
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Aditya Wasan <adityawasan55@gmail.com>
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/ui/dialogs/FolderCreationDialogFragment.kt23
1 files changed, 21 insertions, 2 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 3b00ec11..5132794c 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
@@ -5,9 +5,12 @@
package com.zeapo.pwdstore.ui.dialogs
import android.app.Dialog
-import android.content.DialogInterface
import android.os.Bundle
+import android.os.Handler
+import android.os.SystemClock
+import android.view.MotionEvent
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
@@ -16,13 +19,28 @@ import com.zeapo.pwdstore.R
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)
alertDialogBuilder.setView(R.layout.folder_creation_dialog_fragment)
- alertDialogBuilder.setPositiveButton(getString(R.string.button_create)) { _: DialogInterface, _: Int ->
+ alertDialogBuilder.setPositiveButton(getString(R.string.button_create)) { _, _ ->
createDirectory(requireArguments().getString(CURRENT_DIR_EXTRA)!!)
}
+ alertDialogBuilder.setNegativeButton(getString(android.R.string.cancel)) { _, _ ->
+ dismiss()
+ }
+ isCancelable = false
return alertDialogBuilder.create()
}
@@ -32,6 +50,7 @@ class FolderCreationDialogFragment : DialogFragment() {
val folderName = materialTextView.text.toString()
File("$currentDir/$folderName").mkdir()
(requireActivity() as PasswordStore).updateListAdapter()
+ dismiss()
}
companion object {