Remove IO error interrupted. Created download queue for dashboard.

This commit is contained in:
Bars107 2014-12-09 15:25:47 +02:00
parent f6d752cfd9
commit 654d3889b9
4 changed files with 20 additions and 12 deletions

View file

@ -443,6 +443,10 @@ public class MainMenuActivity extends BaseDownloadActivity {
Fragment f = ref.get();
if(f instanceof DashUpdatesFragment) {
if(!f.isDetached()) {
if (downloadQueue.size() > 0){
startDownload(downloadQueue.get(0));
downloadQueue.remove(0);
}
((DashUpdatesFragment) f).updatedDownloadsList(list);
}
}

View file

@ -28,6 +28,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
private List<ProgressBar> progressBars = new ArrayList<ProgressBar>();
private List<String> baseNames = new ArrayList<String>();
private List<ImageButton> downloadButtons = new ArrayList<ImageButton>();
private List<IndexItem> downloadQueue = new ArrayList<IndexItem>();
private ImageButton cancelButton;
@Override
@ -53,6 +54,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
@Override
public void onResume() {
super.onResume();
downloadQueue.clear();
if (BaseDownloadActivity.downloadListIndexThread != null) {
currentProgress = null;
cancelButton = null;
@ -100,8 +102,6 @@ public class DashUpdatesFragment extends DashBaseFragment {
@Override
public void onClick(View view) {
getDownloadActivity().startDownload(item);
currentProgress = progressBar;
cancelButton = (ImageButton) view;
}
});
downloadButtons.add((ImageButton) downloadButton);
@ -121,7 +121,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
return;
}
//needed when rotation is performed and progress can be null
if (currentProgress == null) {
if (!updateOnlyProgress) {
getProgressIfPossible(basicProgressAsyncTask.getDescription());
if (currentProgress == null) {
return;
@ -137,11 +137,6 @@ public class DashUpdatesFragment extends DashBaseFragment {
if (!visible) {
return;
}
for(ImageButton button : downloadButtons){
if (!button.equals(cancelButton)){
button.setImageResource(R.drawable.ic_download_disabled);
}
}
cancelButton.setImageResource(R.drawable.cancel_button);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -41,6 +41,7 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
protected OsmandSettings settings;
public static DownloadIndexesThread downloadListIndexThread;
protected List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
protected List<IndexItem> downloadQueue = new ArrayList<IndexItem>();
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@ -113,13 +114,18 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
}
public void startDownload(IndexItem item) {
if (downloadListIndexThread.getCurrentRunningTask() != null) {
Toast.makeText(this, "Please wait before previous download is finished", Toast.LENGTH_SHORT).show();
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
downloadQueue.add(item);
Toast.makeText(this, "Added to download queue", Toast.LENGTH_SHORT).show();
return;
}
addToDownload(item);
downloadFilesCheckFreeVersion();
}
private void addToDownload(IndexItem item) {
List<DownloadEntry> download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList<DownloadEntry>());
getEntriesToDownload().put(item, download);
downloadFilesCheckFreeVersion();
}
public void downloadFilesPreCheckSpace() {

View file

@ -163,7 +163,10 @@ public class DownloadIndexesThread {
uiActivity.updateDownloadButton(false);
}
} else if (o instanceof String) {
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
String message = (String) o;
if(!message.equals("I/O error occurred : Interrupted")){
AccessibleToast.makeText(ctx, message, Toast.LENGTH_LONG).show();
}
}
}
super.onProgressUpdate(values);