summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-03-23 14:31:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-24 14:12:21 +0100
commitcaf2cded6edf087c55bce873e649388daf234724 (patch)
tree6633d0d5fd37835eb9363c578d289458b87d1a8a
parentb44380c81a17efc6ed52c0ca65b3adf2cac5637e (diff)
ui: simplify IME displaying in ConfigNamingDialogFragment
Also cleanup some event listener flow. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt48
-rw-r--r--ui/src/main/res/layout/config_naming_dialog_fragment.xml5
2 files changed, 8 insertions, 45 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 df6908b1..97f2ec73 100644
--- a/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt
+++ b/ui/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.kt
@@ -5,15 +5,11 @@
package com.wireguard.android.fragment
import android.app.Dialog
-import android.content.DialogInterface
import android.os.Bundle
-import android.view.inputmethod.InputMethodManager
-import androidx.appcompat.app.AlertDialog
-import androidx.core.content.getSystemService
+import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import com.google.android.material.textfield.TextInputEditText
import com.wireguard.android.Application
import com.wireguard.android.R
import com.wireguard.android.databinding.ConfigNamingDialogFragmentBinding
@@ -27,7 +23,6 @@ import java.nio.charset.StandardCharsets
class ConfigNamingDialogFragment : DialogFragment() {
private var binding: ConfigNamingDialogFragmentBinding? = null
private var config: Config? = null
- private var imm: InputMethodManager? = null
private fun createTunnelAndDismiss() {
val binding = binding ?: return
@@ -42,12 +37,6 @@ class ConfigNamingDialogFragment : DialogFragment() {
}
}
}
-
- override fun dismiss() {
- setKeyboardVisible(false)
- super.dismiss()
- }
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val configText = requireArguments().getString(KEY_CONFIG_TEXT)
@@ -64,7 +53,6 @@ class ConfigNamingDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val activity = requireActivity()
- imm = activity.getSystemService()
val alertDialogBuilder = MaterialAlertDialogBuilder(activity)
alertDialogBuilder.setTitle(R.string.import_from_qr_code)
binding = ConfigNamingDialogFragmentBinding.inflate(activity.layoutInflater, null, false)
@@ -72,37 +60,11 @@ class ConfigNamingDialogFragment : DialogFragment() {
executePendingBindings()
alertDialogBuilder.setView(root)
}
- alertDialogBuilder.setPositiveButton(R.string.create_tunnel, null)
+ alertDialogBuilder.setPositiveButton(R.string.create_tunnel) { _, _ -> createTunnelAndDismiss() }
alertDialogBuilder.setNegativeButton(R.string.cancel) { _, _ -> dismiss() }
- 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() {
- super.onResume()
- val dialog = dialog as AlertDialog?
- if (dialog != null) {
- dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener { createTunnelAndDismiss() }
- setKeyboardVisible(true)
- }
- }
-
- private fun setKeyboardVisible(visible: Boolean) {
- if (visible) {
- imm!!.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
- } else if (binding != null) {
- imm!!.hideSoftInputFromWindow(binding!!.tunnelNameText.windowToken, 0)
- }
+ val dialog = alertDialogBuilder.create()
+ dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
+ return dialog
}
companion object {
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 0fd88c6c..88deb976 100644
--- a/ui/src/main/res/layout/config_naming_dialog_fragment.xml
+++ b/ui/src/main/res/layout/config_naming_dialog_fragment.xml
@@ -3,7 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
-
<import type="com.wireguard.android.widget.NameInputFilter" />
</data>
@@ -24,7 +23,9 @@
android:hint="@string/tunnel_name"
android:imeOptions="actionDone"
android:inputType="textNoSuggestions|textVisiblePassword"
- app:filter="@{NameInputFilter.newInstance()}" />
+ app:filter="@{NameInputFilter.newInstance()}">
+ <requestFocus/>
+ </com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>