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) {
|
||||
LOG.debug("old state=" + this.mapState);
|
||||
switch (this.mapState) {
|
||||
case NOT_DOWNLOADED:
|
||||
this.mapState = mapState;
|
||||
|
@ -101,7 +100,6 @@ public class WorldRegion {
|
|||
case OUTDATED:
|
||||
break;
|
||||
}
|
||||
LOG.debug("new state=" + this.mapState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
|||
protected String message = ""; //$NON-NLS-1$
|
||||
protected Context ctx;
|
||||
protected boolean interrupted = false;
|
||||
protected Object tag;
|
||||
private Handler uiHandler;
|
||||
|
||||
public BasicProgressAsyncTask(Context ctx) {
|
||||
|
@ -45,7 +46,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
|||
updProgress(false);
|
||||
}
|
||||
|
||||
protected abstract void updateProgress(boolean updateOnlyProgress);
|
||||
protected abstract void updateProgress(boolean updateOnlyProgress, Object tag);
|
||||
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateProgress(updateOnlyProgress);
|
||||
updateProgress(updateOnlyProgress, tag);
|
||||
}
|
||||
});
|
||||
msg.what = OsmAndConstants.UI_HANDLER_PROGRESS + 2;
|
||||
|
@ -122,4 +123,7 @@ public abstract class BasicProgressAsyncTask<Params, Progress, Result> extends A
|
|||
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
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask =
|
||||
DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (visibleBanner != null) {
|
||||
|
@ -252,7 +252,7 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
|||
visibleBanner.updateProgress(countedDownloads, basicProgressAsyncTask);
|
||||
}
|
||||
if (progressAdapter != null) {
|
||||
progressAdapter.setProgress(basicProgressAsyncTask.getProgressPercentage());
|
||||
progressAdapter.setProgress(basicProgressAsyncTask, tag);
|
||||
}
|
||||
if (!updateOnlyProgress) {
|
||||
updateDownloadButton();
|
||||
|
@ -581,12 +581,12 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
|||
|
||||
public void registerFreeVersionBanner(View view) {
|
||||
visibleBanner = new BannerAndDownloadFreeVersion(view, this);
|
||||
updateProgress(true);
|
||||
updateProgress(true, null);
|
||||
}
|
||||
|
||||
public void registerUpdateListener(ActiveDownloadsDialogFragment.DownloadEntryAdapter adapter) {
|
||||
progressAdapter = adapter;
|
||||
updateProgress(true);
|
||||
updateProgress(true, null);
|
||||
}
|
||||
|
||||
public void showDialog(FragmentActivity activity, DialogFragment fragment) {
|
||||
|
@ -773,12 +773,18 @@ public class DownloadActivity extends BaseDownloadActivity implements RegionDial
|
|||
for (List<DownloadEntry> list : vs) {
|
||||
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();
|
||||
}
|
||||
|
||||
private static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
|
||||
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) {
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
public void setProgress(int percent) {
|
||||
// TODO: 10/9/15 implement
|
||||
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
|
||||
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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getDownloadActivity().updateProgress(false);
|
||||
getDownloadActivity().updateProgress(false, null);
|
||||
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
|
||||
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 void updateProgress(boolean b) {
|
||||
getDownloadActivity().updateProgress(b);
|
||||
getDownloadActivity().updateProgress(b, null);
|
||||
}
|
||||
|
||||
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
||||
|
|
|
@ -61,13 +61,13 @@ public class DownloadIndexesThread {
|
|||
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
|
||||
private final Context ctx;
|
||||
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 List<BasicProgressAsyncTask<?, ?, ?>> currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
|
||||
private Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
|
||||
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
|
||||
private Map<String, String> indexFileNames = new LinkedHashMap<>();
|
||||
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<>();
|
||||
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 List<IndexItem> voiceRecItems = new LinkedList<>();
|
||||
|
@ -349,7 +349,7 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
uiActivity.updateProgress(false, tag);
|
||||
}
|
||||
updateFilesToUpdate();
|
||||
}
|
||||
|
@ -401,6 +401,7 @@ public class DownloadIndexesThread {
|
|||
+ "");
|
||||
break downloadCycle;
|
||||
}
|
||||
setTag(entry);
|
||||
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
||||
success = result || success;
|
||||
if (result) {
|
||||
|
@ -431,7 +432,7 @@ public class DownloadIndexesThread {
|
|||
updateLoadedFiles();
|
||||
return warn;
|
||||
} catch (InterruptedException e) {
|
||||
log.info("Download Interrupted");
|
||||
LOG.info("Download Interrupted");
|
||||
// do not dismiss dialog
|
||||
}
|
||||
return null;
|
||||
|
@ -492,12 +493,12 @@ public class DownloadIndexesThread {
|
|||
ResourceManager.copyAssets(ctx.getAssets(), de.assetName, de.targetFile);
|
||||
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
|
||||
if (!changedDate) {
|
||||
log.error("Set last timestamp is not supported");
|
||||
LOG.error("Set last timestamp is not supported");
|
||||
}
|
||||
res = true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Copy exception", e);
|
||||
LOG.error("Copy exception", e);
|
||||
}
|
||||
} else {
|
||||
res = downloadFileHelper.downloadFile(de, this, filesToReindex, this, forceWifi);
|
||||
|
@ -506,9 +507,9 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -573,7 +574,7 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
uiActivity.updateProgress(false, tag);
|
||||
runCategorization(uiActivity.getDownloadType());
|
||||
uiActivity.onCategorizationFinished();
|
||||
}
|
||||
|
@ -603,9 +604,9 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -644,7 +645,7 @@ public class DownloadIndexesThread {
|
|||
currentRunningTask.add(this);
|
||||
this.message = ctx.getString(R.string.downloading_list_indexes);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(false);
|
||||
uiActivity.updateProgress(false, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -676,14 +677,14 @@ public class DownloadIndexesThread {
|
|||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.categorizationFinished(filtered, cats);
|
||||
uiActivity.updateProgress(false);
|
||||
uiActivity.updateProgress(false, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateProgress(boolean updateOnlyProgress) {
|
||||
protected void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateProgress(updateOnlyProgress);
|
||||
uiActivity.updateProgress(updateOnlyProgress, tag);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue