- Adjusted how the Android virtual keyboard appears on the screen so that it does not distort the QR code image.

- Created a method to update the QR code when the user updates the Amount text field information, using RxJava debounce to avoid calls while the user is still typing.
- Created a method to remove the QR when there is no Asset selected.
master
Severiano Jaramillo 2018-12-07 15:18:23 -06:00
parent 28561d55f1
commit 04b509651b
5 changed files with 67 additions and 39 deletions

View File

@ -26,7 +26,9 @@
<activity android:name=".activities.LicenseActivity"/> <activity android:name=".activities.LicenseActivity"/>
<activity android:name=".activities.DatabaseLoadActivity"/> <activity android:name=".activities.DatabaseLoadActivity"/>
<activity android:name=".activities.ImportBrainkeyActivity"/> <activity android:name=".activities.ImportBrainkeyActivity"/>
<activity android:name=".activities.MainActivity"/> <activity
android:name=".activities.MainActivity"
android:windowSoftInputMode="adjustPan"/>
<activity <activity
android:name=".activities.SettingsActivity" android:name=".activities.SettingsActivity"
android:label="@string/title_settings"/> android:label="@string/title_settings"/>

View File

@ -24,8 +24,13 @@ import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.viewmodels.AssetViewModel import cy.agorise.bitsybitshareswallet.viewmodels.AssetViewModel
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
import cy.agorise.graphenej.* import cy.agorise.graphenej.*
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.fragment_receive_transaction.* import kotlinx.android.synthetic.main.fragment_receive_transaction.*
import java.lang.Exception
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -75,33 +80,53 @@ class ReceiveTransactionFragment : Fragment() {
updateQR() updateQR()
} }
// Use RxJava Debounce to create QR code only after the user stopped typing an amount
mDisposables.add(
RxTextView.textChanges(tietAmount)
.debounce(1000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { updateQR() }
)
// Use RxJava Debounce to avoid making calls to the NetworkService on every text change event // Use RxJava Debounce to avoid making calls to the NetworkService on every text change event
// mDisposables.add( mDisposables.add(
// RxTextView.textChanges(tietAmount) RxTextView.textChanges(actvAsset)
// .debounce(500, TimeUnit.MILLISECONDS) .debounce(500, TimeUnit.MILLISECONDS)
// .map { it.toString().trim() } .filter { it.toString().length < 3 }
// .filter { it.length > 1 } .observeOn(AndroidSchedulers.mainThread())
// .subscribe { .subscribe {
// mAsset = null
// } updateQR()
// ) }
)
} }
private fun updateQR() { private fun updateQR() {
val amount: Long = 10 if (mAsset == null) {
ivQR.setImageDrawable(null)
return
}
val total = Util.fromBase(AssetAmount(UnsignedLong.valueOf(amount), mAsset!!)) // Try to obtain the amount from the Amount Text Field or make it zero otherwise
val items = arrayOf(LineItem("transfer", 1, total)) val amount: Long = try {
val tmpAmount = tietAmount.text.toString().toDouble()
(tmpAmount * Math.pow(10.0, mAsset!!.precision.toDouble())).toLong()
}catch (e: Exception) {
0
}
val total = AssetAmount(UnsignedLong.valueOf(amount), mAsset!!)
val totalInDouble = Util.fromBase(total)
val items = arrayOf(LineItem("transfer", 1, totalInDouble))
val invoice = Invoice(mUserAccount!!.name, "", "#bitsy", mAsset!!.symbol, items, "", "") val invoice = Invoice(mUserAccount!!.name, "", "#bitsy", mAsset!!.symbol, items, "", "")
Log.d(TAG, "invoice: " + invoice.toJsonString()) Log.d(TAG, "invoice: " + invoice.toJsonString())
try { try {
val bitmap = encodeAsBitmap(Invoice.toQrCode(invoice), "#139657") // PalmPay green val bitmap = encodeAsBitmap(Invoice.toQrCode(invoice), "#139657") // PalmPay green
ivQR.setImageBitmap(bitmap) ivQR.setImageBitmap(bitmap)
// updateAmountAddressUI(total, mUserAccount!!.getName()) updateAmountAddressUI(total, mUserAccount!!.name)
} catch (e: WriterException) { } catch (e: WriterException) {
Log.e(TAG, "WriterException. Msg: " + e.message) Log.e(TAG, "WriterException. Msg: " + e.message)
} }
} }
/** /**
@ -149,26 +174,24 @@ class ReceiveTransactionFragment : Fragment() {
return bitmap return bitmap
} }
// /** /**
// * Updates the UI to show amount and address to send the payment * Updates the UI to show amount and account to send the payment
// * *
// * @param amount Amount in crypto to be paid * @param total Total Amount in crypto to be paid
// * @param address Address to pay amount * @param account Account to pay total
// */ */
// private fun updateAmountAddressUI(amount: Double, account: String) { private fun updateAmountAddressUI(total: AssetAmount, account: String) {
// // Trick to format correctly really small floating point numbers val df = DecimalFormat("####."+("#".repeat(total.asset.precision)))
// val df = DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)) df.roundingMode = RoundingMode.CEILING
// df.maximumFractionDigits = 340 df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
//
// val cryptoAmount = Helper.getCryptoAmountLocaleFormatted( val amount = total.amount.toDouble() / Math.pow(10.toDouble(), total.asset.precision.toDouble())
// locale, amount, val strAmount = df.format(amount)
// inputCoinType.toLowerCase(), this
// ) val txtAmount = getString(R.string.template__please_pay, strAmount, total.asset.symbol)
// val txtAccount = getString(R.string.template__to, account)
// val txtAmount = getString(R.string.please_pay_s_s, cryptoAmount, inputCoinType.toUpperCase())
// val txtAddress = getString(R.string.to_s, account) tvPleasePay.text = txtAmount
// tvTo.text = txtAccount
// tvTotalCryptoAmount.setText(txtAmount) }
// tvReceivingAddress.setText(txtAddress)
// }
} }

