diff --git a/res/values/strings.xml b/res/values/strings.xml index 9ad6749abfd3dd9e4e1888c6de217af70e1a8001..56d312b0ac26281d0c65005dbd6db44268cbe7e6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -62,7 +62,7 @@ Low battery The battery level is too low, you need at least %1$d%% of the battery to continue, %2$d%% if charging. Free up space - The update cannot be completed because there is insufficient free space; at least %1$s of free space is required. Please clear your internal storage before proceeding. + There is insufficient space available to successfully complete the update. You must free up another %1$s of space in the internal storage before proceeding. Reboot diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java index 82304df6b141e3f6dcb0c9596f38ea9be13fc777..051537cb60eb5e6027e5591f6a0328183d444c39 100644 --- a/src/org/lineageos/updater/UpdatesListAdapter.java +++ b/src/org/lineageos/updater/UpdatesListAdapter.java @@ -60,6 +60,7 @@ import org.lineageos.updater.model.UpdateStatus; import java.io.File; import java.io.IOException; import java.text.DateFormat; +import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.List; @@ -310,6 +311,32 @@ public class UpdatesListAdapter extends RecyclerView.Adapter 0 && + updateFile.length() < update.getFileSize()) { + requiredSpace -= updateFile.length(); + } + + if (availableFreeSpace < requiredSpace) { + // Not enough space to download file + double spaceNeeded = (requiredSpace - availableFreeSpace) / (1024.0 * 1024.0); + String message = resources.getString(R.string.dialog_free_space_low_message_pct, + new DecimalFormat("#MB").format(spaceNeeded)); + return new AlertDialog.Builder(mActivity) + .setTitle(R.string.dialog_free_space_low_title) + .setMessage(message) + .setPositiveButton(android.R.string.ok, null); + } + + return null; + } + private void startDownloadWithWarning(final String downloadId) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mActivity); boolean warn = preferences.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true); @@ -347,7 +374,15 @@ public class UpdatesListAdapter extends RecyclerView.Adapter startDownloadWithWarning(downloadId) : null; + clickListener = enabled ? view -> { + AlertDialog.Builder freeSpaceDialog = getSpaceDialog( + mUpdaterController.getUpdate(downloadId)); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else { + startDownloadWithWarning(downloadId); + } + } : null; break; case PAUSE: button.setText(R.string.action_pause); @@ -363,7 +398,12 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (canInstall) { - mUpdaterController.resumeDownload(downloadId); + AlertDialog.Builder freeSpaceDialog = getSpaceDialog(update); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else { + mUpdaterController.resumeDownload(downloadId); + } } else { mActivity.showSnackbar(R.string.snack_update_not_installable, Snackbar.LENGTH_LONG); @@ -378,7 +418,13 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (canInstall) { - getInstallDialog(downloadId).show(); + AlertDialog.Builder installDialog = getInstallDialog(downloadId); + AlertDialog.Builder freeSpaceDialog = getSpaceDialog(update); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else if (installDialog != null) { + installDialog.show(); + } } else { mActivity.showSnackbar(R.string.snack_update_not_installable, Snackbar.LENGTH_LONG); @@ -497,17 +543,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter= neededSpace; - if (!hasFreeSpace) { - String spaceMessage = resources.getString(R.string.dialog_free_space_low_message_pct, - Utils.getFileSize(neededSpace)); - return new AlertDialog.Builder(mActivity) - .setTitle(R.string.dialog_free_space_low_title) - .setMessage(spaceMessage) - .setPositiveButton(android.R.string.ok, null); - } - return new AlertDialog.Builder(mActivity) .setTitle(title) .setMessage(message)