Commit 25500a79 authored by ValentinTimisica's avatar ValentinTimisica
Browse files

For #6295: Clear focus for username/password when Done is pressed

parent fb8dbbe4
......@@ -33,6 +33,7 @@ import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginValidationDelegate
import mozilla.components.concept.storage.LoginValidationDelegate.Result
import mozilla.components.feature.prompts.R
import mozilla.components.feature.prompts.ext.onDone
import mozilla.components.support.ktx.android.content.appName
import mozilla.components.support.ktx.android.view.toScope
import kotlin.reflect.KProperty
......@@ -50,7 +51,7 @@ private const val KEY_LOGIN_HTTP_REALM = "KEY_LOGIN_HTTP_REALM"
* [android.support.v4.app.DialogFragment] implementation to display a
* dialog that allows users to save/update usernames and passwords for a given domain.
*/
@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "LargeClass")
internal class LoginDialogFragment : PromptDialogFragment() {
private inner class SafeArgString(private val key: String) {
......@@ -162,6 +163,12 @@ internal class LoginDialogFragment : PromptDialogFragment() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) =
Unit
})
with(usernameEditText) {
onDone(false) {
clearFocus()
}
}
}
private fun bindPassword(view: View) {
......@@ -192,6 +199,12 @@ internal class LoginDialogFragment : PromptDialogFragment() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
})
with(passwordEditText) {
onDone(false) {
clearFocus()
}
}
}
/**
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.feature.prompts.ext
import android.view.inputmethod.EditorInfo
import android.widget.EditText
/**
* Extension function to handle keyboard Done action
* @param actionConsumed true if you have consumed the action, else false.
* @param onDonePressed callback to execute when Done key is pressed
*/
internal fun EditText.onDone(actionConsumed: Boolean, onDonePressed: () -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
when (actionId) {
EditorInfo.IME_ACTION_DONE -> {
onDonePressed()
actionConsumed
}
else -> false
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment