diff --git a/res/values/strings.xml b/res/values/strings.xml
index 00b712781d1cf1a76434acfc6d7d9a6f43e8a336..28c92f443d76d416a1e9dc74ee6f6d2716f1e2cf 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 04ad0028a463caf9793a2005b3ea517b9d7c1057..0894f2aac2dbbbc0c92d9aef70c5c6f53d54a90e 100644
--- a/src/org/lineageos/updater/UpdatesListAdapter.java
+++ b/src/org/lineageos/updater/UpdatesListAdapter.java
@@ -57,8 +57,10 @@ import org.lineageos.updater.misc.Utils;
import org.lineageos.updater.model.UpdateInfo;
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;
@@ -307,6 +309,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);
@@ -344,7 +372,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);
@@ -360,7 +396,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);
@@ -376,7 +417,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter {
if (canInstall) {
AlertDialog.Builder installDialog = getInstallDialog(downloadId);
- if (installDialog != null) {
+ AlertDialog.Builder freeSpaceDialog = getSpaceDialog(update);
+ if (freeSpaceDialog != null) {
+ freeSpaceDialog.show();
+ } else if (installDialog != null) {
installDialog.show();
}
} else {
@@ -472,17 +516,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter= neededSpace;
- if (!hasFreeSpace) {
- String message = 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(message)
- .setPositiveButton(android.R.string.ok, null);
- }
-
String buildDate = StringGenerator.getDateLocalizedUTC(mActivity,
DateFormat.MEDIUM, update.getTimestamp());
String buildInfoText = mActivity.getString(R.string.list_build_version_date_e,