From 56b4577fc03dcc760e13c19dcb59a4539c3612f1 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 2 Feb 2012 16:08:58 +0000 Subject: [PATCH] Bug 722752 - Show/hide sync banner when sync accounts are added/removed (r=mfinkle) --- mobile/android/base/AboutHomeContent.java | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/AboutHomeContent.java b/mobile/android/base/AboutHomeContent.java index 2a65dc304c5..fd643a0475b 100644 --- a/mobile/android/base/AboutHomeContent.java +++ b/mobile/android/base/AboutHomeContent.java @@ -59,6 +59,7 @@ import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity; import android.accounts.Account; import android.accounts.AccountManager; +import android.accounts.OnAccountsUpdateListener; import android.app.Activity; import android.content.ContentResolver; import android.content.Context; @@ -110,6 +111,8 @@ public class AboutHomeContent extends ScrollView { UriLoadCallback mUriLoadCallback = null; private LayoutInflater mInflater; + private AccountManager mAccountManager; + protected SimpleCursorAdapter mTopSitesAdapter; protected GridView mTopSitesGrid; @@ -125,6 +128,26 @@ public class AboutHomeContent extends ScrollView { mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.abouthome_content, this); + mAccountManager = AccountManager.get(context); + + // The listener will run on the background thread (see 2nd argument) + mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() { + public void onAccountsUpdated(Account[] accounts) { + final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode(); + final boolean syncIsSetup = isSyncSetup(); + + GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + public void run() { + // The listener might run before the UI is initially updated. + // In this case, we should simply wait for the initial setup + // to happen. + if (mTopSitesAdapter != null) + updateLayout(startupMode, syncIsSetup); + } + }); + } + }, GeckoAppShell.getHandler(), true); + setScrollContainer(true); setBackgroundResource(R.drawable.abouthome_bg_repeat); @@ -226,8 +249,7 @@ public class AboutHomeContent extends ScrollView { } private boolean isSyncSetup() { - AccountManager accountManager = AccountManager.get(getContext()); - Account[] accounts = accountManager.getAccountsByType("org.mozilla.firefox_sync"); + Account[] accounts = mAccountManager.getAccountsByType("org.mozilla.firefox_sync"); return accounts.length > 0; }