Load the updates stored in the database from DownloadController

Also, hide the distinction between local and non-local updates.
Local updates should be handled only by DownloadController.
This commit is contained in:
Gabriele M
2017-07-03 16:08:31 +02:00
parent 4196ccb301
commit bda4d2b9b4
3 changed files with 12 additions and 15 deletions

View File

@@ -69,6 +69,10 @@ public class DownloadController implements DownloadControllerInt {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Updater");
mWakeLock.setReferenceCounted(false);
for (UpdateDownload update : mUpdatesDbHelper.getUpdates()) {
addUpdate(update, true);
}
}
private class DownloadEntry {
@@ -220,7 +224,11 @@ public class DownloadController implements DownloadControllerInt {
}
@Override
public boolean addUpdate(UpdateDownload update, boolean local) {
public boolean addUpdate(UpdateDownload update) {
return addUpdate(update, false);
}
private boolean addUpdate(UpdateDownload update, boolean local) {
Log.d(TAG, "Adding download: " + update.getDownloadId());
if (mDownloads.containsKey(update.getDownloadId())) {
Log.e(TAG, "Download (" + update.getDownloadId() + ") already added");

View File

@@ -20,7 +20,7 @@ import java.util.Set;
public interface DownloadControllerInt {
boolean addUpdate(UpdateDownload update, boolean local);
boolean addUpdate(UpdateDownload update);
List<UpdateDownload> getUpdates();

View File

@@ -117,22 +117,11 @@ public class UpdatesActivity extends AppCompatActivity {
};
private void loadUpdatesList() throws IOException, JSONException {
// Process local files first. If they aren't valid, the controller will delete
// them from the database. If they are valid, they should be prioritized.
Log.d(TAG, "Getting updates from internal database");
DownloadControllerInt controller = mDownloadService.getDownloadController();
UpdatesDbHelper dbHelper = new UpdatesDbHelper(this);
for (UpdateDownload update : dbHelper.getUpdates()) {
controller.addUpdate(update, true);
}
Log.d(TAG, "Adding remote updates");
DownloadControllerInt controller = mDownloadService.getDownloadController();
File jsonFile = Utils.getCachedUpdateList(this);
for (UpdateDownload update : Utils.parseJson(jsonFile, true)) {
controller.addUpdate(update, true);
controller.addUpdate(update);
}
List<String> updateIds = new ArrayList<>();