From 6789c11a7b44c221879b60e6b9397c9f8dd451d7 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 16 Sep 2020 15:40:01 +0530 Subject: ConfigNamingDialogFragment: fix focus request for config naming dialog Signed-off-by: Harsh Shandilya --- .../android/fragment/ConfigNamingDialogFragment.kt | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'ui/src/main/java/com/wireguard/android') 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(R.id.tunnel_name_text)?.apply { + setOnFocusChangeListener { v, _ -> + v.post { + imm?.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT) + } + } + requestFocus() + } + } + } } override fun onResume() { -- cgit v1.2.3