Bug 972503 - Allow home panel views to specify an initial filter. r=lucasr
authorJosh Dover <gerfuls@gmail.com>
Thu, 27 Mar 2014 16:17:00 +0100
changeset 175807 38c8dbb6ad87588ed67266248171a9aca70971d8
parent 175806 e472ec4a52801b059125344ba30715a58f55e05b
child 175808 d8a36b893b2bb9a87e3dde853be3aec2eefeaabb
push id5988
push usercbook@mozilla.com
push dateFri, 28 Mar 2014 09:40:37 +0000
treeherderfx-team@38c8dbb6ad87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs972503
milestone31.0a1
Bug 972503 - Allow home panel views to specify an initial filter. r=lucasr
mobile/android/base/home/FramePanelLayout.java
mobile/android/base/home/HomeConfig.java
mobile/android/base/home/PanelLayout.java
--- a/mobile/android/base/home/FramePanelLayout.java
+++ b/mobile/android/base/home/FramePanelLayout.java
@@ -33,15 +33,15 @@ class FramePanelLayout extends PanelLayo
         addView(mChildView);
     }
 
     @Override
     public void load() {
         Log.d(LOGTAG, "Loading");
 
         if (mChildView instanceof DatasetBacked) {
-            // TODO: get filter from ViewEntry
-            DatasetRequest request = new DatasetRequest(mChildConfig.getDatasetId(), null);
+            final FilterDetail filter = new FilterDetail(mChildConfig.getFilter(), null);
+            final DatasetRequest request = new DatasetRequest(mChildConfig.getDatasetId(), filter);
             Log.d(LOGTAG, "Requesting child request: " + request);
             requestDataset(request);
         }
     }
 }
--- a/mobile/android/base/home/HomeConfig.java
+++ b/mobile/android/base/home/HomeConfig.java
@@ -603,61 +603,67 @@ public final class HomeConfig {
     }
 
     public static class ViewConfig implements Parcelable {
         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 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";
 
         public ViewConfig(JSONObject json) throws JSONException, IllegalArgumentException {
             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);
 
             validate();
         }
 
         @SuppressWarnings("unchecked")
         public ViewConfig(Parcel in) {
             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();
 
             validate();
         }
 
         public ViewConfig(ViewConfig viewConfig) {
             mType = viewConfig.mType;
             mDatasetId = viewConfig.mDatasetId;
             mItemType = viewConfig.mItemType;
             mItemHandler = viewConfig.mItemHandler;
             mBackImageUrl = viewConfig.mBackImageUrl;
+            mFilter = viewConfig.mFilter;
 
             validate();
         }
 
         public ViewConfig(ViewType type, String datasetId, ItemType itemType,
-                          ItemHandler itemHandler, String backImageUrl) {
+                          ItemHandler itemHandler, String backImageUrl, String filter) {
             mType = type;
             mDatasetId = datasetId;
             mItemType = itemType;
             mItemHandler = itemHandler;
             mBackImageUrl = backImageUrl;
+            mFilter = filter;
 
             validate();
         }
 
         private void validate() {
             if (mType == null) {
                 throw new IllegalArgumentException("Can't create ViewConfig with null type");
             }
@@ -690,43 +696,52 @@ public final class HomeConfig {
         public ItemHandler getItemHandler() {
             return mItemHandler;
         }
 
         public String getBackImageUrl() {
             return mBackImageUrl;
         }
 
+        public String getFilter() {
+            return mFilter;
+        }
+
         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);
+            }
+
             return json;
         }
 
         @Override
         public int describeContents() {
             return 0;
         }
 
         @Override
         public void writeToParcel(Parcel dest, int flags) {
             dest.writeParcelable(mType, 0);
             dest.writeString(mDatasetId);
             dest.writeParcelable(mItemType, 0);
             dest.writeParcelable(mItemHandler, 0);
             dest.writeString(mBackImageUrl);
+            dest.writeString(mFilter);
         }
 
         public static final Creator<ViewConfig> CREATOR = new Creator<ViewConfig>() {
             @Override
             public ViewConfig createFromParcel(final Parcel in) {
                 return new ViewConfig(in);
             }
 
--- a/mobile/android/base/home/PanelLayout.java
+++ b/mobile/android/base/home/PanelLayout.java
@@ -396,19 +396,19 @@ abstract class PanelLayout extends Frame
 
         /**
          * Adds a filter to the history stack for this view.
          */
         public void pushFilter(FilterDetail filter) {
             if (mFilterStack == null) {
                 mFilterStack = new LinkedList<FilterDetail>();
 
-                // Initialize with a null filter.
-                // TODO: use initial filter from ViewConfig
-                mFilterStack.push(new FilterDetail(null, mPanelConfig.getTitle()));
+                // Initialize with the initial filter.
+                mFilterStack.push(new FilterDetail(mViewConfig.getFilter(),
+                                                   mPanelConfig.getTitle()));
             }
 
             mFilterStack.push(filter);
         }
 
         /**
          * Remove the most recent filter from the stack.
          *