Merge pull request #886 from Bars107/sherpafy

Fixed issue with maps not being downloaded after tour download
This commit is contained in:
vshcherb 2014-09-26 13:50:23 +02:00
commit 1e60522605
4 changed files with 71 additions and 74 deletions

View file

@ -19,6 +19,7 @@ import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.activities.*;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexFragment;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl;
@ -111,7 +112,7 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadIndexFragment downloadActivity;
DownloadActivity downloadActivity;
@Override
public void onCreate() {
@ -879,11 +880,11 @@ public class OsmandApplication extends Application {
this.mapActivity = mapActivity;
}
public void setDownloadActivity(DownloadIndexFragment downloadActivity) {
public void setDownloadActivity(DownloadActivity downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadIndexFragment getDownloadActivity() {
public DownloadActivity getDownloadActivity() {
return downloadActivity;
}
}

View file

@ -30,10 +30,7 @@ import net.osmand.plus.voice.TTSCommandPlayerImpl;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Created by Denis on 08.09.2014.
@ -202,6 +199,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
}
@ -476,4 +474,53 @@ public class DownloadActivity extends SherlockFragmentActivity {
task.execute();
}
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
if ((i.getFileName().equals(map + ".obf.zip") || i.getFileName().equals(map + "_" + IndexConstants.BINARY_MAP_VERSION + ".obf.zip"))
&& i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
for(DownloadEntry d : de ) {
count++;
sz += d.sizeMB;
}
if(s.length() > 0) {
s +=", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getEntriesToDownload().put(i, de);
}
}
}
if(count > 0){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadFilesCheckInternet();
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getEntriesToDownload().clear();
}
});
builder.show();
}
}
}

View file

@ -110,7 +110,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
@Override
public void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
getDownloadActivity().updateProgress(false);
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
@ -121,55 +120,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
}
}
public void showDialogToDownloadMaps(Collection<String> maps) {
int count = 0;
int sz = 0;
String s = "";
for (IndexItem i : DownloadActivity.downloadListIndexThread.getCachedIndexFiles()) {
for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip") && i.getType() == DownloadActivityType.NORMAL_FILE) {
final List<DownloadEntry> de = i.createDownloadEntry(getMyApplication(), i.getType(), new ArrayList<DownloadEntry>(1));
for(DownloadEntry d : de ) {
count++;
sz += d.sizeMB;
}
if(s.length() > 0) {
s +=", ";
}
s += i.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
getDownloadActivity().getEntriesToDownload().put(i, de);
}
}
}
if(count > 0){
Builder builder = new AlertDialog.Builder(getDownloadActivity());
builder.setMessage(getString(R.string.download_additional_maps, s, sz));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getDownloadActivity().downloadFilesCheckInternet();
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
getDownloadActivity().getEntriesToDownload().clear();
}
});
builder.show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) {

View file

@ -229,7 +229,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadIndexFragment da = app.getDownloadActivity();
final DownloadActivity da = app.getDownloadActivity();
if (da != null) {
app.runInUIThread(new Runnable() {
@ -562,7 +562,6 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
if (osmandSettings.SHOW_POI_OVER_MAP.get()) {
adapter.item(R.string.sherpafy_disable_poi).icons(
R.drawable.ic_action_gremove_dark, R.drawable.ic_action_gremove_light)
.position(adapter.length() - 1)
.listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
@ -572,7 +571,6 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}).reg();
} else {
adapter.item(R.string.poi).icons(R.drawable.ic_action_layers_dark, R.drawable.ic_action_layers_light)
.position(adapter.length() - 1)
.listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
@ -582,19 +580,8 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
}).reg();
}
final StageInformation stage = getSelectedStage();
if (stage != null && !isStageVisited(stage.order)) {
adapter.item(R.string.complete_stage)
.icons(R.drawable.ic_action_finish_flag_dark, R.drawable.ic_action_finish_flag_light)
.position(adapter.length() - 1).listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
markStageAsCompleted(stage);
showCompleteStageFragment(mapActivity, stage, false);
}
}).reg();
}
adapter.item(R.string.sherpafy_tour_info_txt).icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).position(adapter.length() - 1)
//important info
adapter.item(R.string.sherpafy_tour_info_txt).icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light)
.listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
@ -603,7 +590,19 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
mapActivity.startActivity(newIntent);
}
}).reg();
//complete stage
final StageInformation stage = getSelectedStage();
if (stage != null && !isStageVisited(stage.order)) {
adapter.item(R.string.complete_stage)
.icons(R.drawable.ic_action_finish_flag_dark, R.drawable.ic_action_finish_flag_light)
.listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
markStageAsCompleted(stage);
showCompleteStageFragment(mapActivity, stage, false);
}
}).reg();
}
//share my location
adapter.item(R.string.context_menu_item_share_location).icons(
R.drawable.ic_action_gshare_dark, R.drawable.ic_action_gshare_light).listen(new OnContextMenuClick() {