Merge pull request #2252 from stefanhoehne/master
Properly calculate the disk usage change for downloads of updates, improve messages to user
This commit is contained in:
commit
0278245300
2 changed files with 43 additions and 7 deletions
|
@ -9,6 +9,15 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="download_files_error_not_enough_space">Not enough space!
|
||||
This would need {3} MB temporarily and {1} MB permanently.
|
||||
Currently, there are only {2} MB available.</string>
|
||||
<string name="download_files_question_space_with_temp">Really download {0} file(s)?
|
||||
This needs {3} MB temporarily and {1} MB permanently?
|
||||
Currently, there are {2} MB available.</string>
|
||||
<string name="download_files_question_space">Really download {0} file(s)?
|
||||
This needs {1} MB permanently?
|
||||
Currently, there are {2} MB available.</string>
|
||||
<string name="show_map_markers_topbar">Show Map markers topbar</string>
|
||||
<string name="map_marker_1st">First Map marker</string>
|
||||
<string name="map_marker_2nd">Second Map marker</string>
|
||||
|
@ -1612,7 +1621,6 @@ If you need help with OsmAnd application, please contact our support team: suppo
|
|||
<string name="osmand_service">Background mode</string>
|
||||
<string name="osmand_service_descr">OsmAnd runs in background while screen is off</string>
|
||||
<string name="download_files_not_enough_space">There is not enough free space to download %1$s MB (free: %2$s).</string>
|
||||
<string name="download_files_question_space">Free space now {2} MB! Download {0} file(s) ({1} MB)?</string>
|
||||
<string name="use_transparent_map_theme">Transparent theme</string>
|
||||
<string name="native_library_not_supported">Native library is not supported on this device.</string>
|
||||
<string name="init_native_library">Initializing native library…</string>
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class DownloadValidationManager {
|
||||
|
@ -46,23 +47,50 @@ public class DownloadValidationManager {
|
|||
return app;
|
||||
}
|
||||
|
||||
private long getExistingFileSize(File file) {
|
||||
if (file != null) {
|
||||
if (file.canRead()) {
|
||||
return file.length();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void downloadFilesCheck_3_ValidateSpace(final FragmentActivity context, final IndexItem... items) {
|
||||
long szLong = 0;
|
||||
long szChangeLong = 0;
|
||||
long szMaxTempLong = 0;
|
||||
int i = 0;
|
||||
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
|
||||
szLong += es.contentSize;
|
||||
final long szExistingLong = getExistingFileSize(es.getTargetFile(getMyApplication()));
|
||||
long change = es.contentSize - szExistingLong;
|
||||
szChangeLong += change;
|
||||
if (szExistingLong > szMaxTempLong) szMaxTempLong = szExistingLong;
|
||||
i++;
|
||||
}
|
||||
for (IndexItem es : items) {
|
||||
szLong += es.contentSize;
|
||||
final long szExistingLong = getExistingFileSize(es.getTargetFile(getMyApplication()));
|
||||
long change = es.contentSize - szExistingLong;
|
||||
szChangeLong += change;
|
||||
if (szExistingLong > szMaxTempLong) szMaxTempLong = szExistingLong;
|
||||
i++;
|
||||
}
|
||||
double sz = ((double) szLong) / (1 << 20);
|
||||
double szChange = ((double) szChangeLong) / (1 << 20);
|
||||
double szMaxTemp = szChange + ((double) szMaxTempLong) / (1 << 20);
|
||||
|
||||
// get availabile space
|
||||
double asz = downloadThread.getAvailableSpace();
|
||||
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
|
||||
if (asz != -1 && asz > 0 && (szMaxTemp > asz)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setMessage(MessageFormat.format(context.getString(R.string.download_files_question_space), i, sz, asz));
|
||||
builder.setMessage(MessageFormat.format(context.getString(R.string.download_files_error_not_enough_space), i, szChange, asz, szMaxTemp));
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
builder.show();
|
||||
} else if (asz != -1 && asz > 0 && (szChange / asz > 0.8 || szMaxTemp / asz > 0.9)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
if (szChange != szMaxTemp) {
|
||||
builder.setMessage(MessageFormat.format(context.getString(R.string.download_files_question_space_with_temp), i, szChange, asz, szMaxTemp));
|
||||
} else {
|
||||
builder.setMessage(MessageFormat.format(context.getString(R.string.download_files_question_space), i, szChange, asz));
|
||||
}
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
|
Loading…
Reference in a new issue