Bug 1160346 - Allow home panel add-ons to specify order and make themselves default. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 06 May 2015 17:44:10 -0700
changeset 243957 43512d4631b70cbe514131b4ee98644f86770b87
parent 243956 d5a378327e88b886d397a978e5cba2937578c9eb
child 243958 2295894af36b22dfa2ec7420d0876fa14a84b89f
push id28761
push usercbook@mozilla.com
push dateFri, 15 May 2015 14:50:10 +0000
treeherdermozilla-central@c0e709a5baca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1160346
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1160346 - Allow home panel add-ons to specify order and make themselves default. r=mfinkle
mobile/android/base/home/HomeConfig.java
mobile/android/modules/Home.jsm
--- a/mobile/android/base/home/HomeConfig.java
+++ b/mobile/android/base/home/HomeConfig.java
@@ -102,25 +102,27 @@ public final class HomeConfig {
     public static class PanelConfig implements Parcelable {
         private final PanelType mType;
         private final String mTitle;
         private final String mId;
         private final LayoutType mLayoutType;
         private final List<ViewConfig> mViews;
         private final AuthConfig mAuthConfig;
         private final EnumSet<Flags> mFlags;
+        private final int mPosition;
 
         static final String JSON_KEY_TYPE = "type";
         static final String JSON_KEY_TITLE = "title";
         static final String JSON_KEY_ID = "id";
         static final String JSON_KEY_LAYOUT = "layout";
         static final String JSON_KEY_VIEWS = "views";
         static final String JSON_KEY_AUTH_CONFIG = "authConfig";
         static final String JSON_KEY_DEFAULT = "default";
         static final String JSON_KEY_DISABLED = "disabled";
+        static final String JSON_KEY_POSITION = "position";
 
         public enum Flags {
             DEFAULT_PANEL,
             DISABLED_PANEL
         }
 
         public PanelConfig(JSONObject json) throws JSONException, IllegalArgumentException {
             final String panelType = json.optString(JSON_KEY_TYPE, null);
@@ -166,32 +168,35 @@ public final class HomeConfig {
             if (json.optBoolean(JSON_KEY_DEFAULT, false)) {
                 mFlags.add(Flags.DEFAULT_PANEL);
             }
 
             if (json.optBoolean(JSON_KEY_DISABLED, false)) {
                 mFlags.add(Flags.DISABLED_PANEL);
             }
 
+            mPosition = json.optInt(JSON_KEY_POSITION, -1);
+
             validate();
         }
 
         @SuppressWarnings("unchecked")
         public PanelConfig(Parcel in) {
             mType = (PanelType) in.readParcelable(getClass().getClassLoader());
             mTitle = in.readString();
             mId = in.readString();
             mLayoutType = (LayoutType) in.readParcelable(getClass().getClassLoader());
 
             mViews = new ArrayList<ViewConfig>();
             in.readTypedList(mViews, ViewConfig.CREATOR);
 
             mAuthConfig = (AuthConfig) in.readParcelable(getClass().getClassLoader());
 
             mFlags = (EnumSet<Flags>) in.readSerializable();
+            mPosition = in.readInt();
 
             validate();
         }
 
         public PanelConfig(PanelConfig panelConfig) {
             mType = panelConfig.mType;
             mTitle = panelConfig.mTitle;
             mId = panelConfig.mId;
@@ -202,37 +207,39 @@ public final class HomeConfig {
             if (viewConfigs != null) {
                 for (ViewConfig viewConfig : viewConfigs) {
                     mViews.add(new ViewConfig(viewConfig));
                 }
             }
 
             mAuthConfig = panelConfig.mAuthConfig;
             mFlags = panelConfig.mFlags.clone();
+            mPosition = panelConfig.mPosition;
 
             validate();
         }
 
         public PanelConfig(PanelType type, String title, String id) {
             this(type, title, id, EnumSet.noneOf(Flags.class));
         }
 
         public PanelConfig(PanelType type, String title, String id, EnumSet<Flags> flags) {
-            this(type, title, id, null, null, null, flags);
+            this(type, title, id, null, null, null, flags, -1);
         }
 
         public PanelConfig(PanelType type, String title, String id, LayoutType layoutType,
-                List<ViewConfig> views, AuthConfig authConfig, EnumSet<Flags> flags) {
+                List<ViewConfig> views, AuthConfig authConfig, EnumSet<Flags> flags, int position) {
             mType = type;
             mTitle = title;
             mId = id;
             mLayoutType = layoutType;
             mViews = views;
             mAuthConfig = authConfig;
             mFlags = flags;
+            mPosition = position;
 
             validate();
         }
 
         private void validate() {
             if (mType == null) {
                 throw new IllegalArgumentException("Can't create PanelConfig with null type");
             }
@@ -309,16 +316,20 @@ public final class HomeConfig {
                 mFlags.remove(Flags.DISABLED_PANEL);
             }
         }
 
         public AuthConfig getAuthConfig() {
             return mAuthConfig;
         }
 
+        public int getPosition() {
+            return mPosition;
+        }
+
         public JSONObject toJSON() throws JSONException {
             final JSONObject json = new JSONObject();
 
             json.put(JSON_KEY_TYPE, mType.toString());
             json.put(JSON_KEY_TITLE, mTitle);
             json.put(JSON_KEY_ID, mId);
 
             if (mLayoutType != null) {
@@ -345,16 +356,18 @@ public final class HomeConfig {
             if (mFlags.contains(Flags.DEFAULT_PANEL)) {
                 json.put(JSON_KEY_DEFAULT, true);
             }
 
             if (mFlags.contains(Flags.DISABLED_PANEL)) {
                 json.put(JSON_KEY_DISABLED, true);
             }
 
+            json.put(JSON_KEY_POSITION, mPosition);
+
             return json;
         }
 
         @Override
         public boolean equals(Object o) {
             if (o == null) {
                 return false;
             }
@@ -385,16 +398,17 @@ public final class HomeConfig {
         public void writeToParcel(Parcel dest, int flags) {
             dest.writeParcelable(mType, 0);
             dest.writeString(mTitle);
             dest.writeString(mId);
             dest.writeParcelable(mLayoutType, 0);
             dest.writeTypedList(mViews);
             dest.writeParcelable(mAuthConfig, 0);
             dest.writeSerializable(mFlags);
+            dest.writeInt(mPosition);
         }
 
         public static final Creator<PanelConfig> CREATOR = new Creator<PanelConfig>() {
             @Override
             public PanelConfig createFromParcel(final Parcel in) {
                 return new PanelConfig(in);
             }
 
@@ -1267,17 +1281,23 @@ public final class HomeConfig {
                 throw new IllegalStateException("Can't install a disabled panel: " + panelConfig.getId());
             }
 
             boolean installed = false;
 
             final String id = panelConfig.getId();
             if (!mConfigMap.containsKey(id)) {
                 mConfigMap.put(id, panelConfig);
-                mConfigOrder.add(id);
+
+                final int position = panelConfig.getPosition();
+                if (position < 0 || position >= mConfigOrder.size()) {
+                    mConfigOrder.add(id);
+                } else {
+                    mConfigOrder.add(position, id);
+                }
 
                 mEnabledCount++;
                 if (mEnabledCount == 1 || panelConfig.isDefault()) {
                     setDefault(panelConfig.getId());
                 }
 
                 installed = true;
 
--- a/mobile/android/modules/Home.jsm
+++ b/mobile/android/modules/Home.jsm
@@ -310,16 +310,17 @@ let HomePanels = (function () {
     INTENT: "intent"
   });
 
   function Panel(id, options) {
     this.id = id;
     this.title = options.title;
     this.layout = options.layout;
     this.views = options.views;
+    this.default = !!options.default;
 
     if (!this.id || !this.title) {
       throw "Home.panels: Can't create a home panel without an id and title!";
     }
 
     if (!this.layout) {
       // Use FRAME layout by default
       this.layout = Layout.FRAME;
@@ -373,16 +374,20 @@ let HomePanels = (function () {
         buttonText: options.auth.buttonText
       };
 
       // Include optional image URL if it is specified.
       if (options.auth.imageUrl) {
         this.authConfig.imageUrl = options.auth.imageUrl;
       }
     }
+
+    if (options.position && typeof options.position === "number") {
+      this.position = options.position;
+    }
   }
 
   let _generatePanel = function(id) {
     let options = _registeredPanels[id]();
     return new Panel(id, options);
   };
 
   // Helper function used to see if a value is in an object.