Bug 965622 - (Part 1) Add EmptyViewConfig to HomeConfig. r=liuche
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 15 Apr 2014 10:03:03 -0700
changeset 197073 aa6dbd1167365ad5357dbdbb3bc4fd95c1536a4b
parent 197072 cd04719806d8d093f75855e15c0ad495ffcd74cb
child 197074 b17e8a8c381f37134e3015ddda04801c534e3d3e
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)
reviewersliuche
bugs965622
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 965622 - (Part 1) Add EmptyViewConfig to HomeConfig. r=liuche
mobile/android/base/home/HomeConfig.java
--- a/mobile/android/base/home/HomeConfig.java
+++ b/mobile/android/base/home/HomeConfig.java
@@ -607,70 +607,83 @@ public final class HomeConfig {
     public static class ViewConfig implements Parcelable {
         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 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";
 
         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);
             mFilter = json.optString(JSON_KEY_FILTER, null);
 
+            final JSONObject jsonEmptyViewConfig = json.optJSONObject(JSON_KEY_EMPTY);
+            if (jsonEmptyViewConfig != null) {
+                mEmptyViewConfig = new EmptyViewConfig(jsonEmptyViewConfig);
+            } else {
+                mEmptyViewConfig = null;
+            }
+
             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());
 
             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;
 
             validate();
         }
 
         public ViewConfig(int index, ViewType type, String datasetId, ItemType itemType,
-                          ItemHandler itemHandler, String backImageUrl, String filter) {
+                          ItemHandler itemHandler, String backImageUrl, String filter,
+                          EmptyViewConfig emptyViewConfig) {
             mIndex = index;
             mType = type;
             mDatasetId = datasetId;
             mItemType = itemType;
             mItemHandler = itemHandler;
             mBackImageUrl = backImageUrl;
             mFilter = filter;
+            mEmptyViewConfig = emptyViewConfig;
 
             validate();
         }
 
         private void validate() {
             if (mType == null) {
                 throw new IllegalArgumentException("Can't create ViewConfig with null type");
             }
@@ -711,32 +724,40 @@ public final class HomeConfig {
         public String getBackImageUrl() {
             return mBackImageUrl;
         }
 
         public String getFilter() {
             return mFilter;
         }
 
+        public EmptyViewConfig getEmptyViewConfig() {
+            return mEmptyViewConfig;
+        }
+
         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());
 
             if (!TextUtils.isEmpty(mBackImageUrl)) {
                 json.put(JSON_KEY_BACK_IMAGE_URL, mBackImageUrl);
             }
 
             if (!TextUtils.isEmpty(mFilter)) {
                 json.put(JSON_KEY_FILTER, mFilter);
             }
 
+            if (mEmptyViewConfig != null) {
+                json.put(JSON_KEY_EMPTY, mEmptyViewConfig.toJSON());
+            }
+
             return json;
         }
 
         @Override
         public int describeContents() {
             return 0;
         }
 
@@ -744,31 +765,101 @@ public final class HomeConfig {
         public void writeToParcel(Parcel dest, int flags) {
             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);
         }
 
         public static final Creator<ViewConfig> CREATOR = new Creator<ViewConfig>() {
             @Override
             public ViewConfig createFromParcel(final Parcel in) {
                 return new ViewConfig(in);
             }
 
             @Override
             public ViewConfig[] newArray(final int size) {
                 return new ViewConfig[size];
             }
         };
     }
 
+    public static class EmptyViewConfig implements Parcelable {
+        private final String mText;
+        private final String mImageUrl;
+
+        private static final String JSON_KEY_TEXT = "text";
+        private static final String JSON_KEY_IMAGE_URL = "imageUrl";
+
+        public EmptyViewConfig(JSONObject json) throws JSONException, IllegalArgumentException {
+            mText = json.optString(JSON_KEY_TEXT, null);
+            mImageUrl = json.optString(JSON_KEY_IMAGE_URL, null);
+        }
+
+        @SuppressWarnings("unchecked")
+        public EmptyViewConfig(Parcel in) {
+            mText = in.readString();
+            mImageUrl = in.readString();
+        }
+
+        public EmptyViewConfig(EmptyViewConfig emptyViewConfig) {
+            mText = emptyViewConfig.mText;
+            mImageUrl = emptyViewConfig.mImageUrl;
+        }
+
+        public EmptyViewConfig(String text, String imageUrl) {
+            mText = text;
+            mImageUrl = imageUrl;
+        }
+
+        public String getText() {
+            return mText;
+        }
+
+        public String getImageUrl() {
+            return mImageUrl;
+        }
+
+        public JSONObject toJSON() throws JSONException {
+            final JSONObject json = new JSONObject();
+
+            json.put(JSON_KEY_TEXT, mText);
+            json.put(JSON_KEY_IMAGE_URL, mImageUrl);
+
+            return json;
+        }
+
+        @Override
+        public int describeContents() {
+            return 0;
+        }
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            dest.writeString(mText);
+            dest.writeString(mImageUrl);
+        }
+
+        public static final Creator<EmptyViewConfig> CREATOR = new Creator<EmptyViewConfig>() {
+            @Override
+            public EmptyViewConfig createFromParcel(final Parcel in) {
+                return new EmptyViewConfig(in);
+            }
+
+            @Override
+            public EmptyViewConfig[] newArray(final int size) {
+                return new EmptyViewConfig[size];
+            }
+        };
+    }
+
     public static class AuthConfig implements Parcelable {
         private final String mMessageText;
         private final String mButtonText;
         private final String mImageUrl;
 
         private static final String JSON_KEY_MESSAGE_TEXT = "messageText";
         private static final String JSON_KEY_BUTTON_TEXT = "buttonText";
         private static final String JSON_KEY_IMAGE_URL = "imageUrl";