Show the keyboard when selecting Other in Receive.

- Automatically show the keyboard and focus the AutoCompleteTextView when the user selects 'Other...' in the Asset spinner, in the Receive screen.
- Created an extension function for EditText, which requests focus and shows the keyboard at the same time, so that the user can immediately start typing the desired text.
master
Severiano Jaramillo 2019-12-25 18:07:27 -06:00
parent 9cabc0565a
commit 3b5d04abd4
2 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import cy.agorise.bitsybitshareswallet.adapters.AssetsAdapter
import cy.agorise.bitsybitshareswallet.adapters.AutoSuggestAssetAdapter
import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.utils.Helper
import cy.agorise.bitsybitshareswallet.utils.showKeyboard
import cy.agorise.bitsybitshareswallet.utils.toast
import cy.agorise.bitsybitshareswallet.viewmodels.ReceiveTransactionViewModel
import cy.agorise.graphenej.*
@ -156,6 +157,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
mAssetsAdapter?.getItem(position)?.let { asset ->
if (asset.id == OTHER_ASSET) {
tilAsset.visibility = View.VISIBLE
actvAsset.showKeyboard()
mAsset = null
} else {
tilAsset.visibility = View.GONE

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
@ -52,4 +53,13 @@ fun String.containsVowels(): Boolean {
fun View.hideKeyboard(){
val inputMethodManager = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(this.windowToken, 0)
}
/**
* Allows to request focus and show the Keyboard from an EditText (and its sub-classes).
*/
fun EditText.showKeyboard() {
requestFocus()
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
}