Simplify code syntax using Java 8 features

Change-Id: I3e59f0c38e4047595374a951619c9b43a46901df
This commit is contained in:
Gabriele M
2018-04-08 10:26:20 +02:00
committed by Joey
parent a72b78c31e
commit a64eae5fc0
6 changed files with 100 additions and 196 deletions

View File

@@ -172,13 +172,8 @@ public class UpdaterController implements Controller {
}
update.setStatus(UpdateStatus.DOWNLOADING);
update.setPersistentStatus(UpdateStatus.Persistent.INCOMPLETE);
new Thread(new Runnable() {
@Override
public void run() {
mUpdatesDbHelper.addUpdateWithOnConflict(update,
SQLiteDatabase.CONFLICT_REPLACE);
}
}).start();
new Thread(() -> mUpdatesDbHelper.addUpdateWithOnConflict(update,
SQLiteDatabase.CONFLICT_REPLACE)).start();
notifyUpdateChange(downloadId);
}
@@ -245,25 +240,22 @@ public class UpdaterController implements Controller {
private void verifyUpdateAsync(final String downloadId) {
mVerifyingUpdates.add(downloadId);
new Thread(new Runnable() {
@Override
public void run() {
Update update = mDownloads.get(downloadId).mUpdate;
File file = update.getFile();
if (file.exists() && verifyPackage(file)) {
file.setReadable(true, false);
update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
mUpdatesDbHelper.changeUpdateStatus(update);
update.setStatus(UpdateStatus.VERIFIED);
} else {
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
mUpdatesDbHelper.removeUpdate(downloadId);
update.setProgress(0);
update.setStatus(UpdateStatus.VERIFICATION_FAILED);
}
mVerifyingUpdates.remove(downloadId);
notifyUpdateChange(downloadId);
new Thread(() -> {
Update update = mDownloads.get(downloadId).mUpdate;
File file = update.getFile();
if (file.exists() && verifyPackage(file)) {
file.setReadable(true, false);
update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
mUpdatesDbHelper.changeUpdateStatus(update);
update.setStatus(UpdateStatus.VERIFIED);
} else {
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
mUpdatesDbHelper.removeUpdate(downloadId);
update.setProgress(0);
update.setStatus(UpdateStatus.VERIFICATION_FAILED);
}
mVerifyingUpdates.remove(downloadId);
notifyUpdateChange(downloadId);
}).start();
}
@@ -454,15 +446,12 @@ public class UpdaterController implements Controller {
}
private void deleteUpdateAsync(final Update update) {
new Thread(new Runnable() {
@Override
public void run() {
File file = update.getFile();
if (file.exists() && !file.delete()) {
Log.e(TAG, "Could not delete " + file.getAbsolutePath());
}
mUpdatesDbHelper.removeUpdate(update.getDownloadId());
new Thread(() -> {
File file = update.getFile();
if (file.exists() && !file.delete()) {
Log.e(TAG, "Could not delete " + file.getAbsolutePath());
}
mUpdatesDbHelper.removeUpdate(update.getDownloadId());
}).start();
}