Bug 949174/964375/952311 - Encapsulate PanelInfo data behind getters (r=margaret)
--- 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);
}
}