Limit the memo length to 100 in the Send screen.

- For some reason if we use a memo longer than 107 chars we get an error, to avoid that error we are limiting the memo length to 100 chars using TextInputLayout's counter options to show the current char count and the max char count. If the current char count exceeds the max the TextInputLayout turns to red and the Send button is disabled.
This commit is contained in:
Severiano Jaramillo 2019-10-31 15:17:18 -06:00
parent 36c9c5928e
commit 67b70e3df2
2 changed files with 17 additions and 2 deletions

View file

@ -82,6 +82,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
private var isCameraPreviewVisible = false
private var isToAccountCorrect = false
private var isAmountCorrect = false
private var isMemoCorrect = true
private var mBalancesDetails = ArrayList<BalanceDetail>()
@ -213,6 +214,19 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
.subscribe { validateAmount() }
)
// Use RxJava Debounce to update the Memo error, to make sure it has the correct length
mDisposables.add(
tietMemo.textChanges()
.skipInitialValue()
.debounce(500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.map { it.toString().trim() }
.subscribe {
isMemoCorrect = it.length <= tilMemo.counterMaxLength
enableDisableSendFAB()
}
)
// Populates the To field if a Deep Link was used
if (args.to != " " && args.asset != " " && args.amount > 0 && args.memo != " ") {
val items = arrayOf(LineItem("transfer", 1, args.amount.toDouble()))
@ -488,7 +502,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
}
private fun enableDisableSendFAB() {
if (isToAccountCorrect && isAmountCorrect) {
if (isToAccountCorrect && isAmountCorrect && isMemoCorrect) {
fabSendTransaction.enable(R.color.colorSend)
vSend.setBackgroundResource(R.drawable.send_fab_background)
} else {

View file

@ -133,6 +133,8 @@
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:hint="@string/text__memo"
app:counterEnabled="true"
app:counterMaxLength="100"
app:layout_constraintTop_toBottomOf="@id/tilAmount"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
@ -150,7 +152,6 @@
android:id="@+id/tvScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_same_topic"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:text="@string/text__scan_qr"
android:textAppearance="@style/TextAppearance.Bitsy.Body1"