diff --git a/res/values/strings.xml b/res/values/strings.xml
index a3d0eaffac6cc2e0a2edf2ef0a54e9f5f0338322..8450d8bc2427d4bc0cef0f6cd3442028304ecfb5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -63,7 +63,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 075379658877e2d1dbb5f8b31ebd3440d95719c6..f808162ec634795d07f56fcd5e762e7a7a6a7c6a 100644
--- a/src/org/lineageos/updater/UpdatesListAdapter.java
+++ b/src/org/lineageos/updater/UpdatesListAdapter.java
@@ -63,8 +63,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;
@@ -320,6 +322,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);
@@ -357,7 +385,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);
@@ -373,7 +409,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);
@@ -389,7 +430,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 {
@@ -522,17 +566,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)