Bug 1123116 - Include Reading List checkbox in status activity. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Wed, 11 Feb 2015 12:12:36 -0800
changeset 246348 ba0c52229c09d6c76a578d1de0ea4f0ad5256dd8
parent 246347 9459820ebc5074f24da28685ce06b3b2a1568f2f
child 246349 9e88eb0cb0d28bd6cbbf7e937bbbdbaaeae56c25
push id7677
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 18:11:24 +0000
treeherdermozilla-aurora@f531d838c055 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1123116
milestone38.0a1
Bug 1123116 - Include Reading List checkbox in status activity. r=rnewman I have tested and see no issues with hiding the checkbox when the service is build-time disabled. ======== https://github.com/mozilla-services/android-sync/commit/d2890e5747dd3a71cb985cb6fe6149396c5be5f7 Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Feb 9 15:47:59 2015 -0800 Bug 1123116 - Include Reading List checkbox in status activity. We're careful to only show the checkbox when the service is compiled in.
mobile/android/base/fxa/activities/FxAccountStatusFragment.java
mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
--- a/mobile/android/base/fxa/activities/FxAccountStatusFragment.java
+++ b/mobile/android/base/fxa/activities/FxAccountStatusFragment.java
@@ -8,16 +8,17 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.fxa.FxAccountUtils;
 import org.mozilla.gecko.background.preferences.PreferenceFragment;
+import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.fxa.FirefoxAccounts;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 import org.mozilla.gecko.fxa.login.Married;
 import org.mozilla.gecko.fxa.login.State;
 import org.mozilla.gecko.fxa.sync.FxAccountSyncStatusHelper;
 import org.mozilla.gecko.fxa.tasks.FxAccountCodeResender;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
@@ -81,16 +82,17 @@ public class FxAccountStatusFragment
   protected Preference needsFinishMigratingPreference;
 
   protected PreferenceCategory syncCategory;
 
   protected CheckBoxPreference bookmarksPreference;
   protected CheckBoxPreference historyPreference;
   protected CheckBoxPreference tabsPreference;
   protected CheckBoxPreference passwordsPreference;
+  protected CheckBoxPreference readingListPreference;
 
   protected EditTextPreference deviceNamePreference;
   protected Preference syncServerPreference;
   protected Preference morePreference;
   protected Preference syncNowPreference;
 
   protected volatile AndroidFxAccount fxAccount;
   // The contract is: when fxAccount is non-null, then clientsDataDelegate is
@@ -145,16 +147,19 @@ public class FxAccountStatusFragment
     needsFinishMigratingPreference = ensureFindPreference("needs_finish_migrating");
 
     syncCategory = (PreferenceCategory) ensureFindPreference("sync_category");
 
     bookmarksPreference = (CheckBoxPreference) ensureFindPreference("bookmarks");
     historyPreference = (CheckBoxPreference) ensureFindPreference("history");
     tabsPreference = (CheckBoxPreference) ensureFindPreference("tabs");
     passwordsPreference = (CheckBoxPreference) ensureFindPreference("passwords");
+    // The Reading List toggle appears with the other Firefox Sync toggles but
+    // controls a separate Android authority.
+    readingListPreference = (CheckBoxPreference) ensureFindPreference("reading_list");
 
     if (!FxAccountUtils.LOG_PERSONAL_INFORMATION) {
       removeDebugButtons();
     } else {
       connectDebugButtons();
       ALWAYS_SHOW_AUTH_SERVER = true;
       ALWAYS_SHOW_SYNC_SERVER = true;
     }
@@ -162,16 +167,17 @@ public class FxAccountStatusFragment
     needsPasswordPreference.setOnPreferenceClickListener(this);
     needsVerificationPreference.setOnPreferenceClickListener(this);
     needsFinishMigratingPreference.setOnPreferenceClickListener(this);
 
     bookmarksPreference.setOnPreferenceClickListener(this);
     historyPreference.setOnPreferenceClickListener(this);
     tabsPreference.setOnPreferenceClickListener(this);
     passwordsPreference.setOnPreferenceClickListener(this);
+    readingListPreference.setOnPreferenceClickListener(this);
 
     deviceNamePreference = (EditTextPreference) ensureFindPreference("device_name");
     deviceNamePreference.setOnPreferenceChangeListener(this);
 
     syncServerPreference = ensureFindPreference("sync_server");
     morePreference = ensureFindPreference("more");
     morePreference.setOnPreferenceClickListener(this);
 
