From 8fd7c2825687eac7395b5f21ec5e1610ada9bc64 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 20 Dec 2018 09:59:10 -0600 Subject: [PATCH] In ReceiveTransactionFragment, add an 'Other...' option at the end of the assets spinner and when the user selects it an AutoCompleteTextView appears below where the user can select other asset, the AutoCompleteTextView suggestions will be backed by BitShares node queries to show matching Assets. --- .../fragments/ReceiveTransactionFragment.kt | 28 +++++++++--- .../layout/fragment_receive_transaction.xml | 43 ++++++++++--------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt index 515e881..4b3272f 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt @@ -38,6 +38,8 @@ import java.util.concurrent.TimeUnit class ReceiveTransactionFragment : Fragment() { private val TAG = this.javaClass.simpleName + private val OTHER_ASSET = "other_asset" + private lateinit var mUserAccountViewModel: UserAccountViewModel private lateinit var mAssetViewModel: AssetViewModel @@ -50,7 +52,7 @@ class ReceiveTransactionFragment : Fragment() { private var mAssetsAdapter: AssetsAdapter? = null - private var mAssets: List? = null + private var mAssets = ArrayList() private var selectedAssetSymbol = "" @@ -72,12 +74,21 @@ class ReceiveTransactionFragment : Fragment() { mUserAccount = UserAccount(user.id, user.name) }) + // Configure Assets spinner to show Assets already saved into the db mAssetViewModel = ViewModelProviders.of(this).get(AssetViewModel::class.java) mAssetViewModel.getAll().observe(this, Observer> { assets -> - mAssets = assets - mAssetsAdapter = AssetsAdapter(context!!, android.R.layout.simple_spinner_item, mAssets!!) + mAssets.clear() + mAssets.addAll(assets) + + // Add an option at the end so the user can search for an asset other than the ones saved in the db + val asset = cy.agorise.bitsybitshareswallet.database.entities.Asset( + OTHER_ASSET, "Other...", 0, "", "" + ) + mAssets.add(asset) + + mAssetsAdapter = AssetsAdapter(context!!, android.R.layout.simple_spinner_item, mAssets) spAsset.adapter = mAssetsAdapter // Try to select the selectedAssetSymbol @@ -94,9 +105,16 @@ class ReceiveTransactionFragment : Fragment() { override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { val asset = mAssetsAdapter!!.getItem(position)!! - selectedAssetSymbol = asset.symbol - mAsset = Asset(asset.id, asset.symbol, asset.precision) + if (asset.id == OTHER_ASSET) { + tilAsset.visibility = View.VISIBLE + mAsset = null + } else { + tilAsset.visibility = View.GONE + selectedAssetSymbol = asset.symbol + + mAsset = Asset(asset.id, asset.symbol, asset.precision) + } updateQR() } } diff --git a/app/src/main/res/layout/fragment_receive_transaction.xml b/app/src/main/res/layout/fragment_receive_transaction.xml index f507a5d..1069133 100644 --- a/app/src/main/res/layout/fragment_receive_transaction.xml +++ b/app/src/main/res/layout/fragment_receive_transaction.xml @@ -59,28 +59,29 @@ app:layout_constraintEnd_toEndOf="@+id/spAsset" app:layout_constraintStart_toStartOf="@+id/spAsset" /> - - - - - - - - - - + - - - - - - - - - + - +