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 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)
}
/**

View file

@ -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<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
// 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) {

View file

@ -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<UserAccount>{ user ->
tvAccountName.text = user.name
tvAccountName.text = user?.name ?: ""
})
// Navigate to the Receive Transaction Fragment

View file

@ -37,8 +37,8 @@
app:popExitAnim="@anim/slide_out_right"/>
<action
android:id="@+id/setup_action"
app:destination="@id/navigation_setup"/>
android:id="@+id/license_action"
app:destination="@id/license_dest"/>
</fragment>
@ -78,10 +78,6 @@
android:defaultValue="false" />
</fragment>
<navigation
android:id="@+id/navigation_setup"
app:startDestination="@id/license_dest">
<fragment
android:id="@+id/license_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment"
@ -90,9 +86,7 @@
<action
android:id="@+id/import_brainkey_action"
app:destination="@id/import_brainkey_dest"
app:popUpTo="@id/license_dest"
app:popUpToInclusive="true"/>
app:destination="@id/import_brainkey_dest"/>
</fragment>
@ -110,14 +104,22 @@
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
<action
android:id="@+id/home_action"
app:popUpTo="@id/home_dest"/>
</fragment>
<fragment
android:id="@+id/create_account_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.CreateAccountFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_create_account"/>
</navigation>
tools:layout="@layout/fragment_create_account">
<action
android:id="@+id/home_action"
app:popUpTo="@id/home_dest"/>
</fragment>
</navigation>