Fix some crashes and caching issues

This commit is contained in:
Cameron Gutman
2015-01-31 17:01:46 -05:00
parent baa5199b83
commit 56f438fe47
2 changed files with 16 additions and 4 deletions

View File

@@ -92,9 +92,6 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
// Get the computer object
computer = managerBinder.getComputer(UUID.fromString(uuidString));
// Start updates
startComputerUpdates();
try {
appGridAdapter = new AppGridAdapter(AppView.this,
PreferenceConfiguration.readPreferences(AppView.this).listMode,
@@ -106,6 +103,9 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
return;
}
// Start updates
startComputerUpdates();
// Load the app grid with cached data (if possible)
populateAppGridWithCache();
@@ -226,6 +226,10 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
updateUiWithAppList(applist);
LimeLog.info("Loaded applist from cache");
} catch (Exception e) {
if (lastRawApplist != null) {
LimeLog.warning("Saved applist corrupted: "+lastRawApplist);
e.printStackTrace();
}
LimeLog.info("Loading applist from the network");
// We'll need to load from the network
loadAppsBlocking();

View File

@@ -3,8 +3,10 @@ package com.limelight.computers;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.net.InetAddress;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@@ -12,6 +14,7 @@ import com.limelight.LimeLog;
import com.limelight.binding.PlatformBinding;
import com.limelight.discovery.DiscoveryService;
import com.limelight.nvstream.http.ComputerDetails;
import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP;
import com.limelight.nvstream.mdns.MdnsComputer;
import com.limelight.nvstream.mdns.MdnsDiscoveryListener;
@@ -24,6 +27,8 @@ import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import org.xmlpull.v1.XmlPullParserException;
public class ComputerManagerService extends Service {
private static final int POLLING_PERIOD_MS = 3000;
private static final int MDNS_QUERY_PERIOD_MS = 1000;
@@ -544,7 +549,8 @@ public class ComputerManagerService extends Service {
try {
// Query the app list from the server
String appList = http.getAppListRaw();
if (appList != null && !appList.isEmpty()) {
List<NvApp> list = NvHTTP.getAppListByReader(new StringReader(appList));
if (appList != null && !appList.isEmpty() && !list.isEmpty()) {
// Open the cache file
FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString());
CacheHelper.writeStringToOutputStream(cacheOut, appList);
@@ -564,6 +570,8 @@ public class ComputerManagerService extends Service {
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
} while (waitPollingDelay());
}