mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-16 22:01:14 +00:00
Fix some caching bugs
This commit is contained in:
@@ -156,6 +156,8 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consecutiveAppListFailures = 0;
|
||||||
|
|
||||||
// App list is the same or empty; nothing to do
|
// App list is the same or empty; nothing to do
|
||||||
if (details.rawAppList == null || details.rawAppList.equals(lastRawApplist)) {
|
if (details.rawAppList == null || details.rawAppList.equals(lastRawApplist)) {
|
||||||
return;
|
return;
|
||||||
@@ -219,7 +221,9 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
|
|||||||
private void populateAppGridWithCache() {
|
private void populateAppGridWithCache() {
|
||||||
try {
|
try {
|
||||||
// Try to load from cache
|
// Try to load from cache
|
||||||
updateUiWithAppList(NvHTTP.getAppListByReader(new InputStreamReader(CacheHelper.openCacheFileForInput(getCacheDir(), "applist", uuidString))));
|
lastRawApplist = CacheHelper.readInputStreamToString(CacheHelper.openCacheFileForInput(getCacheDir(), "applist", uuidString));
|
||||||
|
List<NvApp> applist = NvHTTP.getAppListByReader(new StringReader(lastRawApplist));
|
||||||
|
updateUiWithAppList(applist);
|
||||||
LimeLog.info("Loaded applist from cache");
|
LimeLog.info("Loaded applist from cache");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LimeLog.info("Loading applist from the network");
|
LimeLog.info("Loading applist from the network");
|
||||||
|
|||||||
@@ -520,7 +520,9 @@ public class ComputerManagerService extends Service {
|
|||||||
|
|
||||||
// Can't poll if it's not online
|
// Can't poll if it's not online
|
||||||
if (computer.state != ComputerDetails.State.ONLINE) {
|
if (computer.state != ComputerDetails.State.ONLINE) {
|
||||||
listener.notifyComputerUpdated(computer);
|
if (listener != null) {
|
||||||
|
listener.notifyComputerUpdated(computer);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,20 +544,23 @@ public class ComputerManagerService extends Service {
|
|||||||
try {
|
try {
|
||||||
// Query the app list from the server
|
// Query the app list from the server
|
||||||
String appList = http.getAppListRaw();
|
String appList = http.getAppListRaw();
|
||||||
|
if (appList != null && !appList.isEmpty()) {
|
||||||
|
// Open the cache file
|
||||||
|
FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString());
|
||||||
|
CacheHelper.writeStringToOutputStream(cacheOut, appList);
|
||||||
|
cacheOut.close();
|
||||||
|
|
||||||
// Open the cache file
|
// Update the computer
|
||||||
LimeLog.info("Updating app list from "+computer.uuid.toString());
|
computer.rawAppList = appList;
|
||||||
FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString());
|
|
||||||
CacheHelper.writeStringToOutputStream(cacheOut, appList);
|
|
||||||
cacheOut.close();
|
|
||||||
|
|
||||||
// Update the computer
|
// Notify that the app list has been updated
|
||||||
computer.rawAppList = appList;
|
// and ensure that the thread is still active
|
||||||
|
if (listener != null && thread != null) {
|
||||||
// Notify that the app list has been updated
|
listener.notifyComputerUpdated(computer);
|
||||||
// and ensure that the thread is still active
|
}
|
||||||
if (listener != null && thread != null) {
|
}
|
||||||
listener.notifyComputerUpdated(computer);
|
else {
|
||||||
|
LimeLog.warning("Empty app list received from "+computer.uuid);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -38,12 +38,14 @@ public class CacheHelper {
|
|||||||
return new FileOutputStream(openPath(true, root, path));
|
return new FileOutputStream(openPath(true, root, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readInputStreamToString(InputStream in) {
|
public static String readInputStreamToString(InputStream in) throws IOException {
|
||||||
Scanner s = new Scanner(in);
|
Reader r = new InputStreamReader(in);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
while (s.hasNext()) {
|
char[] buf = new char[256];
|
||||||
sb.append(s.next());
|
int bytesRead;
|
||||||
|
while ((bytesRead = r.read(buf)) != -1) {
|
||||||
|
sb.append(buf, 0, bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user