Fix problem with Navigation from the ImportBrainkeyFragment and CreateAccountFragment when an account is imported/created and the user has to be taken back to the MainFragment.

This commit is contained in:
Severiano Jaramillo 2019-01-08 20:18:42 -06:00
parent 78909498c0
commit 8894c48e5c
4 changed files with 49 additions and 40 deletions

View file

@ -2,6 +2,7 @@ package cy.agorise.bitsybitshareswallet.fragments
import android.preference.PreferenceManager import android.preference.PreferenceManager
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.database.entities.Authority import cy.agorise.bitsybitshareswallet.database.entities.Authority
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
@ -72,7 +73,7 @@ abstract class BaseAccountFragment : ConnectedFragment() {
} }
// Send the user back to HomeFragment // Send the user back to HomeFragment
findNavController().popBackStack() findNavController().navigate(R.id.home_action)
} }
/** /**

View file

@ -1,6 +1,7 @@
package cy.agorise.bitsybitshareswallet.fragments package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -33,6 +34,8 @@ import cy.agorise.bitsybitshareswallet.models.FaucetResponse
import cy.agorise.bitsybitshareswallet.network.ServiceGenerator import cy.agorise.bitsybitshareswallet.network.ServiceGenerator
import retrofit2.Call import retrofit2.Call
import retrofit2.Response import retrofit2.Response
import java.util.*
import kotlin.concurrent.timerTask
class CreateAccountFragment : BaseAccountFragment() { class CreateAccountFragment : BaseAccountFragment() {
@ -226,8 +229,11 @@ class CreateAccountFragment : BaseAccountFragment() {
// Execute the call asynchronously. Get a positive or negative callback. // Execute the call asynchronously. Get a positive or negative callback.
call.enqueue(object : Callback<FaucetResponse> { call.enqueue(object : Callback<FaucetResponse> {
override fun onResponse(call: Call<FaucetResponse>, response: Response<FaucetResponse>) { override fun onResponse(call: Call<FaucetResponse>, response: Response<FaucetResponse>) {
// The network call was a success and we got a response // The network call was a success and we got a response, obtain the info of the newly created account
getCreatedAccountInfo(response.body()) // with a delay to let the nodes update their information
Timer().schedule(timerTask {
getCreatedAccountInfo(response.body())
}, 4000)
} }
override fun onFailure(call: Call<FaucetResponse>, t: Throwable) { override fun onFailure(call: Call<FaucetResponse>, t: Throwable) {

View file

@ -53,7 +53,7 @@ class HomeFragment : Fragment() {
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: "" .getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: ""
if (agreedLicenseVersion != Constants.CURRENT_LICENSE_VERSION || userId == "") { if (agreedLicenseVersion != Constants.CURRENT_LICENSE_VERSION || userId == "") {
findNavController().navigate(R.id.setup_action) findNavController().navigate(R.id.license_action)
return return
} }
@ -61,7 +61,7 @@ class HomeFragment : Fragment() {
mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java) mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java)
mUserAccountViewModel.getUserAccount(userId).observe(this, Observer<UserAccount>{ user -> mUserAccountViewModel.getUserAccount(userId).observe(this, Observer<UserAccount>{ user ->
tvAccountName.text = user.name tvAccountName.text = user?.name ?: ""
}) })
// Navigate to the Receive Transaction Fragment // Navigate to the Receive Transaction Fragment

View file

@ -37,8 +37,8 @@
app:popExitAnim="@anim/slide_out_right"/> app:popExitAnim="@anim/slide_out_right"/>
<action <action
android:id="@+id/setup_action" android:id="@+id/license_action"
app:destination="@id/navigation_setup"/> app:destination="@id/license_dest"/>
</fragment> </fragment>
@ -78,46 +78,48 @@
android:defaultValue="false" /> android:defaultValue="false" />
</fragment> </fragment>
<navigation <fragment
android:id="@+id/navigation_setup" android:id="@+id/license_dest"
app:startDestination="@id/license_dest"> android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_license">
<fragment <action
android:id="@+id/license_dest" android:id="@+id/import_brainkey_action"
android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment" app:destination="@id/import_brainkey_dest"/>
android:label="@string/app_name"
tools:layout="@layout/fragment_license">
<action </fragment>
android:id="@+id/import_brainkey_action"
app:destination="@id/import_brainkey_dest"
app:popUpTo="@id/license_dest"
app:popUpToInclusive="true"/>
</fragment> <fragment
android:id="@+id/import_brainkey_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.ImportBrainkeyFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_import_brainkey">
<fragment <action
android:id="@+id/import_brainkey_dest" android:id="@+id/create_account_action"
android:name="cy.agorise.bitsybitshareswallet.fragments.ImportBrainkeyFragment" app:destination="@id/create_account_dest"
android:label="@string/app_name" app:enterAnim="@anim/slide_in_right"
tools:layout="@layout/fragment_import_brainkey"> app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
<action <action
android:id="@+id/create_account_action" android:id="@+id/home_action"
app:destination="@id/create_account_dest" app:popUpTo="@id/home_dest"/>
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
</fragment> </fragment>
<fragment <fragment
android:id="@+id/create_account_dest" android:id="@+id/create_account_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.CreateAccountFragment" android:name="cy.agorise.bitsybitshareswallet.fragments.CreateAccountFragment"
android:label="@string/app_name" android:label="@string/app_name"
tools:layout="@layout/fragment_create_account"/> tools:layout="@layout/fragment_create_account">
</navigation> <action
android:id="@+id/home_action"
app:popUpTo="@id/home_dest"/>
</fragment>
</navigation> </navigation>