From 67b70e3df298c44fc01ddd6575f3f7789acf9f0a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 31 Oct 2019 15:17:18 -0600 Subject: [PATCH] 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. --- .../fragments/SendTransactionFragment.kt | 16 +++++++++++++++- .../res/layout/fragment_send_transaction.xml | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) 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 1087f34..3fcfea0 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt @@ -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() @@ -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 { diff --git a/app/src/main/res/layout/fragment_send_transaction.xml b/app/src/main/res/layout/fragment_send_transaction.xml index 414b647..37f8ae1 100644 --- a/app/src/main/res/layout/fragment_send_transaction.xml +++ b/app/src/main/res/layout/fragment_send_transaction.xml @@ -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"