Commit 77553a15 authored by MozLando's avatar MozLando
Browse files

Merge #6296



6296: For #6295: Clear focus for username/password when Done is pressed r=psymoon a=ValentinTimisica
Co-authored-by: default avatarValentinTimisica <valentin.timisica@softvision.ro>
parents 1341d92f d352fe51
......@@ -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
}
}
}
/* 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
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.robolectric.testContext
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.mockito.Mockito.never
@RunWith(AndroidJUnit4::class)
class EditTextTest {
private val onDonePressed: () -> Unit = spy {}
@Test
fun `GIVEN a callback, WHEN action done is performed - IME_ACTION_DONE -, THEN onDonePress should be called`() {
val view = EditText(testContext)
val editorInfo = EditorInfo()
val inputConnection = view.onCreateInputConnection(editorInfo)
view.onDone(false, onDonePressed)
inputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE)
verify(onDonePressed).invoke()
}
@Test
fun `GIVEN a callback, WHEN a different action is performed - IME_ACTION_SEARCH -, THEN onDonePress shouldn't be called `() {
val view = EditText(testContext)
val editorInfo = EditorInfo()
val inputConnection = view.onCreateInputConnection(editorInfo)
view.onDone(false, onDonePressed)
inputConnection.performEditorAction(EditorInfo.IME_ACTION_SEARCH)
verify(onDonePressed, never()).invoke()
}
}
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