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.

master
Severiano Jaramillo 2019-03-20 13:55:16 -06:00
parent 756abb8f5f
commit 50526c6bda
3 changed files with 45 additions and 10 deletions

View File

@ -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<FaucetResponse>, 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()
}
}

View File

@ -107,6 +107,12 @@
android:layout_marginEnd="12dp"
android:layout_toStartOf="@id/btnCreate"
android:text="@android:string/cancel"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>

View File

@ -13,7 +13,6 @@
<item name="android:statusBarColor">@color/colorPrimaryVariant</item>
<item name="android:navigationBarColor">@color/colorPrimaryVariant</item>
</style>
<style name="Theme.Bitsy.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar"/>
<!-- Base application dark theme. -->
<style name="Theme.Bitsy.Dark" parent="Theme.MaterialComponents.NoActionBar">