Bug 949174/964375/952311 - Encapsulate PanelInfo data behind getters (r=margaret)
authorLucas Rocha <lucasr@mozilla.com>
Wed, 05 Feb 2014 14:14:51 +0000
changeset 178000 3ce5275b17ed117820e5011456702142a8ee5b9f
parent 177999 a49670361d8ab581e91c9a44834297f142187be3
child 178001 299bcc7ae1fe60acd1de52cf82961cfa1f43fdde
push id5439
push userffxbld
push dateMon, 17 Mar 2014 23:08:15 +0000
treeherdermozilla-aurora@c0befb3c8038 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs949174, 964375, 952311
milestone30.0a1
Bug 949174/964375/952311 - Encapsulate PanelInfo data behind getters (r=margaret)
mobile/android/base/home/PanelManager.java
--- a/mobile/android/base/home/PanelManager.java
+++ b/mobile/android/base/home/PanelManager.java
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
+import org.mozilla.gecko.home.HomeConfig.PanelConfig;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.Context;
@@ -24,26 +25,41 @@ import android.util.SparseArray;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 public class PanelManager implements GeckoEventListener {
     private static final String LOGTAG = "GeckoPanelManager";
 
     public class PanelInfo {
-        public final String id;
-        public final String title;
-        public final String layout;
-        public final JSONArray views;
+        private final String mId;
+        private final String mTitle;
+        private final JSONObject mJSONData;
+
+        public PanelInfo(String id, String title, JSONObject jsonData) {
+            mId = id;
+            mTitle = title;
+            mJSONData = jsonData;
+        }
 
-        public PanelInfo(String id, String title, String layout, JSONArray views) {
-            this.id = id;
-            this.title = title;
-            this.layout = layout;
-            this.views = views;
+        public String getId() {
+            return mId;
+        }
+
+        public String getTitle() {
+            return mTitle;
+        }
+
+        public PanelConfig toPanelConfig() {
+            try {
+                return new PanelConfig(mJSONData);
+            } catch (Exception e) {
+                Log.e(LOGTAG, "Failed to convert PanelInfo to PanelConfig", e);
+                return null;
+            }
         }
     }
 
     public interface RequestCallback {
         public void onComplete(List<PanelInfo> panelInfos);
     }
 
     private static AtomicInteger sRequestId = new AtomicInteger(0);
@@ -107,14 +123,12 @@ public class PanelManager implements Gec
         } catch (JSONException e) {
             Log.e(LOGTAG, "Exception handling " + event + " message", e);
         }
     }
 
     private PanelInfo getPanelInfoFromJSON(JSONObject jsonPanelInfo) throws JSONException {
         final String id = jsonPanelInfo.getString("id");
         final String title = jsonPanelInfo.getString("title");
-        final String layout = jsonPanelInfo.getString("layout");
-        final JSONArray views = jsonPanelInfo.getJSONArray("views");
 
-        return new PanelInfo(id, title, layout, views);
+        return new PanelInfo(id, title, jsonPanelInfo);
     }
 }