Bug 1009586 - Get rid of "Add panel" item in home settings. r=liuche, a=sledru
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 16 May 2014 13:09:15 +0100
changeset 200321 8ff4386b0a35bba190ab73c1fa4563397425a429
parent 200320 7f6a7121a73c09824cb6311830fe96d31e756d6e
child 200322 4490ed792d7697efad71a2d6a3b4f77253e13554
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, sledru
bugs1009586
milestone31.0a2
Bug 1009586 - Get rid of "Add panel" item in home settings. r=liuche, a=sledru
mobile/android/base/preferences/PanelsPreference.java
mobile/android/base/preferences/PanelsPreferenceCategory.java
mobile/android/base/resources/xml/preferences_home.xml
--- a/mobile/android/base/preferences/PanelsPreference.java
+++ b/mobile/android/base/preferences/PanelsPreference.java
@@ -25,43 +25,40 @@ public class PanelsPreference extends Cu
     protected String LOGTAG = "PanelsPreference";
 
     // Position state of this Preference in enclosing category.
     private static final int STATE_IS_FIRST = 0;
     private static final int STATE_IS_LAST = 1;
 
     /**
      * Index of the context menu button for controlling display options.
-     * For (removable) Dynamic panels, this button removes the panel.
-     * For built-in panels, this button toggles showing or hiding the panel.
+     * This button toggles showing or hiding the panel.
      */
     private static final int INDEX_DISPLAY_BUTTON = 1;
     private static final int INDEX_REORDER_BUTTON = 2;
 
     // Indices of buttons in context menu for reordering.
     private static final int INDEX_MOVE_UP_BUTTON = 0;
     private static final int INDEX_MOVE_DOWN_BUTTON = 1;
 
     private String LABEL_HIDE;
     private String LABEL_SHOW;
 
     private View preferenceView;
     protected boolean mIsHidden = false;
-    private boolean mIsRemovable;
 
     private boolean mAnimate;
     private static final int ANIMATION_DURATION_MS = 400;
 
     // State for reordering.
     private int mPositionState = -1;
     private final int mIndex;
 
