Navigate away from account settings after encountering auth problems
parent
47c14b07dd
commit
7af61b1560
|
@ -18,7 +18,10 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.concept.sync.AccountObserver
|
||||
import mozilla.components.concept.sync.ConstellationState
|
||||
import mozilla.components.concept.sync.OAuthAccount
|
||||
import mozilla.components.concept.sync.Profile
|
||||
import mozilla.components.concept.sync.DeviceConstellationObserver
|
||||
import mozilla.components.concept.sync.SyncStatusObserver
|
||||
import mozilla.components.feature.sync.getLastSynced
|
||||
|
@ -30,7 +33,7 @@ import org.mozilla.fenix.R
|
|||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import java.lang.Exception
|
||||
import kotlin.Exception
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
|
||||
|
@ -39,6 +42,27 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
|
|||
get() = Dispatchers.Main + job
|
||||
private lateinit var accountManager: FxaAccountManager
|
||||
|
||||
// Navigate away from this fragment when we encounter auth problems or logout events.
|
||||
private val accountStateObserver = object : AccountObserver {
|
||||
override fun onAuthenticated(account: OAuthAccount) {}
|
||||
|
||||
override fun onAuthenticationProblems() {
|
||||
launch {
|
||||
Navigation.findNavController(view!!).popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(error: Exception) {}
|
||||
|
||||
override fun onLoggedOut() {
|
||||
launch {
|
||||
Navigation.findNavController(view!!).popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProfileUpdated(profile: Profile) {}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
job = Job()
|
||||
|
@ -57,6 +81,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
|
|||
setPreferencesFromResource(R.xml.account_settings_preferences, rootKey)
|
||||
|
||||
accountManager = requireComponents.backgroundServices.accountManager
|
||||
accountManager.register(accountStateObserver, this, true)
|
||||
|
||||
// Sign out
|
||||
val signOut = context!!.getPreferenceKey(R.string.pref_key_sign_out)
|
||||
|
@ -101,7 +126,6 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
|
|||
requireComponents.analytics.metrics.track(Event.SyncAccountSignOut)
|
||||
launch {
|
||||
accountManager.logoutAsync().await()
|
||||
Navigation.findNavController(view!!).popBackStack()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue