Update download activity

This commit is contained in:
Victor Shcherb 2014-08-13 14:13:33 +02:00
parent 801443b003
commit d5798f8d3c
5 changed files with 76 additions and 1 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.DayNightHelper;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
@ -114,6 +115,8 @@ public class OsmandApplication extends Application {
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadIndexActivity downloadActivity;
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();
@ -862,4 +865,12 @@ public class OsmandApplication extends Application {
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
public void setDownloadActivity(DownloadIndexActivity downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadIndexActivity getDownloadActivity() {
return downloadActivity;
}
}

View file

@ -249,6 +249,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
updateProgress(false);
if(t instanceof DownloadIndexesThread.DownloadIndexesAsyncTask) {
@ -258,6 +259,28 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
}
}
@Override
protected void onPause() {
super.onPause();
getMyApplication().setDownloadActivity(null);
}
public void showDialogToDownloadMaps(List<String> maps) {
DownloadIndexAdapter a = (DownloadIndexAdapter) getListAdapter();
boolean e = true;
for (IndexItem i : a.getIndexFiles()) {
for (String map : maps) {
if (i.getFileName().equals(map + ".obf.zip")) {
e = false;
getEntriesToDownload().put(i, i.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>(1)));
}
}
}
if(!e){
downloadFilesCheckInternet();
}
}
private void showDialogOfFreeDownloadsIfNeeded() {

View file

@ -43,6 +43,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> selectedTourPref;
private CommonPreference<String> selectedStagePref;
private CommonPreference<String> visitedStagesPref;
private boolean toursIndexed;
private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
private StageInformation selectedStage = null;
private TourInformation selectedTour = null;
@ -50,6 +51,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private CommonPreference<String> accessCodePref;
private List<FavouritePoint> cachedFavorites = new ArrayList<FavouritePoint>();
private SettingsAPI originalApi;
public static final String TOUR_SERVER = "builder.osmand.net:81";
@Override
public void setup(OsmandApplication app) {
@ -142,6 +144,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
List<String> warns = new ArrayList<String>();
selectedTour = null;
final List<String> suggestToDownloadMap = new ArrayList<String>();
if(toursFolder.exists()) {
File[] availableTours = toursFolder.listFiles();
if(availableTours != null) {
@ -159,6 +162,14 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
} catch (Exception e) {
e.printStackTrace();
}
// check that tour was downloaded
if(toursIndexed) {
for (String map : tourInformation.getMaps()) {
if (!new File(toursFolder.getParentFile(), map + ".obf").exists()) {
suggestToDownloadMap.add(map);
}
}
}
if (selected) {
reloadSelectedTour(progress, tourInformation);
}
@ -168,8 +179,22 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
app.getSettings().setSettingsAPI(originalApi);
}
}
toursIndexed = true;
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadIndexActivity da = app.getDownloadActivity();
if (da != null) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
da.showDialogToDownloadMaps(suggestToDownloadMap);
}
});
}
}
return warns;
}
@ -317,7 +342,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
@Override
public String getIndexesUrl() {
String s = "http://"+"builder.osmand.net"+"/tours.php?gzip&" + Version.getVersionAsURLParam(app);
String s = "http://"+TOUR_SERVER+"/tours.php?gzip&" + Version.getVersionAsURLParam(app);
if(!Algorithms.isEmpty(accessCodePref.get())) {
s += "&code="+accessCodePref.get();
}

View file

@ -6,6 +6,7 @@ import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.util.Algorithms;
@ -43,6 +44,11 @@ public class TourDownloadType extends DownloadActivityType {
return "";
}
public String getBaseUrl(OsmandApplication ctx, String fileName) {
return "http://" + SherpafyCustomization.TOUR_SERVER + "/download?event=2&"
+ Version.getVersionAsURLParam(ctx) + "&file=" + fileName;
}
public String getUrlSuffix(OsmandApplication ctx) {
String accessCode = "";
if (ctx.getAppCustomization() instanceof SherpafyCustomization) {

View file

@ -35,6 +35,7 @@ public class TourInformation {
private String instructions = "";
private File imgFile;
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
private List<String> maps =new ArrayList<String>();
public TourInformation(File f) {
this.folder = f;
@ -49,6 +50,10 @@ public class TourInformation {
return instructions;
}
public List<String> getMaps() {
return maps;
}
private static WeakHashMap<File, Bitmap> androidBitmaps = new WeakHashMap<File, Bitmap>();
private static Bitmap decodeImage(File f) {
if(!androidBitmaps.containsKey(f)) {
@ -98,6 +103,11 @@ public class TourInformation {
String name = getDefAttribute(parser, "name", "");
stage = new StageInformation(this, stageInformation.size());
stage.name = name;
} else if (tag.equals("prerequisite")) {
String map = getDefAttribute(parser, "map", "");
if(!Algorithms.isEmpty(map)) {
maps .add(map);
}
} else if (tag.equals("itinerary") && stage != null){
String img = getDefAttribute(parser, "image", "");
stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0"));