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