-    public PanelsPreference(Context context, CustomListCategory parentCategory, boolean isRemovable, int index, boolean animate) {
+    public PanelsPreference(Context context, CustomListCategory parentCategory, int index, boolean animate) {
         super(context, parentCategory);
-        mIsRemovable = isRemovable;
         mIndex = index;
         mAnimate = animate;
     }
 
     @Override
     protected int getPreferenceLayoutResource() {
         return R.layout.preference_panels;
     }
@@ -93,21 +90,16 @@ public class PanelsPreference extends Cu
         }
     }
 
     @Override
     protected String[] createDialogItems() {
         final Resources res = getContext().getResources();
         final String labelReorder = res.getString(R.string.pref_panels_reorder);
 
-        if (mIsRemovable) {
-            return new String[] { LABEL_SET_AS_DEFAULT, LABEL_REMOVE, labelReorder };
-        }
-
-        // Built-in panels can't be removed, so use show/hide options.
         LABEL_HIDE = res.getString(R.string.pref_panels_hide);
         LABEL_SHOW = res.getString(R.string.pref_panels_show);
 
         return new String[] { LABEL_SET_AS_DEFAULT, LABEL_HIDE, labelReorder };
     }
 
     @Override
     public void setIsDefault(boolean isDefault) {
@@ -126,24 +118,18 @@ public class PanelsPreference extends Cu
     @Override
     protected void onDialogIndexClicked(int index) {
         switch(index) {
             case INDEX_SET_DEFAULT_BUTTON:
                 mParentCategory.setDefault(this);
                 break;
 
             case INDEX_DISPLAY_BUTTON:
-                // Handle display options for the panel.
-                if (mIsRemovable) {
-                    // For removable panels, the button displays text for removing the panel.
-                    mParentCategory.uninstall(this);
-                } else {
-                    // Otherwise, the button toggles between text for showing or hiding the panel.
-                    ((PanelsPreferenceCategory) mParentCategory).setHidden(this, !mIsHidden);
-                }
+                // The button toggles between text for showing or hiding the panel.
+                ((PanelsPreferenceCategory) mParentCategory).setHidden(this, !mIsHidden);
                 break;
 
             case INDEX_REORDER_BUTTON:
                 // Display dialog for changing preference order.
                 final Dialog orderDialog = makeReorderDialog();
                 orderDialog.show();
                 break;
 
@@ -152,20 +138,18 @@ public class PanelsPreference extends Cu
         }
     }
 
     @Override
     protected void configureShownDialog() {
         super.configureShownDialog();
 
         // Handle Show/Hide buttons.
-        if (!mIsRemovable) {
-            final TextView hideButton = (TextView) mDialog.getListView().getChildAt(INDEX_DISPLAY_BUTTON);
-            hideButton.setText(mIsHidden ? LABEL_SHOW : LABEL_HIDE);
-        }
+        final TextView hideButton = (TextView) mDialog.getListView().getChildAt(INDEX_DISPLAY_BUTTON);
+        hideButton.setText(mIsHidden ? LABEL_SHOW : LABEL_HIDE);
     }
 
 
     private Dialog makeReorderDialog() {
         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
 
         final Resources res = getContext().getResources();
         final String labelUp = res.getString(R.string.pref_panels_move_up);
--- a/mobile/android/base/preferences/PanelsPreferenceCategory.java
+++ b/mobile/android/base/preferences/PanelsPreferenceCategory.java
@@ -17,19 +17,16 @@ import android.text.TextUtils;
 import android.util.AttributeSet;
 
 public class PanelsPreferenceCategory extends CustomListCategory {
     public static final String LOGTAG = "PanelsPrefCategory";
 
     protected HomeConfig mHomeConfig;
     protected HomeConfig.Editor mConfigEditor;
 
-    // Account for the fake "Add Panel" preference in preference counting.
-    private static final int PANEL_PREFS_OFFSET = 1;
-
     protected UiAsyncTask<Void, Void, HomeConfig.State> mLoadTask;
 
     public PanelsPreferenceCategory(Context context) {
         super(context);
         initConfig(context);
     }
 
     public PanelsPreferenceCategory(Context context, AttributeSet attrs) {
@@ -82,41 +79,34 @@ public class PanelsPreferenceCategory ex
     /**
      * Refresh the Home Panels list and animate a panel, if specified.
      * If null, load from HomeConfig.
      *
      * @param State HomeConfig.State to rebuild Home Panels list from.
      * @param String panelId of panel to be animated.
      */
     public void refresh(State state, String animatePanelId) {
-        // Clear all the existing home panels, but leave the
-        // first item (Add panels).
-        int prefCount = getPreferenceCount();
-        while (prefCount > 1) {
-            removePreference(getPreference(1));
-            prefCount--;
-        }
+        // Clear all the existing home panels.
+        removeAll();
 
         if (state == null) {
             loadHomeConfig(animatePanelId);
         } else {
             displayHomeConfig(state, animatePanelId);
         }
     }
 
     private void displayHomeConfig(HomeConfig.State configState, String animatePanelId) {
         int index = 0;
         for (PanelConfig panelConfig : configState) {
-            final boolean isRemovable = panelConfig.isDynamic();
-
             // Create and add the pref.
             final String panelId = panelConfig.getId();
             final boolean animate = TextUtils.equals(animatePanelId, panelId);
 
-            final PanelsPreference pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, index, animate);
+            final PanelsPreference pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, index, animate);
             pref.setTitle(panelConfig.getTitle());
             pref.setKey(panelConfig.getId());
             // XXX: Pull icon from PanelInfo.
             addPreference(pref);
 
             if (panelConfig.isDisabled()) {
                 pref.setHidden(true);
             }
@@ -127,34 +117,33 @@ public class PanelsPreferenceCategory ex
         setPositionState();
         setDefaultFromConfig();
     }
 
     private void setPositionState() {
         final int prefCount = getPreferenceCount();
 
         // Pass in position state to first and last preference.
-        final PanelsPreference firstPref = (PanelsPreference) getPreference(PANEL_PREFS_OFFSET);
+        final PanelsPreference firstPref = (PanelsPreference) getPreference(0);
         firstPref.setIsFirst();
 
         final PanelsPreference lastPref = (PanelsPreference) getPreference(prefCount - 1);
         lastPref.setIsLast();
     }
 
     private void setDefaultFromConfig() {
         final String defaultPanelId = mConfigEditor.getDefaultPanelId();
         if (defaultPanelId == null) {
             mDefaultReference = null;
             return;
         }
 
         final int prefCount = getPreferenceCount();
 
-        // First preference (index 0) is Preference to add panels.
-        for (int i = 1; i < prefCount; i++) {
+        for (int i = 0; i < prefCount; i++) {
             final PanelsPreference pref = (PanelsPreference) getPreference(i);
 
             if (defaultPanelId.equals(pref.getKey())) {
                 super.setDefault(pref);
                 break;
             }
         }
     }
--- a/mobile/android/base/resources/xml/preferences_home.xml
+++ b/mobile/android/base/resources/xml/preferences_home.xml
@@ -4,23 +4,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                   xmlns:gecko="http://schemas.android.com/apk/res-auto"
                   android:title="@string/pref_category_home"
                   android:enabled="false">
 
     <org.mozilla.gecko.preferences.PanelsPreferenceCategory
-        android:title="@string/pref_category_home_panels">
-
-        <Preference android:key="android.not_a_preference.home.add_panel"
-                    android:title="@string/pref_home_add_panel"
-                    android:icon="@drawable/icon_new_home_panel" />
-
-    </org.mozilla.gecko.preferences.PanelsPreferenceCategory>
+        android:title="@string/pref_category_home_panels"/>
 
     <PreferenceCategory android:title="@string/pref_category_home_content_settings">
 
         <ListPreference android:key="home.sync.updateMode"
                         android:title="@string/pref_home_updates"
                         android:entries="@array/pref_home_updates_entries"
                         android:entryValues="@array/pref_home_updates_values"
                         android:persistent="false" />