Bug 970707 - Add refreshEnabled to ViewConfig. r=margaret
authorJosh Dover <gerfuls@gmail.com>
Tue, 15 Apr 2014 15:48:00 +0200
changeset 197274 15ca8fe42018bd2307f663539096ea8431c2ebf0
parent 197273 b56da878caedd7c9e351b0bde1a2aa7e7db77f68
child 197275 1e2c46a659c92578af1936ab5bc7024c4df79f53
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs970707
milestone31.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 970707 - Add refreshEnabled to ViewConfig. r=margaret
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
@@ -608,24 +608,30 @@ public final class HomeConfig {
         private final int mIndex;
         private final ViewType mType;
         private final String mDatasetId;
         private final ItemType mItemType;
         private final ItemHandler mItemHandler;
         private final String mBackImageUrl;
         private final String mFilter;
         private final EmptyViewConfig mEmptyViewConfig;
+        private final EnumSet<Flags> mFlags;
 
         private static final String JSON_KEY_TYPE = "type";
         private static final String JSON_KEY_DATASET = "dataset";
         private static final String JSON_KEY_ITEM_TYPE = "itemType";
         private static final String JSON_KEY_ITEM_HANDLER = "itemHandler";
         private static final String JSON_KEY_BACK_IMAGE_URL = "backImageUrl";
         private static final String JSON_KEY_FILTER = "filter";
         private static final String JSON_KEY_EMPTY = "empty";
+        private static final String JSON_KEY_REFRESH_ENABLED = "refreshEnabled";
+
+        public enum Flags {
+            REFRESH_ENABLED
+        }
 
         public ViewConfig(int index, JSONObject json) throws JSONException, IllegalArgumentException {
             mIndex = index;
             mType = ViewType.fromId(json.getString(JSON_KEY_TYPE));
             mDatasetId = json.getString(JSON_KEY_DATASET);
             mItemType = ItemType.fromId(json.getString(JSON_KEY_ITEM_TYPE));
             mItemHandler = ItemHandler.fromId(json.getString(JSON_KEY_ITEM_HANDLER));
             mBackImageUrl = json.optString(JSON_KEY_BACK_IMAGE_URL, null);
@@ -633,57 +639,65 @@ public final class HomeConfig {
 
             final JSONObject jsonEmptyViewConfig = json.optJSONObject(JSON_KEY_EMPTY);
             if (jsonEmptyViewConfig != null) {
                 mEmptyViewConfig = new EmptyViewConfig(jsonEmptyViewConfig);
             } else {
                 mEmptyViewConfig = null;
             }
 
+            mFlags = EnumSet.noneOf(Flags.class);
+            if (json.optBoolean(JSON_KEY_REFRESH_ENABLED, false)) {
+                mFlags.add(Flags.REFRESH_ENABLED);
+            }
+
             validate();
         }
 
         @SuppressWarnings("unchecked")
         public ViewConfig(Parcel in) {
             mIndex = in.readInt();
             mType = (ViewType) in.readParcelable(getClass().getClassLoader());
             mDatasetId = in.readString();
             mItemType = (ItemType) in.readParcelable(getClass().getClassLoader());
             mItemHandler = (ItemHandler) in.readParcelable(getClass().getClassLoader());
             mBackImageUrl = in.readString();
             mFilter = in.readString();
             mEmptyViewConfig = (EmptyViewConfig) in.readParcelable(getClass().getClassLoader());
+            mFlags = (EnumSet<Flags>) in.readSerializable();
 
             validate();
         }
 
         public ViewConfig(ViewConfig viewConfig) {
             mIndex = viewConfig.mIndex;
             mType = viewConfig.mType;
             mDatasetId = viewConfig.mDatasetId;
             mItemType = viewConfig.mItemType;
             mItemHandler = viewConfig.mItemHandler;
             mBackImageUrl = viewConfig.mBackImageUrl;
             mFilter = viewConfig.mFilter;
             mEmptyViewConfig = viewConfig.mEmptyViewConfig;
+            mFlags = viewConfig.mFlags.clone();
 
             validate();
         }
 
         public ViewConfig(int index, ViewType type, String datasetId, ItemType itemType,
                           ItemHandler itemHandler, String backImageUrl, String filter,
-                          EmptyViewConfig emptyViewConfig) {
+                          EmptyViewConfig emptyViewConfig, EnumSet<Flags> flags) {
             mIndex = index;
             mType = type;
             mDatasetId = datasetId;
             mItemType = itemType;
             mItemHandler = itemHandler;
             mBackImageUrl = backImageUrl;
             mFilter = filter;
             mEmptyViewConfig = emptyViewConfig;
+            mFlags = flags;
 
             validate();
         }
 
         private void validate() {
             if (mType == null) {
                 throw new IllegalArgumentException("Can't create ViewConfig with null type");
             }
@@ -694,16 +708,20 @@ public final class HomeConfig {
 
             if (mItemType == null) {
                 throw new IllegalArgumentException("Can't create ViewConfig with null item type");
             }
 
             if (mItemHandler == null) {
                 throw new IllegalArgumentException("Can't create ViewConfig with null item handler");
             }
+
+            if (mFlags == null) {
+               throw new IllegalArgumentException("Can't create ViewConfig with null flags");
+            }
         }
 
         public int getIndex() {
             return mIndex;
         }
 
         public ViewType getType() {
             return mType;
@@ -728,16 +746,20 @@ public final class HomeConfig {
         public String getFilter() {
             return mFilter;
         }
 
         public EmptyViewConfig getEmptyViewConfig() {
             return mEmptyViewConfig;
         }
 
+        public boolean isRefreshEnabled() {
+            return mFlags.contains(Flags.REFRESH_ENABLED);
+        }
+
         public JSONObject toJSON() throws JSONException {
             final JSONObject json = new JSONObject();
 
             json.put(JSON_KEY_TYPE, mType.toString());
             json.put(JSON_KEY_DATASET, mDatasetId);
             json.put(JSON_KEY_ITEM_TYPE, mItemType.toString());
             json.put(JSON_KEY_ITEM_HANDLER, mItemHandler.toString());
 
@@ -748,16 +770,20 @@ public final class HomeConfig {
             if (!TextUtils.isEmpty(mFilter)) {
                 json.put(JSON_KEY_FILTER, mFilter);
             }
 
             if (mEmptyViewConfig != null) {
                 json.put(JSON_KEY_EMPTY, mEmptyViewConfig.toJSON());
             }
 
+            if (mFlags.contains(Flags.REFRESH_ENABLED)) {
+                json.put(JSON_KEY_REFRESH_ENABLED, true);
+            }
+
             return json;
         }
 
         @Override
         public int describeContents() {
             return 0;
         }
 
@@ -766,16 +792,17 @@ public final class HomeConfig {
             dest.writeInt(mIndex);
             dest.writeParcelable(mType, 0);
             dest.writeString(mDatasetId);
             dest.writeParcelable(mItemType, 0);
             dest.writeParcelable(mItemHandler, 0);
             dest.writeString(mBackImageUrl);
             dest.writeString(mFilter);
             dest.writeParcelable(mEmptyViewConfig, 0);
+            dest.writeSerializable(mFlags);
         }
 
         public static final Creator<ViewConfig> CREATOR = new Creator<ViewConfig>() {
             @Override
             public ViewConfig createFromParcel(final Parcel in) {
                 return new ViewConfig(in);
             }
 
--- a/mobile/android/modules/Home.jsm
+++ b/mobile/android/modules/Home.jsm
@@ -311,16 +311,20 @@ let HomePanels = (function () {
         view.itemHandler = ItemHandler.BROWSER;
       } else if (!_valueExists(ItemHandler, view.itemHandler)) {
         throw "Home.panels: Invalid item handler: panel.id = " + this.id + ", view.itemHandler = " + view.itemHandler;
       }
 
       if (!view.dataset) {
         throw "Home.panels: No dataset provided for view: panel.id = " + this.id + ", view.type = " + view.type;
       }
+
+      if (view.onrefresh) {
+        view.refreshEnabled = true;
+      }
     }
 
     if (options.auth) {
       if (!options.auth.messageText) {
         throw "Home.panels: Invalid auth messageText: panel.id = " + this.id;
       }
       if (!options.auth.buttonText) {
         throw "Home.panels: Invalid auth buttonText: panel.id = " + this.id;