Add gpx download type
This commit is contained in:
parent
44a4b93df1
commit
ac60edda8d
4 changed files with 58 additions and 10 deletions
|
@ -46,6 +46,8 @@ public class IndexConstants {
|
||||||
|
|
||||||
public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$
|
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 final static String POI_TABLE = "poi"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
|
public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net";
|
||||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.plus.ApplicationMode.ApplicationModeBean;
|
||||||
import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
|
import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
|
||||||
import net.osmand.plus.CustomOsmandPlugin.SuggestedDownloadItem;
|
import net.osmand.plus.CustomOsmandPlugin.SuggestedDownloadItem;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
|
import net.osmand.plus.download.CustomIndexItem;
|
||||||
import net.osmand.plus.download.DownloadActivityType;
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.DownloadResourceGroup;
|
import net.osmand.plus.download.DownloadResourceGroup;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
@ -52,6 +53,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -731,7 +733,10 @@ public class SettingsHelper {
|
||||||
String scopeId = object.optString("scope-id", null);
|
String scopeId = object.optString("scope-id", null);
|
||||||
String path = object.optString("path", null);
|
String path = object.optString("path", null);
|
||||||
String type = object.optString("type", 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);
|
CustomRegion region = new CustomRegion(scopeId, path, type);
|
||||||
|
|
||||||
|
@ -797,17 +802,20 @@ public class SettingsHelper {
|
||||||
names.put(localeKey, name);
|
names.put(localeKey, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String fileName = indexItemJson.optString("filename");
|
|
||||||
String description = indexItemJson.optString("description");
|
|
||||||
long timestamp = indexItemJson.optLong("timestamp") * 1000;
|
long timestamp = indexItemJson.optLong("timestamp") * 1000;
|
||||||
String size = indexItemJson.optString("contentSize");
|
|
||||||
long contentSize = indexItemJson.optLong("contentSize");
|
long contentSize = indexItemJson.optLong("contentSize");
|
||||||
long containerSize = indexItemJson.optLong("containerSize");
|
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);
|
@NonNull DownloadActivityType tp = DownloadActivityType.getIndexType(indexType);
|
||||||
if (tp != null) {
|
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);
|
region.downloadItems.add(indexItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
OsmAnd/src/net/osmand/plus/download/CustomIndexItem.java
Normal file
25
OsmAnd/src/net/osmand/plus/download/CustomIndexItem.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,9 @@ public class DownloadActivityType {
|
||||||
new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "wikivoyage", 65);
|
new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "wikivoyage", 65);
|
||||||
public static final DownloadActivityType LIVE_UPDATES_FILE =
|
public static final DownloadActivityType LIVE_UPDATES_FILE =
|
||||||
new DownloadActivityType(R.string.download_live_updates, "live_updates", 70);
|
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 stringResource;
|
||||||
private final int iconResource;
|
private final int iconResource;
|
||||||
|
|
||||||
|
@ -136,6 +139,8 @@ public class DownloadActivityType {
|
||||||
return fileName.endsWith(IndexConstants.SQLITE_EXT);
|
return fileName.endsWith(IndexConstants.SQLITE_EXT);
|
||||||
} else if (DEPTH_CONTOUR_FILE == this) {
|
} else if (DEPTH_CONTOUR_FILE == this) {
|
||||||
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -166,12 +171,14 @@ public class DownloadActivityType {
|
||||||
return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||||
} else if (DEPTH_CONTOUR_FILE == this) {
|
} else if (DEPTH_CONTOUR_FILE == this) {
|
||||||
return ctx.getAppPath(IndexConstants.MAPS_PATH);
|
return ctx.getAppPath(IndexConstants.MAPS_PATH);
|
||||||
|
} else if (GPX_FILE == this) {
|
||||||
|
return ctx.getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
|
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) {
|
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||||
|
@ -215,6 +222,8 @@ public class DownloadActivityType {
|
||||||
return IndexConstants.SQLITE_EXT;
|
return IndexConstants.SQLITE_EXT;
|
||||||
} else if (DEPTH_CONTOUR_FILE == this) {
|
} else if (DEPTH_CONTOUR_FILE == this) {
|
||||||
return BINARY_MAP_INDEX_EXT;
|
return BINARY_MAP_INDEX_EXT;
|
||||||
|
} else if (GPX_FILE == this) {
|
||||||
|
return IndexConstants.GPX_FILE_EXT;
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -238,6 +247,8 @@ public class DownloadActivityType {
|
||||||
return "&fonts=yes";
|
return "&fonts=yes";
|
||||||
} else if (this == DEPTH_CONTOUR_FILE) {
|
} else if (this == DEPTH_CONTOUR_FILE) {
|
||||||
return "&inapp=depth";
|
return "&inapp=depth";
|
||||||
|
} else if (this == GPX_FILE) {
|
||||||
|
return "&gpx=yes";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -303,6 +314,8 @@ public class DownloadActivityType {
|
||||||
return ctx.getString(R.string.download_depth_countours);
|
return ctx.getString(R.string.download_depth_countours);
|
||||||
} else if (this == FONT_FILE) {
|
} else if (this == FONT_FILE) {
|
||||||
return ctx.getString(R.string.fonts_header);
|
return ctx.getString(R.string.fonts_header);
|
||||||
|
} else if (this == GPX_FILE) {
|
||||||
|
return ctx.getString(R.string.shared_string_gpx_tracks);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue