Add some new common functions for app list caching

This commit is contained in:
Cameron Gutman 2015-01-30 18:27:15 -05:00
parent 8235717502
commit 9988330613
3 changed files with 19 additions and 5 deletions

View File

@ -21,6 +21,7 @@ public class ComputerDetails {
public PairingManager.PairState pairState;
public String macAddress;
public int runningGameId;
public String rawAppList;
public ComputerDetails() {
// Use defaults
@ -43,6 +44,7 @@ public class ComputerDetails {
this.macAddress = details.macAddress;
this.pairState = details.pairState;
this.runningGameId = details.runningGameId;
this.rawAppList = details.rawAppList;
}
@Override

View File

@ -17,6 +17,10 @@ public class NvApp {
this.isRunning = isRunning.equals("1");
}
public void setIsRunningBoolean(boolean isRunning) {
this.isRunning = isRunning;
}
public String getAppName() {
return this.appName;
}

View File

@ -304,13 +304,12 @@ public class NvHTTP {
return pm.pair(uniqueId, pin);
}
public LinkedList<NvApp> getAppList() throws GfeHttpResponseException, IOException, XmlPullParserException {
ResponseBody resp = openHttpConnection(baseUrl + "/applist?uniqueid=" + uniqueId, true);
public static LinkedList<NvApp> getAppListByReader(Reader r) throws XmlPullParserException, IOException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new InputStreamReader(resp.byteStream()));
xpp.setInput(r);
int eventType = xpp.getEventType();
LinkedList<NvApp> appList = new LinkedList<NvApp>();
Stack<String> currentTag = new Stack<String>();
@ -342,9 +341,18 @@ public class NvHTTP {
}
eventType = xpp.next();
}
return appList;
}
public String getAppListRaw() throws MalformedURLException, IOException {
return openHttpConnectionToString(baseUrl + "/applist?uniqueid=" + uniqueId, true);
}
public LinkedList<NvApp> getAppList() throws GfeHttpResponseException, IOException, XmlPullParserException {
ResponseBody resp = openHttpConnection(baseUrl + "/applist?uniqueid=" + uniqueId, true);
LinkedList<NvApp> appList = getAppListByReader(new InputStreamReader(resp.byteStream()));
resp.close();
return appList;
}