View File

@ -335,6 +335,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
for (nextItem in invoice.lineItems) { for (nextItem in invoice.lineItems) {
amount += nextItem.quantity * nextItem.price amount += nextItem.quantity * nextItem.price
} }
// TODO Improve pattern to account for different asset precisions
val df = DecimalFormat("####.#####") val df = DecimalFormat("####.#####")
df.roundingMode = RoundingMode.CEILING df.roundingMode = RoundingMode.CEILING
df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault()) df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())

View File

@ -79,7 +79,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:maxLines="1"
android:text="Please Pay: 12.25316 BTS" tools:text="Please Pay: 12.25316 BTS"
android:textAppearance="@style/TextAppearance.Bitsy.Body1" android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textAlignment="center" android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@id/tvTo"/> app:layout_constraintBottom_toTopOf="@id/tvTo"/>
@ -89,7 +89,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxLines="1" android:maxLines="1"
android:text="To: seventest-3" tools:text="To: seventest-3"
android:textAppearance="@style/TextAppearance.Bitsy.Body1" android:textAppearance="@style/TextAppearance.Bitsy.Body1"
android:textAlignment="center" android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"/> app:layout_constraintBottom_toBottomOf="parent"/>

View File

@ -47,6 +47,8 @@
<string name="text__memo">Memo</string> <string name="text__memo">Memo</string>
<string name="text__scan_qr">Scan QR</string> <string name="text__scan_qr">Scan QR</string>
<string name="text__asset">Asset</string> <string name="text__asset">Asset</string>
<string name="template__please_pay">Please pay: %1$s %2$s</string>
<string name="template__to">To: %1$s</string>
<!-- Settings --> <!-- Settings -->
<string name="title_settings">Settings</string> <string name="title_settings">Settings</string>