From b628260d7731935c972a95be3549e39173a85ea5 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 31 Jan 2019 18:52:41 -0600 Subject: [PATCH] Make all smartcoins to show the 'bit' prefix in all the screens that show them, but keeping the original asset symbol unmodified to be used in the places where the symbol is required. --- .../adapters/AssetsAdapter.kt | 4 +-- .../adapters/BalancesAdapter.kt | 2 +- .../adapters/BalancesDetailsAdapter.kt | 4 +-- .../database/entities/Asset.kt | 3 +++ .../database/joins/BalanceDetail.kt | 12 +++++++-- .../database/joins/BalanceDetailDao.kt | 2 +- .../fragments/ReceiveTransactionFragment.kt | 26 +++++++++++-------- .../fragments/SendTransactionFragment.kt | 2 +- 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/AssetsAdapter.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/AssetsAdapter.kt index ccfd3cc..9b99ed7 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/AssetsAdapter.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/AssetsAdapter.kt @@ -22,7 +22,7 @@ class AssetsAdapter(context: Context, resource: Int, data: List) : val text: TextView = cv!!.findViewById(android.R.id.text1) val asset = getItem(position) - text.text = asset!!.symbol + text.text = asset?.toString() return cv } @@ -33,7 +33,7 @@ class AssetsAdapter(context: Context, resource: Int, data: List) : val text: TextView = v.findViewById(android.R.id.text1) val asset = getItem(position) - text.text = asset!!.symbol + text.text = asset?.toString() return v } diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesAdapter.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesAdapter.kt index 58451f0..c2009fd 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesAdapter.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesAdapter.kt @@ -63,7 +63,7 @@ class BalancesAdapter(private val context: Context) : override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { val balance = mSortedList.get(position) - viewHolder.tvSymbol.text = balance.symbol + viewHolder.tvSymbol.text = balance.toString() val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble()) viewHolder.tvAmount.text = String.format("%." + Math.min(balance.precision, 8) + "f", amount) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesDetailsAdapter.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesDetailsAdapter.kt index 4428ddf..cdd50e0 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesDetailsAdapter.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/adapters/BalancesDetailsAdapter.kt @@ -26,7 +26,7 @@ class BalancesDetailsAdapter(context: Context, resource: Int, data: List 0") fun getAll(): LiveData> } \ No newline at end of file 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 71a0cd8..25433df 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt @@ -71,6 +71,7 @@ class ReceiveTransactionFragment : ConnectedFragment() { private var mAssets = ArrayList() + /** Keeps track of the current selected asset symbol */ private var selectedAssetSymbol = "" /** Used to avoid erasing the QR code when the user selects an item from the AutoComplete suggestions */ @@ -150,7 +151,7 @@ class ReceiveTransactionFragment : ConnectedFragment() { tilAsset.visibility = View.GONE selectedAssetSymbol = asset.symbol - mAsset = Asset(asset.id, asset.symbol, asset.precision) + mAsset = Asset(asset.id, asset.toString(), asset.precision) } updateQR() } @@ -194,7 +195,7 @@ class ReceiveTransactionFragment : ConnectedFragment() { actvAsset.setOnItemClickListener { parent, _, position, _ -> val asset = parent.adapter.getItem(position) as cy.agorise.bitsybitshareswallet.database.entities.Asset - mAsset = Asset(asset.id, asset.symbol, asset.precision) + mAsset = Asset(asset.id, asset.toString(), asset.precision) selectedInAutoCompleteTextView = true updateQR() } @@ -250,23 +251,26 @@ class ReceiveTransactionFragment : ConnectedFragment() { return } + val asset = mAsset!! + // Try to obtain the amount from the Amount Text Field or make it zero otherwise val amount: Long = try { val tmpAmount = tietAmount.text.toString().toDouble() - (tmpAmount * Math.pow(10.0, mAsset!!.precision.toDouble())).toLong() + (tmpAmount * Math.pow(10.0, asset.precision.toDouble())).toLong() }catch (e: Exception) { 0 } - val total = AssetAmount(UnsignedLong.valueOf(amount), mAsset!!) + val total = AssetAmount(UnsignedLong.valueOf(amount), asset) val totalInDouble = Util.fromBase(total) val items = arrayOf(LineItem("transfer", 1, totalInDouble)) - val invoice = Invoice(mUserAccount!!.name, "", "", mAsset!!.symbol, items, "", "") + val invoice = Invoice(mUserAccount?.name, "", "", + asset.symbol.replaceFirst("bit", ""), items, "", "") Log.d(TAG, "invoice: " + invoice.toJsonString()) try { val bitmap = encodeAsBitmap(Invoice.toQrCode(invoice), "#139657") // PalmPay green ivQR.setImageBitmap(bitmap) - updateAmountAddressUI(total, mUserAccount!!.name) + updateAmountAddressUI(amount, asset.symbol, asset.precision, mUserAccount!!.name) } catch (e: WriterException) { Log.e(TAG, "WriterException. Msg: " + e.message) } @@ -323,17 +327,17 @@ class ReceiveTransactionFragment : ConnectedFragment() { * @param total Total Amount in crypto to be paid * @param account Account to pay total */ - private fun updateAmountAddressUI(total: AssetAmount, account: String) { - val txtAmount: String = if (total.amount.toLong() == 0L) { + private fun updateAmountAddressUI(assetAmount: Long, assetSymbol: String, assetPrecision: Int, account: String) { + val txtAmount: String = if (assetAmount == 0L) { getString(R.string.template__please_send, getString(R.string.text__any_amount), " ") } else { - val df = DecimalFormat("####."+("#".repeat(total.asset.precision))) + val df = DecimalFormat("####."+("#".repeat(assetPrecision))) df.roundingMode = RoundingMode.CEILING df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault()) - val amount = total.amount.toDouble() / Math.pow(10.toDouble(), total.asset.precision.toDouble()) + val amount = assetAmount.toDouble() / Math.pow(10.toDouble(), assetPrecision.toDouble()) val strAmount = df.format(amount) - getString(R.string.template__please_send, strAmount, total.asset.symbol) + getString(R.string.template__please_send, strAmount, assetSymbol) } val txtAccount = getString(R.string.template__to, account) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt index f621e7f..f3e1cdf 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt @@ -213,7 +213,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble()) tvAvailableAssetAmount.text = - String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.symbol) + String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.toString()) validateAmount() }