summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-16 15:40:01 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2020-09-16 18:01:06 +0200
commit6789c11a7b44c221879b60e6b9397c9f8dd451d7 (patch)
treeb0b0fca9e1c5ec453d67fdbb0af8fe2b53b67d09
parentc56065fcfe9fb887cb7ccec23a7af22111f352bc (diff)
ConfigNamingDialogFragment: fix focus request for config naming dialog
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt20
-rw-r--r--ui/src/main/res/layout/config_naming_dialog_fragment.xml3
2 files changed, 18 insertions, 5 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt
index 03aad0f0..3c5d0ce9 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt
@@ -5,13 +5,16 @@
package com.wireguard.android.fragment
import android.app.Dialog
-import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
+import android.view.View
import android.view.inputmethod.InputMethodManager
+import androidx.annotation.IdRes
import androidx.appcompat.app.AlertDialog
+import androidx.core.content.getSystemService
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
+import com.google.android.material.textfield.TextInputEditText
import com.wireguard.android.Application
import com.wireguard.android.R
import com.wireguard.android.databinding.ConfigNamingDialogFragmentBinding
@@ -62,7 +65,7 @@ class ConfigNamingDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val activity = requireActivity()
- imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
+ imm = activity.getSystemService()
val alertDialogBuilder = AlertDialog.Builder(activity)
alertDialogBuilder.setTitle(R.string.import_from_qr_code)
binding = ConfigNamingDialogFragmentBinding.inflate(activity.layoutInflater, null, false)
@@ -72,7 +75,18 @@ class ConfigNamingDialogFragment : DialogFragment() {
}
alertDialogBuilder.setPositiveButton(R.string.create_tunnel, null)
alertDialogBuilder.setNegativeButton(R.string.cancel) { _, _ -> dismiss() }
- return alertDialogBuilder.create()
+ return alertDialogBuilder.create().apply {
+ setOnShowListener {
+ findViewById<TextInputEditText>(R.id.tunnel_name_text)?.apply {
+ setOnFocusChangeListener { v, _ ->
+ v.post {
+ imm?.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT)
+ }
+ }
+ requestFocus()
+ }
+ }
+ }
}
override fun onResume() {
diff --git a/ui/src/main/res/layout/config_naming_dialog_fragment.xml b/ui/src/main/res/layout/config_naming_dialog_fragment.xml
index a7017804..60a904b6 100644
--- a/ui/src/main/res/layout/config_naming_dialog_fragment.xml
+++ b/ui/src/main/res/layout/config_naming_dialog_fragment.xml
@@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <EditText
+ <com.google.android.material.textfield.TextInputEditText
android:id="@+id/tunnel_name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -29,5 +29,4 @@
</FrameLayout>
-
</layout>