@@ -238,16 +244,24 @@ public class FxAccountStatusFragment
     if (preference == bookmarksPreference ||
         preference == historyPreference ||
         preference == passwordsPreference ||
         preference == tabsPreference) {
       saveEngineSelections();
       return true;
     }
 
+    if (preference == readingListPreference) {
+      final boolean syncAutomatically = readingListPreference.isChecked();
+      ContentResolver.setIsSyncable(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY, 1);
+      ContentResolver.setSyncAutomatically(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY, syncAutomatically);
+      FxAccountUtils.pii(LOG_TAG, (syncAutomatically ? "En" : "Dis") + "abling Reading List sync automatically.");
+      return true;
+    }
+
     if (preference == morePreference) {
       getActivity().openOptionsMenu();
       return true;
     }
 
     if (preference == syncNowPreference) {
       if (fxAccount != null) {
         FirefoxAccounts.requestSync(fxAccount.getAndroidAccount(), FirefoxAccounts.FORCE, null, null);
@@ -272,16 +286,21 @@ public class FxAccountStatusFragment
   protected void setCheckboxesEnabled(boolean enabled) {
     bookmarksPreference.setEnabled(enabled);
     historyPreference.setEnabled(enabled);
     tabsPreference.setEnabled(enabled);
     passwordsPreference.setEnabled(enabled);
     // Since we can't sync, we can't update our remote client record.
     deviceNamePreference.setEnabled(enabled);
     syncNowPreference.setEnabled(enabled);
+
+    // The checkboxes are a set of global settings: they reflect the account
+    // state and not the underlying Sync state. In the future, each checkbox
+    // will reflect its own piece of the account state.
+    readingListPreference.setEnabled(enabled);
   }
 
   /**
    * Show at most one error preference, hiding all others.
    *
    * @param errorPreferenceToShow
    *          single error preference to show; if null, hide all error preferences
    */
@@ -493,16 +512,17 @@ public class FxAccountStatusFragment
       final boolean masterSyncAutomatically = ContentResolver.getMasterSyncAutomatically();
       if (!masterSyncAutomatically) {
         showNeedsMasterSyncAutomaticallyEnabled();
         return;
       }
     } finally {
       // No matter our state, we should update the checkboxes.
       updateSelectedEngines();
+      updateReadingList();
     }
 
     final String clientName = clientsDataDelegate.getClientName();
     deviceNamePreference.setSummary(clientName);
     deviceNamePreference.setText(clientName);
 
     updateSyncNowPreference();
   }
@@ -602,16 +622,29 @@ public class FxAccountStatusFragment
       setCheckboxesEnabled(false);
     } catch (Exception e) {
       Logger.warn(LOG_TAG, "Got exception getting engines to select; ignoring.", e);
       return;
     }
   }
 
   /**
+   * Query the current reading list automatic sync state, and update the UI
+   * accordingly.
+   */
+  protected void updateReadingList() {
+    if (AppConstants.MOZ_ANDROID_READING_LIST_SERVICE) {
+      final boolean syncAutomatically = ContentResolver.getSyncAutomatically(fxAccount.getAndroidAccount(), BrowserContract.READING_LIST_AUTHORITY);
+      readingListPreference.setChecked(syncAutomatically);
+    } else {
+      syncCategory.removePreference(readingListPreference);
+    }
+  }
+
+  /**
    * Persist engine selections to local shared preferences, and request a sync
    * to persist selections to remote storage.
    */
   protected void saveEngineSelections() {
     final Map<String, Boolean> engineSelections = new HashMap<String, Boolean>();
     engineSelections.put("bookmarks", bookmarksPreference.isChecked());
     engineSelections.put("history", historyPreference.isChecked());
     engineSelections.put("passwords", passwordsPreference.isChecked());
--- a/mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
+++ b/mobile/android/base/resources/xml/fxaccount_status_prefscreen.xml
@@ -74,16 +74,20 @@
         <CheckBoxPreference
             android:key="tabs"
             android:persistent="false"
             android:title="@string/fxaccount_status_tabs" />
         <CheckBoxPreference
             android:key="passwords"
             android:persistent="false"
             android:title="@string/fxaccount_status_passwords" />
+        <CheckBoxPreference
+            android:key="reading_list"
+            android:persistent="false"
+            android:title="@string/fxaccount_status_reading_list" />
 
         <EditTextPreference
             android:singleLine="true"
             android:key="device_name"
             android:persistent="false"
             android:title="@string/fxaccount_status_device_name" />
 
         <Preference