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.
This commit is contained in:
parent
756abb8f5f
commit
50526c6bda
3 changed files with 45 additions and 10 deletions
|
@ -219,14 +219,36 @@ class CreateAccountFragment : BaseAccountFragment() {
|
||||||
onAccountSelected(result, tietPin.text.toString())
|
onAccountSelected(result, tietPin.text.toString())
|
||||||
} else {
|
} else {
|
||||||
context?.toast(getString(R.string.error__created_account_not_found))
|
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.
|
* Sends the account-creation request to the faucet server.
|
||||||
* Only account name and public address is sent here.
|
* Only account name and public address is sent here.
|
||||||
*/
|
*/
|
||||||
private fun createAccount() {
|
private fun createAccount() {
|
||||||
|
setStateLoading()
|
||||||
|
|
||||||
val accountName = tietAccountName.text.toString()
|
val accountName = tietAccountName.text.toString()
|
||||||
val faucetRequest = FaucetRequest(accountName, mAddress, Constants.FAUCET_REFERRER)
|
val faucetRequest = FaucetRequest(accountName, mAddress, Constants.FAUCET_REFERRER)
|
||||||
|
|
||||||
|
@ -249,12 +271,16 @@ class CreateAccountFragment : BaseAccountFragment() {
|
||||||
|
|
||||||
override fun onFailure(call: Call<FaucetResponse>, t: Throwable) {
|
override fun onFailure(call: Call<FaucetResponse>, t: Throwable) {
|
||||||
// the network call was a failure
|
// the network call was a failure
|
||||||
MaterialDialog(context!!)
|
context?.let { context ->
|
||||||
|
MaterialDialog(context)
|
||||||
.title(R.string.title_error)
|
.title(R.string.title_error)
|
||||||
.message(cy.agorise.bitsybitshareswallet.R.string.error__faucet)
|
.message(cy.agorise.bitsybitshareswallet.R.string.error__faucet)
|
||||||
.negativeButton(android.R.string.ok)
|
.negativeButton(android.R.string.ok)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStateError()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,11 +299,15 @@ class CreateAccountFragment : BaseAccountFragment() {
|
||||||
getString(R.string.error__faucet_template, "None")
|
getString(R.string.error__faucet_template, "None")
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialDialog(context!!)
|
context?.let {context ->
|
||||||
|
MaterialDialog(context)
|
||||||
.title(R.string.title_error)
|
.title(R.string.title_error)
|
||||||
.message(text = content)
|
.message(text = content)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStateError()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -107,6 +107,12 @@
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_toStartOf="@id/btnCreate"
|
android:layout_toStartOf="@id/btnCreate"
|
||||||
android:text="@android:string/cancel"/>
|
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>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
<item name="android:statusBarColor">@color/colorPrimaryVariant</item>
|
<item name="android:statusBarColor">@color/colorPrimaryVariant</item>
|
||||||
<item name="android:navigationBarColor">@color/colorPrimaryVariant</item>
|
<item name="android:navigationBarColor">@color/colorPrimaryVariant</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="Theme.Bitsy.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar"/>
|
|
||||||
|
|
||||||
<!-- Base application dark theme. -->
|
<!-- Base application dark theme. -->
|
||||||
<style name="Theme.Bitsy.Dark" parent="Theme.MaterialComponents.NoActionBar">
|
<style name="Theme.Bitsy.Dark" parent="Theme.MaterialComponents.NoActionBar">
|
||||||
|
|
Loading…
Reference in a new issue