Download dialog
This commit is contained in:
parent
a83dadf7c2
commit
ee65717d7b
6 changed files with 61 additions and 31 deletions
|
@ -89,7 +89,6 @@ public class WorldRegion {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processNewMapState(MapState mapState) {
|
public void processNewMapState(MapState mapState) {
|
||||||
LOG.debug("old state=" + this.mapState);
|
|
||||||
switch (this.mapState) {
|
switch (this.mapState) {
|
||||||
case NOT_DOWNLOADED:
|
case NOT_DOWNLOADED:
|
||||||
this.mapState = mapState;
|
this.mapState = mapState;
|
||||||
|
@ -101,7 +100,6 @@ public class WorldRegion {
|
||||||
case OUTDATED:
|
case OUTDATED:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LOG.debug("new state=" + this.mapState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,6 +16,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
||||||
protected String message = ""; //$NON-NLS-1$
|
protected String message = ""; //$NON-NLS-1$
|
||||||
protected Context ctx;
|
protected Context ctx;
|
||||||
protected boolean interrupted = false;
|
protected boolean interrupted = false;
|
||||||
|
protected Object tag;
|
||||||
private Handler uiHandler;
|
private Handler uiHandler;
|
||||||
|
|
||||||
public BasicProgressAsyncTask(Context ctx) {
|
public BasicProgressAsyncTask(Context ctx) {
|
||||||
|
@ -45,7 +46,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
||||||
updProgress(false);
|
updProgress(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void updateProgress(boolean updateOnlyProgress);
|
protected abstract void updateProgress(boolean updateOnlyProgress, Object tag);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startWork(int work) {
|
public void startWork(int work) {
|
||||||
|
@ -75,7 +76,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
||||||
Message msg = Message.obtain(uiHandler, new Runnable() {
|
Message msg = Message.obtain(uiHandler, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateProgress(updateOnlyProgress);
|
updateProgress(updateOnlyProgress, tag);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
msg.what = OsmAndConstants.UI_HANDLER_PROGRESS + 2;
|
msg.what = OsmAndConstants.UI_HANDLER_PROGRESS + 2;
|
||||||
|
@ -122,4 +123,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
||||||
return interrupted;
|
return interrupted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setTag(Object tag) {
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -79,7 +79,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgress(boolean updateOnlyProgress) {
|
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgress(boolean updateOnlyProgress) {
|
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
||||||
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||||
if (visibleBanner != null) {
|
if (visibleBanner != null) {
|
||||||
|
@ -252,7 +252,7 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
||||||
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||||
}
|
}
|
||||||
if (progressAdapter != null) {
|
if (progressAdapter != null) {
|
||||||
progressAdapter.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
progressAdapter.setProgress(basicProgressAsyncTask, tag);
|
||||||
}
|
}
|
||||||
if (!updateOnlyProgress) {
|
if (!updateOnlyProgress) {
|
||||||
updateDownloadButton();
|
updateDownloadButton();
|
||||||
|
@ -581,12 +581,12 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
||||||
|
|
||||||
public void registerFreeVersionBanner(View view) {
|
public void registerFreeVersionBanner(View view) {
|
||||||
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
|
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
|
||||||
updateProgress(true);
|
updateProgress(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerUpdateListener(ActiveDownloadsDialogFragment.DownloadEntryAdapter adapter) {
|
public void registerUpdateListener(ActiveDownloadsDialogFragment.DownloadEntryAdapter adapter) {
|
||||||
progressAdapter = adapter;
|
progressAdapter = adapter;
|
||||||
updateProgress(true);
|
updateProgress(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||||
|
@ -773,12 +773,18 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
||||||
for (List<DownloadEntry> list : vs) {
|
for (List<DownloadEntry> list : vs) {
|
||||||
downloadEntries.addAll(list);
|
downloadEntries.addAll(list);
|
||||||
}
|
}
|
||||||
builder.setAdapter(new DownloadEntryAdapter(getActivity(), downloadEntries), null);
|
final DownloadEntryAdapter adapter = new DownloadEntryAdapter(getActivity(), downloadEntries);
|
||||||
|
builder.setAdapter(adapter, null);
|
||||||
|
((DownloadActivity) getActivity()).registerUpdateListener(adapter);
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
|
private static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
|
||||||
private final Drawable deleteDrawable;
|
private final Drawable deleteDrawable;
|
||||||
|
private int itemInProgressPosition = -1;
|
||||||
|
private int progress = -1;
|
||||||
|
private final Set<Integer> downloadedItems = new HashSet<>();
|
||||||
|
private boolean isFinished;
|
||||||
|
|
||||||
public DownloadEntryAdapter(Context context, List<DownloadEntry> objects) {
|
public DownloadEntryAdapter(Context context, List<DownloadEntry> objects) {
|
||||||
super(context, R.layout.two_line_with_images_list_item, objects);
|
super(context, R.layout.two_line_with_images_list_item, objects);
|
||||||
|
@ -798,11 +804,32 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
||||||
}
|
}
|
||||||
DownloadEntryViewHolder viewHolder = (DownloadEntryViewHolder) convertView.getTag();
|
DownloadEntryViewHolder viewHolder = (DownloadEntryViewHolder) convertView.getTag();
|
||||||
viewHolder.bindDownloadEntry(getItem(position));
|
viewHolder.bindDownloadEntry(getItem(position));
|
||||||
|
if (position == itemInProgressPosition) {
|
||||||
|
viewHolder.progressBar.setIndeterminate(false);
|
||||||
|
viewHolder.progressBar.setProgress(progress);
|
||||||
|
} else if (isFinished || downloadedItems.contains(position)) {
|
||||||
|
viewHolder.progressBar.setIndeterminate(false);
|
||||||
|
viewHolder.progressBar.setProgress(viewHolder.progressBar.getMax());
|
||||||
|
}
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgress(int percent) {
|
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
|
||||||
// TODO: 10/9/15 implement
|
isFinished = task == null
|
||||||
|
|| task.getStatus() == AsyncTask.Status.FINISHED;
|
||||||
|
itemInProgressPosition = -1;
|
||||||
|
progress = -1;
|
||||||
|
if (isFinished) return;
|
||||||
|
if (tag instanceof DownloadEntry) {
|
||||||
|
progress = task.getProgressPercentage();
|
||||||
|
for (int i = 0; i < getCount(); i++) {
|
||||||
|
if (getItem(i).equals(tag)) {
|
||||||
|
itemInProgressPosition = i;
|
||||||
|
downloadedItems.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
getDownloadActivity().updateProgress(false);
|
getDownloadActivity().updateProgress(false, null);
|
||||||
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||||
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
|
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
|
||||||
View mainView = getView().findViewById(R.id.MainLayout);
|
View mainView = getView().findViewById(R.id.MainLayout);
|
||||||
|
@ -300,7 +300,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
||||||
public View findViewById(int id){ return getView().findViewById(id);}
|
public View findViewById(int id){ return getView().findViewById(id);}
|
||||||
|
|
||||||
public void updateProgress(boolean b) {
|
public void updateProgress(boolean b) {
|
||||||
getDownloadActivity().updateProgress(b);
|
getDownloadActivity().updateProgress(b, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
||||||
|
|
|
@ -61,13 +61,13 @@ public class DownloadIndexesThread {
|
||||||
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
|
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
|
||||||
private final Context ctx;
|
private final Context ctx;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private final static Log log = PlatformUtil.getLog(DownloadIndexesThread.class);
|
private final static Log LOG = PlatformUtil.getLog(DownloadIndexesThread.class);
|
||||||
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 Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
|
private Map<String, String> indexFileNames = new LinkedHashMap<>();
|
||||||
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
|
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<>();
|
||||||
private java.text.DateFormat dateFormat;
|
private java.text.DateFormat dateFormat;
|
||||||
private List<IndexItem> itemsToUpdate = new ArrayList<IndexItem>();
|
private List<IndexItem> itemsToUpdate = new ArrayList<>();
|
||||||
|
|
||||||
private Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = new HashMap<>();
|
private Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = new HashMap<>();
|
||||||
private List<IndexItem> voiceRecItems = new LinkedList<>();
|
private List<IndexItem> voiceRecItems = new LinkedList<>();
|
||||||
|
@ -349,7 +349,7 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
currentRunningTask.remove(this);
|
currentRunningTask.remove(this);
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(false);
|
uiActivity.updateProgress(false, tag);
|
||||||
}
|
}
|
||||||
updateFilesToUpdate();
|
updateFilesToUpdate();
|
||||||
}
|
}
|
||||||
|
@ -401,6 +401,7 @@ public class DownloadIndexesThread {
|
||||||
+ "");
|
+ "");
|
||||||
break downloadCycle;
|
break downloadCycle;
|
||||||
}
|
}
|
||||||
|
setTag(entry);
|
||||||
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
||||||
success = result || success;
|
success = result || success;
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -431,7 +432,7 @@ public class DownloadIndexesThread {
|
||||||
updateLoadedFiles();
|
updateLoadedFiles();
|
||||||
return warn;
|
return warn;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.info("Download Interrupted");
|
LOG.info("Download Interrupted");
|
||||||
// do not dismiss dialog
|
// do not dismiss dialog
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -492,12 +493,12 @@ public class DownloadIndexesThread {
|
||||||
ResourceManager.copyAssets(ctx.getAssets(), de.assetName, de.targetFile);
|
ResourceManager.copyAssets(ctx.getAssets(), de.assetName, de.targetFile);
|
||||||
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
|
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
|
||||||
if (!changedDate) {
|
if (!changedDate) {
|
||||||
log.error("Set last timestamp is not supported");
|
LOG.error("Set last timestamp is not supported");
|
||||||
}
|
}
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Copy exception", e);
|
LOG.error("Copy exception", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res = downloadFileHelper.downloadFile(de, this, filesToReindex, this, forceWifi);
|
res = downloadFileHelper.downloadFile(de, this, filesToReindex, this, forceWifi);
|
||||||
|
@ -506,9 +507,9 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateProgress(boolean updateOnlyProgress) {
|
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(updateOnlyProgress);
|
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -573,7 +574,7 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
currentRunningTask.remove(this);
|
currentRunningTask.remove(this);
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(false);
|
uiActivity.updateProgress(false, tag);
|
||||||
runCategorization(uiActivity.getDownloadType());
|
runCategorization(uiActivity.getDownloadType());
|
||||||
uiActivity.onCategorizationFinished();
|
uiActivity.onCategorizationFinished();
|
||||||
}
|
}
|
||||||
|
@ -603,9 +604,9 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateProgress(boolean updateOnlyProgress) {
|
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(updateOnlyProgress);
|
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -644,7 +645,7 @@ public class DownloadIndexesThread {
|
||||||
currentRunningTask.add(this);
|
currentRunningTask.add(this);
|
||||||
this.message = ctx.getString(R.string.downloading_list_indexes);
|
this.message = ctx.getString(R.string.downloading_list_indexes);
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(false);
|
uiActivity.updateProgress(false, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,14 +677,14 @@ public class DownloadIndexesThread {
|
||||||
currentRunningTask.remove(this);
|
currentRunningTask.remove(this);
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.categorizationFinished(filtered, cats);
|
uiActivity.categorizationFinished(filtered, cats);
|
||||||
uiActivity.updateProgress(false);
|
uiActivity.updateProgress(false, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateProgress(boolean updateOnlyProgress) {
|
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||||
if (uiActivity != null) {
|
if (uiActivity != null) {
|
||||||
uiActivity.updateProgress(updateOnlyProgress);
|
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue