Add gpx download type

This commit is contained in:
Vitaliy 2020-04-14 23:49:09 +03:00
parent 44a4b93df1
commit ac60edda8d
4 changed files with 58 additions and 10 deletions

View file

@ -46,6 +46,8 @@ public class IndexConstants {
public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$
public static final String GPX_FILE_EXT = ".gpx"; //$NON-NLS-1$
public final static String POI_TABLE = "poi"; //$NON-NLS-1$
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";

View file

@ -23,6 +23,7 @@ import net.osmand.plus.ApplicationMode.ApplicationModeBean;
import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
import net.osmand.plus.CustomOsmandPlugin.SuggestedDownloadItem;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.download.CustomIndexItem;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.IndexItem;
@ -52,6 +53,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -731,7 +733,10 @@ public class SettingsHelper {
String scopeId = object.optString("scope-id", null);
String path = object.optString("path", null);
String type = object.optString("type", null);
String folder = object.optString("folder", null);
String subfolder = null;
if ("gpx".equals(type)) {
subfolder = object.optString("subfolder", null);
}
CustomRegion region = new CustomRegion(scopeId, path, type);
@ -797,17 +802,20 @@ public class SettingsHelper {
names.put(localeKey, name);
}
}
String fileName = indexItemJson.optString("filename");
String description = indexItemJson.optString("description");
long timestamp = indexItemJson.optLong("timestamp") * 1000;
String size = indexItemJson.optString("contentSize");
long contentSize = indexItemJson.optLong("contentSize");
long containerSize = indexItemJson.optLong("containerSize");
String indexType = indexItemJson.optString("type", null);
String fileName = indexItemJson.optString("filename");
String description = indexItemJson.optString("description");
String downloadurl = indexItemJson.optString("downloadurl");
String size = new DecimalFormat("#.#").format(containerSize / (1024f * 1024f));
String indexType = indexItemJson.optString("type", type);
@NonNull DownloadActivityType tp = DownloadActivityType.getIndexType(indexType);
if (tp != null) {
IndexItem indexItem = new IndexItem(fileName, description, timestamp, size, contentSize, containerSize, tp);
IndexItem indexItem = new CustomIndexItem(fileName, description, downloadurl, timestamp, size, contentSize, containerSize, tp);
region.downloadItems.add(indexItem);
}
}

View file

@ -0,0 +1,25 @@
package net.osmand.plus.download;
import net.osmand.plus.OsmandApplication;
public class CustomIndexItem extends IndexItem {
private final String downloadurl;
public CustomIndexItem(String fileName, String description, String downloadurl,
long dateModified, String size, long contentSize,
long containerSize, DownloadActivityType type) {
super(fileName, description, dateModified, size, contentSize, containerSize, type);
this.downloadurl = downloadurl;
}
@Override
public DownloadEntry createDownloadEntry(OsmandApplication ctx) {
DownloadEntry entry = super.createDownloadEntry(ctx);
if (entry != null) {
entry.urlToDownload = downloadurl;
}
return entry;
}
}

View file

@ -51,6 +51,9 @@ public class DownloadActivityType {
new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "wikivoyage", 65);
public static final DownloadActivityType LIVE_UPDATES_FILE =
new DownloadActivityType(R.string.download_live_updates, "live_updates", 70);
public static final DownloadActivityType GPX_FILE =
new DownloadActivityType(R.string.shared_string_gpx_tracks, R.drawable.ic_action_polygom_dark, "gpx", 75);
private final int stringResource;
private final int iconResource;
@ -136,6 +139,8 @@ public class DownloadActivityType {
return fileName.endsWith(IndexConstants.SQLITE_EXT);
} else if (DEPTH_CONTOUR_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION));
} else if (GPX_FILE == this) {
return fileName.endsWith(IndexConstants.GPX_FILE_EXT);
}
return false;
}
@ -166,12 +171,14 @@ public class DownloadActivityType {
return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
} else if (DEPTH_CONTOUR_FILE == this) {
return ctx.getAppPath(IndexConstants.MAPS_PATH);
} else if (GPX_FILE == this) {
return ctx.getAppPath(IndexConstants.GPX_INDEX_DIR);
}
throw new UnsupportedOperationException();
}
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
return HILLSHADE_FILE != this && SLOPE_FILE != this && WIKIVOYAGE_FILE != this;
return HILLSHADE_FILE != this && SLOPE_FILE != this && WIKIVOYAGE_FILE != this && GPX_FILE != this;
}
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
@ -215,6 +222,8 @@ public class DownloadActivityType {
return IndexConstants.SQLITE_EXT;
} else if (DEPTH_CONTOUR_FILE == this) {
return BINARY_MAP_INDEX_EXT;
} else if (GPX_FILE == this) {
return IndexConstants.GPX_FILE_EXT;
}
throw new UnsupportedOperationException();
}
@ -238,6 +247,8 @@ public class DownloadActivityType {
return "&fonts=yes";
} else if (this == DEPTH_CONTOUR_FILE) {
return "&inapp=depth";
} else if (this == GPX_FILE) {
return "&gpx=yes";
}
return "";
}
@ -303,6 +314,8 @@ public class DownloadActivityType {
return ctx.getString(R.string.download_depth_countours);
} else if (this == FONT_FILE) {
return ctx.getString(R.string.fonts_header);
} else if (this == GPX_FILE) {
return ctx.getString(R.string.shared_string_gpx_tracks);
}
return "";
}