Replace current json only if new one is valid

This commit is contained in:
Gabriele M
2017-07-05 23:35:14 +02:00
parent 3e36596127
commit eaba161d43

View File

@@ -151,10 +151,11 @@ public class UpdatesActivity extends AppCompatActivity {
} }
private void downloadUpdatesList() { private void downloadUpdatesList() {
File jsonFile = Utils.getCachedUpdateList(this); final File jsonFile = Utils.getCachedUpdateList(this);
final File jsonFileTmp = new File(jsonFile.getAbsolutePath() + ".tmp");
String url = Utils.getServerURL(this); String url = Utils.getServerURL(this);
Log.d(TAG, "Checking " + url); Log.d(TAG, "Checking " + url);
DownloadClient.downloadFile(url, jsonFile, new DownloadClient.DownloadCallback() { DownloadClient.downloadFile(url, jsonFileTmp, new DownloadClient.DownloadCallback() {
@Override @Override
public void onFailure(boolean cancelled) { public void onFailure(boolean cancelled) {
Log.e(TAG, "Could not download updates list"); Log.e(TAG, "Could not download updates list");
@@ -173,6 +174,7 @@ public class UpdatesActivity extends AppCompatActivity {
try { try {
Log.d(TAG, "List downloaded"); Log.d(TAG, "List downloaded");
loadUpdatesList(); loadUpdatesList();
jsonFileTmp.renameTo(jsonFile);
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
Log.e(TAG, "Could not read json", e); Log.e(TAG, "Could not read json", e);
} }