diff --git a/src/org/lineageos/updater/ExportUpdateService.java b/src/org/lineageos/updater/ExportUpdateService.java index f05a7d11..e272dc8f 100644 --- a/src/org/lineageos/updater/ExportUpdateService.java +++ b/src/org/lineageos/updater/ExportUpdateService.java @@ -175,36 +175,30 @@ public class ExportUpdateService extends Service { startForeground(NOTIFICATION_ID, notificationBuilder.build()); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); - Runnable runnableComplete = new Runnable() { - @Override - public void run() { - notificationStyle.setSummaryText(null); - notificationStyle.setBigContentTitle( - getString(R.string.notification_export_success)); - notificationBuilder.setContentTitle( - getString(R.string.notification_export_success)); - notificationBuilder.setProgress(0, 0, false); - notificationBuilder.setContentText(destination.getName()); - notificationBuilder.mActions.clear(); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); - stopForeground(STOP_FOREGROUND_DETACH); - } + Runnable runnableComplete = () -> { + notificationStyle.setSummaryText(null); + notificationStyle.setBigContentTitle( + getString(R.string.notification_export_success)); + notificationBuilder.setContentTitle( + getString(R.string.notification_export_success)); + notificationBuilder.setProgress(0, 0, false); + notificationBuilder.setContentText(destination.getName()); + notificationBuilder.mActions.clear(); + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + stopForeground(STOP_FOREGROUND_DETACH); }; - Runnable runnableFailed = new Runnable() { - @Override - public void run() { - notificationStyle.setSummaryText(null); - notificationStyle.setBigContentTitle( - getString(R.string.notification_export_fail)); - notificationBuilder.setContentTitle( - getString(R.string.notification_export_fail)); - notificationBuilder.setProgress(0, 0, false); - notificationBuilder.setContentText(null); - notificationBuilder.mActions.clear(); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); - stopForeground(STOP_FOREGROUND_DETACH); - } + Runnable runnableFailed = () -> { + notificationStyle.setSummaryText(null); + notificationStyle.setBigContentTitle( + getString(R.string.notification_export_fail)); + notificationBuilder.setContentTitle( + getString(R.string.notification_export_fail)); + notificationBuilder.setProgress(0, 0, false); + notificationBuilder.setContentText(null); + notificationBuilder.mActions.clear(); + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + stopForeground(STOP_FOREGROUND_DETACH); }; mExportRunnable = new ExportRunnable(source, destination, progressCallBack, diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 416e1e31..b81f1127 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -60,8 +60,6 @@ import org.lineageos.updater.model.UpdateInfo; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; public class UpdatesActivity extends UpdatesListActivity { @@ -308,12 +306,7 @@ public class UpdatesActivity extends UpdatesListActivity { } else { findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.recycler_view).setVisibility(View.VISIBLE); - Collections.sort(sortedUpdates, new Comparator() { - @Override - public int compare(UpdateInfo u1, UpdateInfo u2) { - return Long.compare(u2.getTimestamp(), u1.getTimestamp()); - } - }); + sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp())); for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); } @@ -366,14 +359,11 @@ public class UpdatesActivity extends UpdatesListActivity { @Override public void onFailure(final boolean cancelled) { Log.e(TAG, "Could not download updates list"); - runOnUiThread(new Runnable() { - @Override - public void run() { - if (!cancelled) { - showSnackbar(R.string.snack_updates_check_failed, Snackbar.LENGTH_LONG); - } - refreshAnimationStop(); + runOnUiThread(() -> { + if (!cancelled) { + showSnackbar(R.string.snack_updates_check_failed, Snackbar.LENGTH_LONG); } + refreshAnimationStop(); }); } @@ -384,13 +374,10 @@ public class UpdatesActivity extends UpdatesListActivity { @Override public void onSuccess(File destination) { - runOnUiThread(new Runnable() { - @Override - public void run() { - Log.d(TAG, "List downloaded"); - processNewJson(jsonFile, jsonFileTmp, manualRefresh); - refreshAnimationStop(); - } + runOnUiThread(() -> { + Log.d(TAG, "List downloaded"); + processNewJson(jsonFile, jsonFileTmp, manualRefresh); + refreshAnimationStop(); }); } }; diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java index 5b0705ec..15768ff0 100644 --- a/src/org/lineageos/updater/UpdatesListAdapter.java +++ b/src/org/lineageos/updater/UpdatesListAdapter.java @@ -15,7 +15,6 @@ */ package org.lineageos.updater; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -292,17 +291,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + if (checkbox.isChecked()) { + preferences.edit() + .putBoolean(Constants.PREF_MOBILE_DATA_WARNING, false) + .apply(); + mActivity.supportInvalidateOptionsMenu(); } + mUpdaterController.startDownload(downloadId); }) .setNegativeButton(android.R.string.cancel, null) .show(); @@ -317,24 +313,15 @@ public class UpdatesListAdapter extends RecyclerView.Adapter startDownloadWithWarning(downloadId) : null; break; case PAUSE: button.setImageResource(R.drawable.ic_pause); button.setContentDescription( mActivity.getString(R.string.action_description_pause)); button.setEnabled(enabled); - clickListener = !enabled ? null : new View.OnClickListener() { - @Override - public void onClick(View view) { - mUpdaterController.pauseDownload(downloadId); - } - }; + clickListener = enabled ? view -> mUpdaterController.pauseDownload(downloadId) + : null; break; case RESUME: { button.setImageResource(R.drawable.ic_resume); @@ -344,17 +331,14 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + if (canInstall) { + mUpdaterController.resumeDownload(downloadId); + } else { + mActivity.showSnackbar(R.string.snack_update_not_installable, + Snackbar.LENGTH_LONG); } - }; + } : null; } break; case INSTALL: { @@ -364,29 +348,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + if (canInstall) { + getInstallDialog(downloadId).show(); + } else { + mActivity.showSnackbar(R.string.snack_update_not_installable, + Snackbar.LENGTH_LONG); } - }; + } : null; } break; case INFO: { button.setImageResource(R.drawable.ic_info); button.setContentDescription(mActivity.getString(R.string.action_description_info)); button.setEnabled(enabled); - clickListener = !enabled ? null : new View.OnClickListener() { - @Override - public void onClick(View view) { - showInfoDialog(); - } - }; + clickListener = enabled ? view -> showInfoDialog() : null; } break; case DELETE: { @@ -394,12 +370,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter getDeleteDialog(downloadId).show() : null; } break; case CANCEL_INSTALLATION: { @@ -407,12 +378,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter getCancelInstallationDialog().show() : null; } break; default: @@ -421,13 +387,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + if (clickListener != null) { + clickListener.onClick(v); + stopActionMode(); } }); } @@ -442,26 +405,20 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + mUpdaterController.pauseDownload(downloadId); + mUpdaterController.deleteUpdate(downloadId); }) .setNegativeButton(android.R.string.cancel, null); } private View.OnLongClickListener getLongClickListener(final UpdateInfo update, final boolean canDelete) { - return new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - if (mActionMode == null) { - startActionMode(update, canDelete); - } - return true; + return view -> { + if (mActionMode == null) { + startActionMode(update, canDelete); } + return true; }; } @@ -488,12 +445,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter Utils.triggerUpdate(mActivity, downloadId)) .setNegativeButton(android.R.string.cancel, null); } @@ -501,13 +453,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { + Intent intent = new Intent(mActivity, UpdaterService.class); + intent.setAction(UpdaterService.ACTION_INSTALL_STOP); + mActivity.startService(intent); }) .setNegativeButton(android.R.string.cancel, null); } @@ -559,12 +508,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter mode.finish()) .show(); return true; case R.id.menu_copy_url: diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index 35c9e207..97c939d6 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -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(); } diff --git a/src/org/lineageos/updater/download/HttpURLConnectionClient.java b/src/org/lineageos/updater/download/HttpURLConnectionClient.java index afee518b..2b7c80e3 100644 --- a/src/org/lineageos/updater/download/HttpURLConnectionClient.java +++ b/src/org/lineageos/updater/download/HttpURLConnectionClient.java @@ -192,12 +192,7 @@ public class HttpURLConnectionClient implements DownloadClient { for (Map.Entry> entry : mClient.getHeaderFields().entrySet()) { if ("Link".equalsIgnoreCase((entry.getKey()))) { duplicates = new PriorityQueue<>(entry.getValue().size(), - new Comparator() { - @Override - public int compare(DuplicateLink d1, DuplicateLink d2) { - return Integer.compare(d1.mPriority, d2.mPriority); - } - }); + Comparator.comparingInt(d -> d.mPriority)); // https://tools.ietf.org/html/rfc6249 // https://tools.ietf.org/html/rfc5988#section-5 diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 8ce368e1..255b750e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -43,7 +43,6 @@ import org.lineageos.updater.model.UpdateInfo; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; @@ -246,12 +245,8 @@ public class Utils { } public static void removeUncryptFiles(File downloadPath) { - File[] uncryptFiles = downloadPath.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.endsWith(Constants.UNCRYPT_FILE_EXT); - } - }); + File[] uncryptFiles = downloadPath.listFiles( + (dir, name) -> name.endsWith(Constants.UNCRYPT_FILE_EXT)); if (uncryptFiles == null) { return; }