2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Automatically close the 'auth-problems fragment' once we're through the auth flow (https://github.com/mozilla-mobile/fenix/pull/3340)

This commit is contained in:
Grisha Kruglov 2019-06-11 07:36:05 -07:00 committed by Colin Lee
parent 55aeb93e31
commit 21ca6f0a1d

View File

@ -7,23 +7,37 @@ package org.mozilla.fenix.settings
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.fragment.NavHostFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents
class AccountProblemFragment : PreferenceFragmentCompat() {
class AccountProblemFragment : PreferenceFragmentCompat(), AccountObserver {
override fun onResume() {
super.onResume()
(activity as AppCompatActivity).title = getString(R.string.sync_reconnect)
(activity as AppCompatActivity).supportActionBar?.show()
// We may have fixed our auth problem, in which case close this fragment.
if (requireComponents.backgroundServices.accountManager.authenticatedAccount() != null &&
!requireComponents.backgroundServices.accountManager.accountNeedsReauth()
) {
NavHostFragment.findNavController(this).popBackStack()
return
}
requireComponents.backgroundServices.accountManager.register(this, owner = this)
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@ -61,4 +75,24 @@ class AccountProblemFragment : PreferenceFragmentCompat() {
true
}
}
// We're told our auth problems have been fixed; close this fragment.
override fun onAuthenticated(account: OAuthAccount) {
CoroutineScope(Dispatchers.Main).launch {
NavHostFragment.findNavController(this@AccountProblemFragment).popBackStack()
}
}
override fun onAuthenticationProblems() {}
override fun onError(error: Exception) {}
// We're told there are no more auth problems since there is no more account; close this fragment.
override fun onLoggedOut() {
CoroutineScope(Dispatchers.Main).launch {
NavHostFragment.findNavController(this@AccountProblemFragment).popBackStack()
}
}
override fun onProfileUpdated(profile: Profile) {}
}