1
0
Fork 0

No issue: Fix breaking AccountObserver API

master
Jonathan Almeida 2019-08-02 11:32:42 -04:00 committed by Jonathan Almeida
parent 29f089c414
commit ec96d134ff
9 changed files with 9 additions and 58 deletions

View File

@ -25,7 +25,6 @@ import mozilla.components.service.fxa.DeviceConfig
import mozilla.components.service.fxa.ServerConfig
import mozilla.components.service.fxa.SyncConfig
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.feature.push.AutoPushFeature
import mozilla.components.feature.push.AutoPushSubscription
import mozilla.components.feature.push.PushConfig
@ -134,26 +133,16 @@ class BackgroundServices(
* of the send-tab/push feature: https://github.com/mozilla-mobile/fenix/issues/4063
*/
private val accountObserver = object : AccountObserver {
// We want to update our subscriptions only on a fresh sign in.
// See https://github.com/mozilla-mobile/android-components/issues/3964
@Suppress("MayBeConst") // linter is wrong
val prefFreshSignInKey = "fresh_sign_in"
override fun onAuthenticationProblems() {}
override fun onProfileUpdated(profile: Profile) {}
override fun onLoggedOut() {
pushService.stop()
preferences.edit().putBoolean(prefFreshSignInKey, true).apply()
push.unsubscribeForType(PushType.Services)
}
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
pushService.start(context)
if (preferences.getBoolean(prefFreshSignInKey, true)) {
preferences.edit().putBoolean(prefFreshSignInKey, false).apply()
if (newAccount) {
push.subscribeForType(PushType.Services)
}
}

View File

@ -6,7 +6,6 @@ package org.mozilla.fenix.customtabs
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.service.fxa.manager.FxaAccountManager
import org.mozilla.fenix.ext.components
@ -15,15 +14,9 @@ class AuthCustomTabActivity : CustomTabActivity() {
// Navigate away from this activity when we have successful authentication
private val accountStateObserver = object : AccountObserver {
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
this@AuthCustomTabActivity.finish()
}
override fun onAuthenticationProblems() {}
override fun onLoggedOut() {}
override fun onProfileUpdated(profile: Profile) {}
}
override fun onResume() {

View File

@ -732,7 +732,7 @@ class HomeFragment : Fragment(), AccountObserver {
}
}
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
view?.let {
FenixSnackbar.make(it, Snackbar.LENGTH_SHORT).setText(
it.context.getString(R.string.onboarding_firefox_account_sync_is_on)

View File

@ -31,7 +31,6 @@ import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.BackHandler
import org.mozilla.fenix.R
@ -222,7 +221,7 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
override fun onBackPressed(): Boolean = bookmarkView.onBackPressed()
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
bookmarkInteractor.signedIn()
lifecycleScope.launch {
refreshBookmarks()
@ -233,12 +232,6 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), BackHandler, Accou
bookmarkInteractor.signedOut()
}
override fun onAuthenticationProblems() {
}
override fun onProfileUpdated(profile: Profile) {
}
private suspend fun refreshBookmarks() {
context?.bookmarkStorage()?.getTree(bookmarkStore.state.tree!!.guid, false).withOptionalDesktopFolders(context)
?.let { node ->

View File

@ -29,7 +29,6 @@ import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.ext.nav
@ -125,18 +124,11 @@ class SelectBookmarkFolderFragment : Fragment(), AccountObserver {
else -> super.onOptionsItemSelected(item)
}
}
override fun onAuthenticationProblems() {
}
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
bookmarkInteractor.signedIn()
}
override fun onLoggedOut() {
bookmarkInteractor.signedOut()
}
override fun onProfileUpdated(profile: Profile) {
}
}

View File

@ -13,7 +13,6 @@ import androidx.preference.PreferenceFragmentCompat
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.R
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.nav
@ -71,20 +70,16 @@ class AccountProblemFragment : PreferenceFragmentCompat(), AccountObserver {
}
// We're told our auth problems have been fixed; close this fragment.
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
lifecycleScope.launch {
NavHostFragment.findNavController(this@AccountProblemFragment).popBackStack()
}
}
override fun onAuthenticationProblems() {}
// We're told there are no more auth problems since there is no more account; close this fragment.
override fun onLoggedOut() {
lifecycleScope.launch {
NavHostFragment.findNavController(this@AccountProblemFragment).popBackStack()
}
}
override fun onProfileUpdated(profile: Profile) {}
}

View File

@ -22,8 +22,6 @@ import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.ConstellationState
import mozilla.components.concept.sync.DeviceConstellationObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.service.fxa.FxaException
import mozilla.components.service.fxa.FxaPanicException
import mozilla.components.service.fxa.manager.FxaAccountManager
@ -42,8 +40,6 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
// 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() {
lifecycleScope.launch {
findNavController().popBackStack()
@ -61,8 +57,6 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
}
}
}
override fun onProfileUpdated(profile: Profile) {}
}
override fun onResume() {

View File

@ -326,7 +326,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
Navigation.findNavController(view!!).navigate(directions)
}
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
lifecycleScope.launch {
context?.let {
updateAccountUIState(it, it.components.backgroundServices.accountManager.accountProfile())

View File

@ -16,7 +16,6 @@ import androidx.navigation.fragment.NavHostFragment.findNavController
import kotlinx.android.synthetic.main.fragment_turn_on_sync.view.*
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
@ -77,13 +76,9 @@ class TurnOnSyncFragment : Fragment(), AccountObserver {
}
}
override fun onAuthenticated(account: OAuthAccount) {
override fun onAuthenticated(account: OAuthAccount, newAccount: Boolean) {
FenixSnackbar.make(view!!, FenixSnackbar.LENGTH_SHORT)
.setText(requireContext().getString(R.string.sync_syncing_in_progress))
.show()
}
override fun onAuthenticationProblems() {}
override fun onLoggedOut() {}
override fun onProfileUpdated(profile: Profile) {}
}