From 50526c6bda3356fbc78d3190466f2ec23cfd9f4f Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 20 Mar 2019 13:55:16 -0600 Subject: [PATCH] Added a loading indicator (ProgressBar) to the CreateAccountFragment that shows when the app is trying to create an account. This lets users know that the app is working avoiding users going back to the previous screen and preventing a crashlytics reported crash that happens when the create account response is received but the user is no longer in the CreateAccountFragment. --- .../fragments/CreateAccountFragment.kt | 48 +++++++++++++++---- .../res/layout/fragment_create_account.xml | 6 +++ app/src/main/res/values/styles.xml | 1 - 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt index 49237a6..e7e8567 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt @@ -219,14 +219,36 @@ class CreateAccountFragment : BaseAccountFragment() { onAccountSelected(result, tietPin.text.toString()) } else { context?.toast(getString(R.string.error__created_account_not_found)) + setStateError() } } + /** + * Sets the state to Loading, when the app is trying to create an account and waiting for the response. + */ + private fun setStateLoading() { + btnCancel.isEnabled = false + btnCreate.isEnabled = false + progressBar.visibility = View.VISIBLE + } + + /** + * Sets the state to Error, when the app is unable to create the account or unable to retrieve + * the information from the newly created account. + */ + private fun setStateError() { + btnCancel.isEnabled = true + btnCreate.isEnabled = false + progressBar.visibility = View.GONE + } + /** * Sends the account-creation request to the faucet server. * Only account name and public address is sent here. */ private fun createAccount() { + setStateLoading() + val accountName = tietAccountName.text.toString() val faucetRequest = FaucetRequest(accountName, mAddress, Constants.FAUCET_REFERRER) @@ -249,11 +271,15 @@ class CreateAccountFragment : BaseAccountFragment() { override fun onFailure(call: Call, t: Throwable) { // the network call was a failure - MaterialDialog(context!!) - .title(R.string.title_error) - .message(cy.agorise.bitsybitshareswallet.R.string.error__faucet) - .negativeButton(android.R.string.ok) - .show() + context?.let { context -> + MaterialDialog(context) + .title(R.string.title_error) + .message(cy.agorise.bitsybitshareswallet.R.string.error__faucet) + .negativeButton(android.R.string.ok) + .show() + } + + setStateError() } }) } @@ -273,10 +299,14 @@ class CreateAccountFragment : BaseAccountFragment() { getString(R.string.error__faucet_template, "None") } - MaterialDialog(context!!) - .title(R.string.title_error) - .message(text = content) - .show() + context?.let {context -> + MaterialDialog(context) + .title(R.string.title_error) + .message(text = content) + .show() + } + + setStateError() } } diff --git a/app/src/main/res/layout/fragment_create_account.xml b/app/src/main/res/layout/fragment_create_account.xml index a327b77..b8a119e 100644 --- a/app/src/main/res/layout/fragment_create_account.xml +++ b/app/src/main/res/layout/fragment_create_account.xml @@ -107,6 +107,12 @@ android:layout_marginEnd="12dp" android:layout_toStartOf="@id/btnCreate" android:text="@android:string/cancel"/> + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c3edbca..18efb8d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -13,7 +13,6 @@ @color/colorPrimaryVariant @color/colorPrimaryVariant -