From 8894c48e5c3d405402cccf2ecac0dd50cd8d0afb Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 8 Jan 2019 20:18:42 -0600 Subject: [PATCH] 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. --- .../fragments/BaseAccountFragment.kt | 3 +- .../fragments/CreateAccountFragment.kt | 10 ++- .../fragments/HomeFragment.kt | 4 +- .../main/res/navigation/mobile_navigation.xml | 72 ++++++++++--------- 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt index 56a3fa7..b45f613 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt @@ -2,6 +2,7 @@ package cy.agorise.bitsybitshareswallet.fragments import android.preference.PreferenceManager import androidx.navigation.fragment.findNavController +import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.database.entities.Authority import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository @@ -72,7 +73,7 @@ abstract class BaseAccountFragment : ConnectedFragment() { } // Send the user back to HomeFragment - findNavController().popBackStack() + findNavController().navigate(R.id.home_action) } /** 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 dc25c73..3cc2730 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt @@ -1,6 +1,7 @@ package cy.agorise.bitsybitshareswallet.fragments import android.os.Bundle +import android.preference.PreferenceManager import android.util.Log import android.view.LayoutInflater import android.view.View @@ -33,6 +34,8 @@ import cy.agorise.bitsybitshareswallet.models.FaucetResponse import cy.agorise.bitsybitshareswallet.network.ServiceGenerator import retrofit2.Call import retrofit2.Response +import java.util.* +import kotlin.concurrent.timerTask class CreateAccountFragment : BaseAccountFragment() { @@ -226,8 +229,11 @@ class CreateAccountFragment : BaseAccountFragment() { // Execute the call asynchronously. Get a positive or negative callback. call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { - // The network call was a success and we got a response - getCreatedAccountInfo(response.body()) + // The network call was a success and we got a response, obtain the info of the newly created account + // with a delay to let the nodes update their information + Timer().schedule(timerTask { + getCreatedAccountInfo(response.body()) + }, 4000) } override fun onFailure(call: Call, t: Throwable) { diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt index e213fcc..be56fa5 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt @@ -53,7 +53,7 @@ class HomeFragment : Fragment() { .getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: "" if (agreedLicenseVersion != Constants.CURRENT_LICENSE_VERSION || userId == "") { - findNavController().navigate(R.id.setup_action) + findNavController().navigate(R.id.license_action) return } @@ -61,7 +61,7 @@ class HomeFragment : Fragment() { mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java) mUserAccountViewModel.getUserAccount(userId).observe(this, Observer{ user -> - tvAccountName.text = user.name + tvAccountName.text = user?.name ?: "" }) // Navigate to the Receive Transaction Fragment diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index bded66c..aa1bb35 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -37,8 +37,8 @@ app:popExitAnim="@anim/slide_out_right"/> + android:id="@+id/license_action" + app:destination="@id/license_dest"/> @@ -78,46 +78,48 @@ android:defaultValue="false" /> - + - + - + - + - + - + - + - + - + + + \ No newline at end of file