Fix compilation errors
This commit is contained in:
parent
b07b830e96
commit
2fb9610b82
8 changed files with 289 additions and 290 deletions
|
@ -57,8 +57,11 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
|
||||
|
||||
public void cancelDownload(IndexItem item) {
|
||||
// TODO Auto-generated method stub
|
||||
FIXME;
|
||||
downloadListIndexThread.cancelDownload(item);
|
||||
}
|
||||
|
||||
public void startDownload(IndexItem... items) {
|
||||
downloadFilesWithAllChecks(items);
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,7 +74,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
}
|
||||
|
||||
@UiThread
|
||||
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
}
|
||||
|
||||
public void downloadedIndexes() {
|
||||
|
@ -119,66 +122,63 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean startDownload(IndexItem... items) {
|
||||
for(IndexItem i : items) {
|
||||
downloadListIndexThread.addToDownload(i);
|
||||
}
|
||||
// FIXME ??? commented line
|
||||
// if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
|
||||
// return false;
|
||||
// }
|
||||
downloadFilesWithAllChecks();
|
||||
updateFragments();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void downloadFilesPreCheckSpace() {
|
||||
double sz = 0;
|
||||
List<DownloadEntry> list = downloadListIndexThread.flattenDownloadEntries();
|
||||
for (DownloadEntry es : list) {
|
||||
sz += es.sizeMB;
|
||||
public void downloadFilesCheck_3_ValidateSpace(final IndexItem... items) {
|
||||
long szLong = 0;
|
||||
int i = 0;
|
||||
for (IndexItem es : downloadListIndexThread.getCurrentDownloadingItems()) {
|
||||
szLong += es.contentSize;
|
||||
i++;
|
||||
}
|
||||
for (IndexItem es : items) {
|
||||
szLong += es.contentSize;
|
||||
i++;
|
||||
}
|
||||
double sz = ((double) szLong) / (1 << 20);
|
||||
// get availabile space
|
||||
double asz = downloadListIndexThread.getAvailableSpace();
|
||||
if (asz != -1 && asz > 0 && sz / asz > 0.4) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), list.size(), sz, asz));
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.download_files_question_space), i, sz, asz));
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
downloadListIndexThread.runDownloadFiles();
|
||||
downloadFileCheck_Final_Run(items);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
builder.show();
|
||||
} else {
|
||||
downloadListIndexThread.runDownloadFiles();
|
||||
downloadFileCheck_Final_Run(items);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadFileCheck_Final_Run(IndexItem[] items) {
|
||||
downloadListIndexThread.runDownloadFiles(items);
|
||||
updateFragments();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void downloadFilesWithAllChecks() {
|
||||
downloadFilesCheckFreeVersion();
|
||||
protected void downloadFilesWithAllChecks(IndexItem[] items) {
|
||||
downloadFilesCheck_1_FreeVersion(items);
|
||||
}
|
||||
|
||||
protected void downloadFilesCheckFreeVersion() {
|
||||
protected void downloadFilesCheck_1_FreeVersion(IndexItem[] items) {
|
||||
if (Version.isFreeVersion(getMyApplication())) {
|
||||
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
|
||||
new InstallPaidVersionDialogFragment()
|
||||
.show(getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG);
|
||||
} else {
|
||||
downloadFilesCheckInternet();
|
||||
downloadFilesCheck_2_Internet(items);
|
||||
}
|
||||
} else {
|
||||
downloadFilesCheckInternet();
|
||||
downloadFilesCheck_2_Internet(items);
|
||||
}
|
||||
}
|
||||
|
||||
protected void downloadFilesCheckInternet() {
|
||||
protected void downloadFilesCheck_2_Internet(IndexItem[] items) {
|
||||
if (!getMyApplication().getSettings().isWifiConnected()) {
|
||||
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
|
||||
new ConfirmDownloadDialogFragment().show(getSupportFragmentManager(),
|
||||
|
@ -187,7 +187,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
AccessibleToast.makeText(this, R.string.no_index_file_to_download, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
downloadFilesPreCheckSpace();
|
||||
downloadFilesCheck_3_ValidateSpace(items);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,8 +196,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
fragSet.add(new WeakReference<Fragment>(fragment));
|
||||
}
|
||||
|
||||
public void makeSureUserCancelDownload(IndexItem item) {
|
||||
TODO;
|
||||
public void makeSureUserCancelDownload(final IndexItem item) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setTitle(getString(R.string.shared_string_cancel));
|
||||
bld.setMessage(R.string.confirm_interrupt_download);
|
||||
|
@ -205,14 +204,13 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
cancelDownload.run();
|
||||
cancelDownload(item);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.shared_string_no, null);
|
||||
bld.show();
|
||||
}
|
||||
|
||||
|
||||
public static class InstallPaidVersionDialogFragment extends DialogFragment {
|
||||
public static final String TAG = "InstallPaidVersionDialogFragment";
|
||||
@NonNull
|
||||
|
@ -258,7 +256,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
((BaseDownloadActivity) getActivity()).downloadFilesPreCheckSpace();
|
||||
((BaseDownloadActivity) getActivity()).downloadFilesCheck_3_ValidateSpace();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
|
|
|
@ -150,7 +150,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask =
|
||||
downloadListIndexThread.getCurrentRunningTask();
|
||||
if (visibleBanner != null) {
|
||||
|
@ -214,7 +214,8 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
if(activeDownloads != null) {
|
||||
activeDownloads.refresh();
|
||||
}
|
||||
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
|
||||
// FIXME
|
||||
//((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
|
||||
for (WeakReference<Fragment> ref : fragSet) {
|
||||
Fragment f = ref.get();
|
||||
notifyUpdateDataSetChanged(f);
|
||||
|
@ -259,7 +260,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
|
||||
public void registerFreeVersionBanner(View view) {
|
||||
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
|
||||
updateProgress(true, null);
|
||||
updateProgress(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -354,7 +355,6 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
|
||||
String message = basicProgressAsyncTask.getDescription();
|
||||
int percent = basicProgressAsyncTask.getProgressPercentage();
|
||||
|
||||
setMinimizedFreeVersionBanner(true);
|
||||
updateAvailableDownloads(countedDownloads);
|
||||
downloadProgressLayout.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -14,20 +14,16 @@ public class DownloadEntry {
|
|||
|
||||
public String baseName;
|
||||
public String urlToDownload;
|
||||
public File existingBackupFile;
|
||||
public boolean isAsset;
|
||||
public String assetName;
|
||||
public DownloadActivityType type;
|
||||
|
||||
public IndexItem item;
|
||||
|
||||
public DownloadEntry(IndexItem item) {
|
||||
this.item = item;
|
||||
public DownloadEntry() {
|
||||
}
|
||||
|
||||
public DownloadEntry(IndexItem pr, String assetName, String fileName, long dateModified) {
|
||||
public DownloadEntry(String assetName, String fileName, long dateModified) {
|
||||
this.dateModified = dateModified;
|
||||
this.item = pr;
|
||||
targetFile = new File(fileName);
|
||||
this.assetName = assetName;
|
||||
isAsset = true;
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.OsmAndCollator;
|
||||
|
@ -34,25 +37,20 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class DownloadIndexesThread {
|
||||
|
@ -64,6 +62,9 @@ public class DownloadIndexesThread {
|
|||
private DatabaseHelper dbHelper;
|
||||
private DownloadFileHelper downloadFileHelper;
|
||||
private List<BasicProgressAsyncTask<?, ?, ?, ?>> currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?, ?>>());
|
||||
private ConcurrentLinkedQueue<IndexItem> indexItemDownloading = new ConcurrentLinkedQueue<IndexItem>();
|
||||
private IndexItem currentDownloadingItem = null;
|
||||
private int currentDownloadingItemProgress = 0;
|
||||
|
||||
|
||||
private DownloadIndexes indexes = new DownloadIndexes();
|
||||
|
@ -76,7 +77,6 @@ public class DownloadIndexesThread {
|
|||
private Map<String, String> indexFileNames = new LinkedHashMap<>();
|
||||
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<>();
|
||||
private List<IndexItem> itemsToUpdate = new ArrayList<>();
|
||||
private Map<IndexItem, List<DownloadEntry>> entriesToDownload = new LinkedHashMap<IndexItem, List<DownloadEntry>>();
|
||||
|
||||
|
||||
|
||||
|
@ -93,21 +93,16 @@ public class DownloadIndexesThread {
|
|||
this.uiActivity = uiActivity;
|
||||
}
|
||||
|
||||
public List<DownloadEntry> flattenDownloadEntries() {
|
||||
List<DownloadEntry> res = new ArrayList<DownloadEntry>();
|
||||
for (List<DownloadEntry> ens : getEntriesToDownload().values()) {
|
||||
if (ens != null) {
|
||||
res.addAll(ens);
|
||||
}
|
||||
public List<IndexItem> getCurrentDownloadingItems() {
|
||||
List<IndexItem> res = new ArrayList<IndexItem>();
|
||||
IndexItem ii = currentDownloadingItem;
|
||||
if(ii != null) {
|
||||
res.add(ii);
|
||||
}
|
||||
res.addAll(indexItemDownloading);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void addToDownload(IndexItem item) {
|
||||
List<DownloadEntry> download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList<DownloadEntry>());
|
||||
getEntriesToDownload().put(item, download);
|
||||
}
|
||||
|
||||
public List<IndexItem> getCachedIndexFiles() {
|
||||
return indexes.indexFiles != null ? indexes.indexFiles.getIndexFiles() : null;
|
||||
}
|
||||
|
@ -268,12 +263,27 @@ public class DownloadIndexesThread {
|
|||
execute(new ReloadIndexesTask(ctx));
|
||||
}
|
||||
|
||||
public void runDownloadFiles() {
|
||||
public void runDownloadFiles(IndexItem... items) {
|
||||
if (getCurrentRunningTask() instanceof ReloadIndexesTask) {
|
||||
if(checkRunning()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(IndexItem i : items) {
|
||||
indexItemDownloading.add(i);
|
||||
}
|
||||
if (currentDownloadingItem == null) {
|
||||
execute(new DownloadIndexesAsyncTask(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelDownload(IndexItem item) {
|
||||
if(currentDownloadingItem == item) {
|
||||
downloadFileHelper.setInterruptDownloading(true);;
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private <P> void execute(BasicProgressAsyncTask<?, P, ?, ?> task, P... indexItems) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
|
@ -388,6 +398,15 @@ public class DownloadIndexesThread {
|
|||
return false;
|
||||
}
|
||||
|
||||
public IndexItem getCurrentDownloadingItem() {
|
||||
return currentDownloadingItem;
|
||||
}
|
||||
|
||||
public int getCurrentDownloadingItemProgress() {
|
||||
return currentDownloadingItemProgress;
|
||||
}
|
||||
|
||||
// FIXME deprecated
|
||||
public BasicProgressAsyncTask<?, ?, ?, ?> getCurrentRunningTask() {
|
||||
for (int i = 0; i < currentRunningTask.size(); ) {
|
||||
if (currentRunningTask.get(i).getStatus() == Status.FINISHED) {
|
||||
|
@ -451,12 +470,12 @@ public class DownloadIndexesThread {
|
|||
|
||||
public int getCountedDownloads() {
|
||||
int i = 0;
|
||||
Collection<List<DownloadEntry>> vs = getEntriesToDownload().values();
|
||||
for (List<DownloadEntry> v : vs) {
|
||||
for (DownloadEntry e : v) {
|
||||
if (DownloadActivityType.isCountedInDownloads(e.item)) {
|
||||
if(currentDownloadingItem != null && DownloadActivityType.isCountedInDownloads(currentDownloadingItem)) {
|
||||
i++;
|
||||
}
|
||||
for(IndexItem ii : indexItemDownloading) {
|
||||
if (DownloadActivityType.isCountedInDownloads(ii)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
@ -501,7 +520,7 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false, tag);
|
||||
uiActivity.updateProgress(false);
|
||||
uiActivity.onCategorizationFinished();
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +551,7 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress, Void tag) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress, null);
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -543,6 +562,7 @@ public class DownloadIndexesThread {
|
|||
|
||||
private OsmandPreference<Integer> downloads;
|
||||
|
||||
|
||||
public DownloadIndexesAsyncTask(Context ctx) {
|
||||
super(ctx);
|
||||
downloads = app.getSettings().NUMBER_OF_FREE_DOWNLOADS;
|
||||
|
@ -559,11 +579,11 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected void onProgressUpdate(Object... values) {
|
||||
for (Object o : values) {
|
||||
if (o instanceof DownloadEntry) {
|
||||
if (o instanceof IndexItem) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateFragments();
|
||||
DownloadEntry item = (DownloadEntry) o;
|
||||
String name = item.item.getBasename();
|
||||
IndexItem item = (IndexItem) o;
|
||||
String name = item.getBasename();
|
||||
long count = dbHelper.getCount(name, DatabaseHelper.DOWNLOAD_ENTRY) + 1;
|
||||
DatabaseHelper.HistoryDownloadEntry entry = new DatabaseHelper.HistoryDownloadEntry(name, count);
|
||||
if (count == 1) {
|
||||
|
@ -572,15 +592,6 @@ public class DownloadIndexesThread {
|
|||
dbHelper.update(entry, DatabaseHelper.DOWNLOAD_ENTRY);
|
||||
}
|
||||
}
|
||||
} else if (o instanceof IndexItem) {
|
||||
entriesToDownload.remove(o);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateFragments();
|
||||
IndexItem item = (IndexItem) o;
|
||||
|
||||
long count = dbHelper.getCount(item.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) + 1;
|
||||
dbHelper.add(new DatabaseHelper.HistoryDownloadEntry(item.getBasename(), count), DatabaseHelper.DOWNLOAD_ENTRY);
|
||||
}
|
||||
} else if (o instanceof String) {
|
||||
String message = (String) o;
|
||||
if (!message.equals("I/O error occurred : Interrupted")) {
|
||||
|
@ -590,7 +601,7 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
} else {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(true, null);
|
||||
uiActivity.updateProgress(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -637,74 +648,43 @@ public class DownloadIndexesThread {
|
|||
try {
|
||||
List<File> filesToReindex = new ArrayList<File>();
|
||||
boolean forceWifi = downloadFileHelper.isWifiConnected();
|
||||
Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
|
||||
String breakDownloadMessage = null;
|
||||
downloadCycle:
|
||||
while (!entriesToDownload.isEmpty()) {
|
||||
Iterator<Entry<IndexItem, List<DownloadEntry>>> it = entriesToDownload.entrySet().iterator();
|
||||
IndexItem file = null;
|
||||
List<DownloadEntry> list = null;
|
||||
while (it.hasNext()) {
|
||||
Entry<IndexItem, List<DownloadEntry>> n = it.next();
|
||||
if (!currentDownloads.containsAll(n.getValue())) {
|
||||
file = n.getKey();
|
||||
list = n.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
break downloadCycle;
|
||||
}
|
||||
if (list != null) {
|
||||
boolean success = false;
|
||||
for (DownloadEntry entry : list) {
|
||||
if (currentDownloads.contains(entry)) {
|
||||
Set<IndexItem> currentDownloads = new HashSet<IndexItem>();
|
||||
try {
|
||||
downloadCycle: while (!indexItemDownloading.isEmpty()) {
|
||||
IndexItem item = indexItemDownloading.poll();
|
||||
currentDownloadingItem = item;
|
||||
currentDownloadingItemProgress = 0;
|
||||
if (currentDownloads.contains(item)) {
|
||||
continue;
|
||||
}
|
||||
currentDownloads.add(entry);
|
||||
double asz = getAvailableSpace();
|
||||
// validate interrupted
|
||||
if (downloadFileHelper.isInterruptDownloading()) {
|
||||
currentDownloads.add(item);
|
||||
boolean success = false;
|
||||
if(!validateEnoughSpace(item)) {
|
||||
break downloadCycle;
|
||||
}
|
||||
// validate enough space
|
||||
if (asz != -1 && entry.sizeMB > asz) {
|
||||
breakDownloadMessage = app.getString(R.string.download_files_not_enough_space, entry.sizeMB, asz);
|
||||
if(!validateNotExceedsFreeLimit(item)) {
|
||||
break downloadCycle;
|
||||
}
|
||||
if (exceedsFreelimit(entry)) {
|
||||
breakDownloadMessage = app.getString(R.string.free_version_message, DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS
|
||||
+ "");
|
||||
break downloadCycle;
|
||||
}
|
||||
setTag(entry);
|
||||
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
||||
setTag(item);
|
||||
boolean result = downloadFile(item, filesToReindex, forceWifi);
|
||||
success = result || success;
|
||||
if (result) {
|
||||
if (DownloadActivityType.isCountedInDownloads(entry.item)) {
|
||||
if (DownloadActivityType.isCountedInDownloads(item)) {
|
||||
downloads.set(downloads.get() + 1);
|
||||
}
|
||||
if (entry.existingBackupFile != null) {
|
||||
Algorithms.removeAllFiles(entry.existingBackupFile);
|
||||
File bf = item.getBackupFile(app);
|
||||
if (bf.exists()) {
|
||||
Algorithms.removeAllFiles(bf);
|
||||
}
|
||||
// trackEvent(entry);
|
||||
publishProgress(entry);
|
||||
publishProgress(item);
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
entriesToDownload.remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
currentDownloadingItem = null;
|
||||
currentDownloadingItemProgress = 0;
|
||||
}
|
||||
String warn = reindexFiles(filesToReindex);
|
||||
if (breakDownloadMessage != null) {
|
||||
if (warn != null) {
|
||||
warn = breakDownloadMessage + "\n" + warn;
|
||||
} else {
|
||||
warn = breakDownloadMessage;
|
||||
}
|
||||
}
|
||||
updateLoadedFiles();
|
||||
return warn;
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -714,10 +694,30 @@ public class DownloadIndexesThread {
|
|||
return null;
|
||||
}
|
||||
|
||||
private boolean exceedsFreelimit(DownloadEntry entry) {
|
||||
return Version.isFreeVersion(app) &&
|
||||
DownloadActivityType.isCountedInDownloads(entry.item) && downloads.get() >= DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||
private boolean validateEnoughSpace(IndexItem item) {
|
||||
double asz = getAvailableSpace();
|
||||
double cs =(item.contentSize / (1 << 20));
|
||||
// validate enough space
|
||||
if (asz != -1 && cs > asz) {
|
||||
String breakDownloadMessage = app.getString(R.string.download_files_not_enough_space,
|
||||
cs, asz);
|
||||
publishProgress(breakDownloadMessage);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validateNotExceedsFreeLimit(IndexItem item) {
|
||||
boolean exceed = Version.isFreeVersion(app) &&
|
||||
DownloadActivityType.isCountedInDownloads(item) && downloads.get() >= DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||
if(exceed) {
|
||||
String breakDownloadMessage = app.getString(R.string.free_version_message,
|
||||
DownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
|
||||
publishProgress(breakDownloadMessage);
|
||||
}
|
||||
return !exceed;
|
||||
}
|
||||
|
||||
|
||||
private String reindexFiles(List<File> filesToReindex) {
|
||||
boolean vectorMapsToReindex = false;
|
||||
|
@ -760,9 +760,14 @@ public class DownloadIndexesThread {
|
|||
publishProgress(warning);
|
||||
}
|
||||
|
||||
public boolean downloadFile(DownloadEntry de, List<File> filesToReindex, boolean forceWifi)
|
||||
public boolean downloadFile(IndexItem item, List<File> filesToReindex, boolean forceWifi)
|
||||
throws InterruptedException {
|
||||
downloadFileHelper.setInterruptDownloading(false);
|
||||
DownloadEntry de = item.createDownloadEntry(app);
|
||||
boolean res = false;
|
||||
if(de == null) {
|
||||
return res;
|
||||
}
|
||||
if (de.isAsset) {
|
||||
try {
|
||||
if (ctx != null) {
|
||||
|
@ -783,10 +788,11 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||
}
|
||||
protected void updateProgress(boolean updateOnlyProgress, IndexItem tag) {
|
||||
currentDownloadingItemProgress = getProgressPercentage();
|
||||
uiActivity.updateProgress(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -169,9 +169,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type, List<DownloadEntry> res) {
|
||||
res.add(new DownloadEntry(this, assetName, destFile, dateModified));
|
||||
return res;
|
||||
public DownloadEntry createDownloadEntry(OsmandApplication ctx) {
|
||||
return new DownloadEntry(assetName, destFile, dateModified);
|
||||
}
|
||||
|
||||
public String getDestFile(){
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.HasName;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
||||
public class IndexItem implements Comparable<IndexItem>/*, Parcelable*/ {
|
||||
private static final Log log = PlatformUtil.getLog(IndexItem.class);
|
||||
|
||||
String description;
|
||||
|
@ -33,7 +29,6 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
DownloadActivityType type;
|
||||
boolean extra;
|
||||
|
||||
private String initializedName;
|
||||
|
||||
public IndexItem(String fileName, String description, long timestamp, String size, long contentSize,
|
||||
long containerSize, DownloadActivityType tp) {
|
||||
|
@ -75,13 +70,16 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
return contentSize;
|
||||
}
|
||||
|
||||
public double getContentSizeMB() {
|
||||
return ((double)contentSize) / (1 << 20);
|
||||
}
|
||||
|
||||
public String getSizeDescription(Context ctx) {
|
||||
return size + " MB";
|
||||
}
|
||||
|
||||
|
||||
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type,
|
||||
List<DownloadEntry> downloadEntries) {
|
||||
public DownloadEntry createDownloadEntry(OsmandApplication ctx) {
|
||||
String fileName = this.fileName;
|
||||
File parent = type.getDownloadFolder(ctx, this);
|
||||
boolean preventMediaIndexing = type.preventMediaIndexing(ctx, this);
|
||||
|
@ -97,11 +95,12 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
}
|
||||
}
|
||||
}
|
||||
final DownloadEntry entry;
|
||||
DownloadEntry entry;
|
||||
if (parent == null || !parent.exists()) {
|
||||
ctx.showToastMessage(R.string.sd_dir_not_accessible);
|
||||
entry = null;
|
||||
} else {
|
||||
entry = new DownloadEntry(this);
|
||||
entry = new DownloadEntry();
|
||||
entry.type = type;
|
||||
entry.baseName = getBasename();
|
||||
entry.urlToDownload = entry.type.getBaseUrl(ctx, fileName) + entry.type.getUrlSuffix(ctx);
|
||||
|
@ -109,15 +108,26 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
entry.unzipFolder = type.isZipFolder(ctx, this);
|
||||
entry.dateModified = timestamp;
|
||||
entry.sizeMB = contentSize / (1024f*1024f);
|
||||
String extension = type.getUnzipExtension(ctx, this);
|
||||
entry.targetFile = new File(parent, entry.baseName + extension);
|
||||
File backup = new File(ctx.getAppPath(IndexConstants.BACKUP_INDEX_DIR), entry.targetFile.getName());
|
||||
if (backup.exists()) {
|
||||
entry.existingBackupFile = backup;
|
||||
entry.targetFile = getTargetFile(ctx);
|
||||
}
|
||||
downloadEntries.add(entry);
|
||||
return entry;
|
||||
}
|
||||
return downloadEntries;
|
||||
|
||||
public String getTargetFileName() {
|
||||
return type.getTargetFileName(this);
|
||||
}
|
||||
|
||||
public String getBasename() {
|
||||
return type.getBasename(this);
|
||||
}
|
||||
|
||||
private File getTargetFile(OsmandApplication ctx) {
|
||||
return new File(type.getDownloadFolder(ctx, this), getBasename() + type.getUnzipExtension(ctx, this));
|
||||
}
|
||||
|
||||
public File getBackupFile(OsmandApplication ctx) {
|
||||
File backup = new File(ctx.getAppPath(IndexConstants.BACKUP_INDEX_DIR), getTargetFile(ctx).getName());
|
||||
return backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,9 +142,7 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
return listAlreadyDownloaded.containsKey(getTargetFileName());
|
||||
}
|
||||
|
||||
public String getBasename() {
|
||||
return type.getBasename(this);
|
||||
}
|
||||
|
||||
|
||||
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {
|
||||
return type.getVisibleName(this, ctx, osmandRegions, true);
|
||||
|
@ -148,22 +156,12 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
return type.getVisibleDescription(this, clctx);
|
||||
}
|
||||
|
||||
public String getTargetFileName() {
|
||||
return type.getTargetFileName(this);
|
||||
}
|
||||
|
||||
|
||||
public String getDate(java.text.DateFormat format) {
|
||||
return format.format(new Date(timestamp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return initializedName + " must be fixed";
|
||||
}
|
||||
|
||||
public void setName(String initializedName) {
|
||||
this.initializedName = initializedName;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
|
@ -180,45 +178,45 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
// '}';
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(this.description);
|
||||
dest.writeString(this.fileName);
|
||||
dest.writeString(this.size);
|
||||
dest.writeLong(this.timestamp);
|
||||
dest.writeLong(this.contentSize);
|
||||
dest.writeLong(this.containerSize);
|
||||
dest.writeParcelable(this.type, flags);
|
||||
dest.writeByte(extra ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.initializedName);
|
||||
dest.writeString(this.simplifiedFileName);
|
||||
}
|
||||
|
||||
protected IndexItem(Parcel in) {
|
||||
this.description = in.readString();
|
||||
this.fileName = in.readString();
|
||||
this.size = in.readString();
|
||||
this.timestamp = in.readLong();
|
||||
this.contentSize = in.readLong();
|
||||
this.containerSize = in.readLong();
|
||||
this.type = in.readParcelable(DownloadActivityType.class.getClassLoader());
|
||||
this.extra = in.readByte() != 0;
|
||||
this.initializedName = in.readString();
|
||||
this.simplifiedFileName = in.readString();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<IndexItem> CREATOR = new Parcelable.Creator<IndexItem>() {
|
||||
public IndexItem createFromParcel(Parcel source) {
|
||||
return new IndexItem(source);
|
||||
}
|
||||
|
||||
public IndexItem[] newArray(int size) {
|
||||
return new IndexItem[size];
|
||||
}
|
||||
};
|
||||
// @Override
|
||||
// public int describeContents() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void writeToParcel(Parcel dest, int flags) {
|
||||
// dest.writeString(this.description);
|
||||
// dest.writeString(this.fileName);
|
||||
// dest.writeString(this.size);
|
||||
// dest.writeLong(this.timestamp);
|
||||
// dest.writeLong(this.contentSize);
|
||||
// dest.writeLong(this.containerSize);
|
||||
// dest.writeParcelable(this.type, flags);
|
||||
// dest.writeByte(extra ? (byte) 1 : (byte) 0);
|
||||
// dest.writeString(this.initializedName);
|
||||
// dest.writeString(this.simplifiedFileName);
|
||||
// }
|
||||
//
|
||||
// protected IndexItem(Parcel in) {
|
||||
// this.description = in.readString();
|
||||
// this.fileName = in.readString();
|
||||
// this.size = in.readString();
|
||||
// this.timestamp = in.readLong();
|
||||
// this.contentSize = in.readLong();
|
||||
// this.containerSize = in.readLong();
|
||||
// this.type = in.readParcelable(DownloadActivityType.class.getClassLoader());
|
||||
// this.extra = in.readByte() != 0;
|
||||
// this.initializedName = in.readString();
|
||||
// this.simplifiedFileName = in.readString();
|
||||
// }
|
||||
//
|
||||
// public static final Parcelable.Creator<IndexItem> CREATOR = new Parcelable.Creator<IndexItem>() {
|
||||
// public IndexItem createFromParcel(Parcel source) {
|
||||
// return new IndexItem(source);
|
||||
// }
|
||||
//
|
||||
// public IndexItem[] newArray(int size) {
|
||||
// return new IndexItem[size];
|
||||
// }
|
||||
// };
|
||||
}
|
|
@ -7,7 +7,7 @@ import java.util.Set;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.BaseDownloadActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadEntry;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -21,14 +21,14 @@ import android.widget.ArrayAdapter;
|
|||
|
||||
public class ActiveDownloadsDialogFragment extends DialogFragment {
|
||||
|
||||
private DownloadEntryAdapter adapter;
|
||||
private IndexItemAdapter adapter;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.downloads).setNegativeButton(R.string.shared_string_dismiss, null);
|
||||
adapter = new DownloadEntryAdapter(getDownloadActivity());
|
||||
adapter = new IndexItemAdapter(getDownloadActivity());
|
||||
builder.setAdapter(adapter, null);
|
||||
getDownloadActivity().setActiveDownloads(this);
|
||||
return builder.create();
|
||||
|
@ -48,7 +48,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
return (DownloadActivity) getActivity();
|
||||
}
|
||||
|
||||
public static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
|
||||
public static class IndexItemAdapter extends ArrayAdapter<IndexItem> {
|
||||
private final Drawable deleteDrawable;
|
||||
private final DownloadActivity context;
|
||||
private int itemInProgressPosition = -1;
|
||||
|
@ -56,8 +56,8 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
private final Set<Integer> downloadedItems = new HashSet<>();
|
||||
private boolean isFinished;
|
||||
|
||||
public DownloadEntryAdapter(DownloadActivity context) {
|
||||
super(context, R.layout.two_line_with_images_list_item, new ArrayList<DownloadEntry>());
|
||||
public IndexItemAdapter(DownloadActivity context) {
|
||||
super(context, R.layout.two_line_with_images_list_item, new ArrayList<IndexItem>());
|
||||
this.context = context;
|
||||
deleteDrawable = context.getMyApplication().getIconsCache()
|
||||
.getPaintedContentIcon(R.drawable.ic_action_remove_dark,
|
||||
|
@ -67,7 +67,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
|
||||
public void updateData() {
|
||||
clear();
|
||||
addAll(BaseDownloadActivity.downloadListIndexThread.flattenDownloadEntries());
|
||||
addAll(BaseDownloadActivity.downloadListIndexThread.getCurrentDownloadingItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,10 +90,10 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
|
||||
private static class DownloadEntryViewHolder extends TwoLineWithImagesViewHolder {
|
||||
private final Drawable deleteDrawable;
|
||||
private final DownloadEntryAdapter adapter;
|
||||
private final IndexItemAdapter adapter;
|
||||
|
||||
private DownloadEntryViewHolder(View convertView, final DownloadActivity context,
|
||||
Drawable deleteDrawable, DownloadEntryAdapter adapter) {
|
||||
Drawable deleteDrawable, IndexItemAdapter adapter) {
|
||||
super(convertView, context);
|
||||
this.deleteDrawable = deleteDrawable;
|
||||
this.adapter = adapter;
|
||||
|
@ -101,9 +101,9 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
rightImageButton.setImageDrawable(deleteDrawable);
|
||||
}
|
||||
|
||||
public void bindDownloadEntry(final DownloadEntry downloadEntry, final int progress,
|
||||
public void bindDownloadEntry(final IndexItem item, final int progress,
|
||||
boolean isDownloaded) {
|
||||
nameTextView.setText(downloadEntry.item.getVisibleName(context,
|
||||
nameTextView.setText(item.getVisibleName(context,
|
||||
context.getMyApplication().getRegions()));
|
||||
rightImageButton.setVisibility(View.VISIBLE);
|
||||
|
||||
|
@ -111,23 +111,23 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
|
|||
boolean isIndeterminate = true;
|
||||
if (progress != -1) {
|
||||
isIndeterminate = false;
|
||||
double downloaded = downloadEntry.sizeMB * progress / 100;
|
||||
double downloaded = item.getContentSizeMB() * progress / 100;
|
||||
descrTextView.setText(context.getString(R.string.value_downloaded_from_max, downloaded,
|
||||
downloadEntry.sizeMB));
|
||||
item.getContentSizeMB()));
|
||||
} else if (isDownloaded) {
|
||||
isIndeterminate = false;
|
||||
localProgress = progressBar.getMax();
|
||||
descrTextView.setText(context.getString(R.string.file_size_in_mb,
|
||||
downloadEntry.sizeMB));
|
||||
item.getContentSizeMB()));
|
||||
rightImageButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
descrTextView.setText(context.getString(R.string.file_size_in_mb,
|
||||
downloadEntry.sizeMB));
|
||||
item.getContentSizeMB()));
|
||||
}
|
||||
rightImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
context.cancelDownload(downloadEntry.item);
|
||||
context.cancelDownload(item);
|
||||
adapter.updateData();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -291,11 +291,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
|
|||
|
||||
public static class ConfirmDownloadUnneededMapDialogFragment extends DialogFragment {
|
||||
private static final String INDEX_ITEM = "index_item";
|
||||
private static IndexItem item = null;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final IndexItem indexItem = getArguments().getParcelable(INDEX_ITEM);
|
||||
final IndexItem indexItem = item;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.are_you_sure);
|
||||
builder.setMessage(R.string.confirm_download_roadmaps);
|
||||
|
@ -304,8 +305,10 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
|
|||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if(indexItem != null) {
|
||||
((DownloadActivity) getActivity()).startDownload(indexItem);
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -314,7 +317,6 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
|
|||
ConfirmDownloadUnneededMapDialogFragment fragment =
|
||||
new ConfirmDownloadUnneededMapDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(INDEX_ITEM, indexItem);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue