update names
This commit is contained in:
parent
5081b70c94
commit
381492698a
12 changed files with 442 additions and 306 deletions
|
@ -38,6 +38,7 @@ public class IndexConstants {
|
|||
public static final String BACKUP_INDEX_DIR= "backup/";
|
||||
public static final String GPX_INDEX_DIR= "tracks/";
|
||||
public static final String TILES_INDEX_DIR= "tiles/";
|
||||
public static final String TOURS_INDEX_DIR= "tours/";
|
||||
public static final String SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$
|
||||
public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$
|
||||
public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
<resources>
|
||||
<string name="settings_file_create_error">Couldn\'t create settings file in tour folder.</string>
|
||||
<string name="tour">Tour</string>
|
||||
<string name="download_tours">Tours</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.Window;
|
||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
|
@ -11,6 +13,7 @@ import net.osmand.plus.activities.PluginsActivity;
|
|||
import net.osmand.plus.activities.SettingsActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.api.SettingsAPI;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
|
||||
public class OsmAndAppCustomization {
|
||||
|
||||
|
@ -73,4 +76,8 @@ public class OsmAndAppCustomization {
|
|||
return LocalIndexesActivity.class;
|
||||
}
|
||||
|
||||
public void getDownloadTypes(List<DownloadActivityType> items) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.io.File;
|
|||
import java.io.FilenameFilter;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -96,6 +95,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final List<DownloadActivityType> downloadTypes = getDownloadTypes();
|
||||
type = downloadTypes.get(0);
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
if(downloadListIndexThread == null) {
|
||||
downloadListIndexThread = new DownloadIndexesThread(this);
|
||||
|
@ -153,9 +154,13 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
if (intent != null && intent.getExtras() != null) {
|
||||
final String filter = intent.getExtras().getString(FILTER_KEY);
|
||||
if (filter != null) {
|
||||
if(filter.equals(getString(R.string.voice))) {
|
||||
changeType(DownloadActivityType.VOICE_FILE);
|
||||
} else {
|
||||
filterText.setText(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<IndexItem> list = new ArrayList<IndexItem>();
|
||||
downloadListIndexThread.setUiActivity(this);
|
||||
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
|
||||
|
@ -176,16 +181,16 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
} else {
|
||||
showDialogOfFreeDownloadsIfNeeded();
|
||||
}
|
||||
final DownloadActivityType[] downloadTypes = getDownloadTypes();
|
||||
|
||||
spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item,
|
||||
new ArrayList<String>(Arrays.asList(toString(downloadTypes)))
|
||||
toString(downloadTypes)
|
||||
);
|
||||
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
|
||||
getSupportActionBar().setListNavigationCallbacks(spinnerAdapter, new OnNavigationListener() {
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
|
||||
changeType(downloadTypes[itemPosition]);
|
||||
changeType(downloadTypes.get(itemPosition));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -409,46 +414,34 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
|
||||
public void selectDownloadType() {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
final DownloadActivityType[] items = getDownloadTypes();
|
||||
bld.setItems(toString(items), new DialogInterface.OnClickListener() {
|
||||
final List<DownloadActivityType> items = getDownloadTypes();
|
||||
bld.setItems(toString(items).toArray(new String[items.size()]), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
changeType(items[which]);
|
||||
changeType(items.get(which));
|
||||
}
|
||||
});
|
||||
bld.show();
|
||||
}
|
||||
|
||||
private String[] toString(DownloadActivityType[] t) {
|
||||
String[] items = new String[t.length];
|
||||
for (int i = 0; i < t.length; i++) {
|
||||
if (t[i] == DownloadActivityType.NORMAL_FILE) {
|
||||
items[i] = getString(R.string.download_regular_maps);
|
||||
} else if (t[i] == DownloadActivityType.ROADS_FILE) {
|
||||
items[i] = getString(R.string.download_roads_only_maps);
|
||||
} else if ( t[i] == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
items[i] = getString(R.string.download_srtm_maps);
|
||||
} else if (t[i] == DownloadActivityType.HILLSHADE_FILE) {
|
||||
items[i] = getString(R.string.download_hillshade_maps);
|
||||
}
|
||||
private List<String> toString(List<DownloadActivityType> t) {
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for(DownloadActivityType ts : t) {
|
||||
items.add(ts.getString(getMyApplication()));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private DownloadActivityType[] getDownloadTypes() {
|
||||
DownloadActivityType[] items;
|
||||
private List<DownloadActivityType> getDownloadTypes() {
|
||||
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
|
||||
items.add(DownloadActivityType.NORMAL_FILE);
|
||||
items.add(DownloadActivityType.VOICE_FILE);
|
||||
items.add(DownloadActivityType.ROADS_FILE);
|
||||
if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){
|
||||
items = new DownloadActivityType[]{
|
||||
DownloadActivityType.NORMAL_FILE,
|
||||
DownloadActivityType.ROADS_FILE,
|
||||
DownloadActivityType.HILLSHADE_FILE,
|
||||
DownloadActivityType.SRTM_COUNTRY_FILE};
|
||||
} else {
|
||||
items = new DownloadActivityType[]{
|
||||
DownloadActivityType.NORMAL_FILE,
|
||||
DownloadActivityType.ROADS_FILE,
|
||||
};
|
||||
items.add(DownloadActivityType.HILLSHADE_FILE);
|
||||
items.add(DownloadActivityType.SRTM_COUNTRY_FILE);
|
||||
}
|
||||
getMyApplication().getAppCustomization().getDownloadTypes(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
|
@ -543,7 +536,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
|
||||
wiki = true;
|
||||
break;
|
||||
} else if (DownloadActivityType.isCountedInDownloads(es)) {
|
||||
} else if (DownloadActivityType.isCountedInDownloads(es.getType())) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,304 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
public enum DownloadActivityType {
|
||||
NORMAL_FILE, ROADS_FILE, /*SRTM_FILE, */HILLSHADE_FILE, SRTM_COUNTRY_FILE;
|
||||
import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
import static net.osmand.IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
|
||||
|
||||
public static boolean isCountedInDownloads(IndexItem es) {
|
||||
DownloadActivityType tp = es.getType();
|
||||
if(tp == HILLSHADE_FILE || tp == SRTM_COUNTRY_FILE || es.isVoiceItem()){
|
||||
return false;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
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 android.content.Context;
|
||||
|
||||
public class DownloadActivityType {
|
||||
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
private static Map<String, DownloadActivityType> byTag = new HashMap<String, DownloadActivityType>();
|
||||
|
||||
public static final DownloadActivityType NORMAL_FILE = new DownloadActivityType(R.string.download_regular_maps, "map");
|
||||
public static final DownloadActivityType VOICE_FILE = new DownloadActivityType(R.string.voice, "voice");
|
||||
public static final DownloadActivityType ROADS_FILE = new DownloadActivityType(R.string.download_roads_only_maps, "road_map");
|
||||
public static final DownloadActivityType HILLSHADE_FILE = new DownloadActivityType(R.string.download_srtm_maps, "srtm_map");
|
||||
public static final DownloadActivityType SRTM_COUNTRY_FILE = new DownloadActivityType(R.string.download_hillshade_maps, "hillshade");
|
||||
private int resource;
|
||||
private String[] tags;
|
||||
|
||||
public DownloadActivityType(int resource, String... tags) {
|
||||
this.resource = resource;
|
||||
this.tags = tags;
|
||||
for(String st : tags) {
|
||||
byTag.put(st, this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isCountedInDownloads(DownloadActivityType tp) {
|
||||
if(tp == HILLSHADE_FILE || tp == SRTM_COUNTRY_FILE){
|
||||
if(tp == NORMAL_FILE || tp == ROADS_FILE){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getString(Context c) {
|
||||
return c.getString(resource);
|
||||
}
|
||||
|
||||
public static DownloadActivityType getIndexType(String tagName) {
|
||||
return byTag.get(tagName);
|
||||
}
|
||||
|
||||
protected static String addVersionToExt(String ext, int version) {
|
||||
return "_" + version + ext;
|
||||
}
|
||||
|
||||
public boolean isAccepted(String fileName) {
|
||||
if (ROADS_FILE == this || NORMAL_FILE == this) {
|
||||
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP,
|
||||
IndexConstants.BINARY_MAP_VERSION))
|
||||
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)
|
||||
|| fileName.endsWith(IndexConstants.SQLITE_EXT);
|
||||
} else if (VOICE_FILE == this) {
|
||||
return fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION));
|
||||
} else if (SRTM_COUNTRY_FILE == this) {
|
||||
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP,
|
||||
IndexConstants.BINARY_MAP_VERSION));
|
||||
} else if (HILLSHADE_FILE == this) {
|
||||
return fileName.endsWith(IndexConstants.SQLITE_EXT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public File getDownloadFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
if (ROADS_FILE == this || NORMAL_FILE == this) {
|
||||
if(indexItem.fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
}
|
||||
return ctx.getAppPath(IndexConstants.MAPS_PATH);
|
||||
} else if (VOICE_FILE == this) {
|
||||
return ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
} else if (SRTM_COUNTRY_FILE == this) {
|
||||
return ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR);
|
||||
} else if (HILLSHADE_FILE == this) {
|
||||
return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return this == VOICE_FILE;
|
||||
}
|
||||
|
||||
public boolean preventMediaIndexing(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return this == VOICE_FILE && indexItem.fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP);
|
||||
}
|
||||
|
||||
public String getUnzipExtension(OsmandApplication ctx, IndexItem indexItem) {
|
||||
if (NORMAL_FILE == this) {
|
||||
if (indexItem.fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
return BINARY_MAP_INDEX_EXT;
|
||||
} else if (indexItem.fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
return BINARY_MAP_INDEX_EXT;
|
||||
} else if (indexItem.fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
|
||||
return IndexConstants.EXTRA_EXT;
|
||||
} else if (indexItem.fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
return IndexConstants.SQLITE_EXT;
|
||||
}
|
||||
} else if (ROADS_FILE == this) {
|
||||
return "-roads" + BINARY_MAP_INDEX_EXT;
|
||||
} else if (VOICE_FILE == this) {
|
||||
return "";
|
||||
} else if (SRTM_COUNTRY_FILE == this) {
|
||||
return BINARY_SRTM_MAP_INDEX_EXT;
|
||||
} else if (HILLSHADE_FILE == this) {
|
||||
return IndexConstants.SQLITE_EXT;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getUrlSuffix(OsmandApplication ctx) {
|
||||
if (this== DownloadActivityType.ROADS_FILE) {
|
||||
return "&road=yes";
|
||||
} else if (this == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
return "&srtmcountry=yes";
|
||||
}else if (this== DownloadActivityType.HILLSHADE_FILE) {
|
||||
return "&hillshade=yes";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getBaseUrl(OsmandApplication ctx, String fileName) {
|
||||
return "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&"
|
||||
+ Version.getVersionAsURLParam(ctx) + "&file=" + fileName;
|
||||
}
|
||||
|
||||
|
||||
public IndexItem parseIndexItem(Context ctx, XmlPullParser parser) {
|
||||
String name = parser.getAttributeValue(null, "name"); //$NON-NLS-1$
|
||||
if(!isAccepted(name)) {
|
||||
return null;
|
||||
}
|
||||
String size = parser.getAttributeValue(null, "size"); //$NON-NLS-1$
|
||||
String date = parser.getAttributeValue(null, "date"); //$NON-NLS-1$
|
||||
String description = parser.getAttributeValue(null, "description"); //$NON-NLS-1$
|
||||
String parts = parser.getAttributeValue(null, "parts"); //$NON-NLS-1$
|
||||
date = reparseDate(ctx, date);
|
||||
IndexItem it = new IndexItem(name, description, date, size, parts, this);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
protected static String reparseDate(Context ctx, String date) {
|
||||
try {
|
||||
Date d = simpleDateFormat.parse(date);
|
||||
return AndroidUtils.formatDate(ctx, d.getTime());
|
||||
} catch (ParseException e) {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
public String getVisibleDescription(IndexItem indexItem, Context ctx) {
|
||||
if (this == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
return ctx.getString(R.string.download_srtm_maps);
|
||||
} else if (this == DownloadActivityType.ROADS_FILE) {
|
||||
return ctx.getString(R.string.download_roads_only_item);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getVoiceName(Context ctx, String basename) {
|
||||
try {
|
||||
String nm = basename.replace('-', '_').replace(' ', '_');
|
||||
if (nm.endsWith("_tts")) {
|
||||
nm = nm.substring(0, nm.length() - 4);
|
||||
}
|
||||
Field f = R.string.class.getField("lang_"+nm);
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return ctx.getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return basename;
|
||||
}
|
||||
|
||||
public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
|
||||
String fileName = indexItem.fileName;
|
||||
if (this == VOICE_FILE) {
|
||||
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.voice) + "\n" + getVoiceName(ctx, getBasename(indexItem));
|
||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.ttsvoice) + "\n" + getVoiceName(ctx, getBasename(indexItem));
|
||||
}
|
||||
return getBasename(indexItem);
|
||||
}
|
||||
final String bn = getBasename(indexItem);
|
||||
final String lc = bn.toLowerCase();
|
||||
String std = getStandardMapName(ctx, lc);
|
||||
if (std != null) {
|
||||
return std;
|
||||
}
|
||||
if (bn.contains("addresses-nationwide")) {
|
||||
final int ind = bn.indexOf("addresses-nationwide");
|
||||
String downloadName = bn.substring(0, ind - 1) + bn.substring(ind + "addresses-nationwide".length());
|
||||
return osmandRegions.getLocaleName(downloadName) +
|
||||
" "+ ctx.getString(R.string.index_item_nation_addresses);
|
||||
}
|
||||
|
||||
return osmandRegions.getLocaleName(lc);
|
||||
}
|
||||
|
||||
private String getStandardMapName(Context ctx, String basename) {
|
||||
if(basename.equals("world-ski")) {
|
||||
return ctx.getString(R.string.index_item_world_ski);
|
||||
} else if(basename.equals("world_altitude_correction_ww15mgh")) {
|
||||
return ctx.getString(R.string.index_item_world_altitude_correction);
|
||||
} else if(basename.equals("world_basemap")) {
|
||||
return ctx.getString(R.string.index_item_world_basemap);
|
||||
} else if(basename.equals("world_bitcoin_payments")) {
|
||||
return ctx.getString(R.string.index_item_world_bitcoin_payments);
|
||||
} else if(basename.equals("world_seamarks")) {
|
||||
return ctx.getString(R.string.index_item_world_seamarks);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getTargetFileName(IndexItem item) {
|
||||
String fileName = item.fileName;
|
||||
// if(fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP) ||
|
||||
// fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
if (this == VOICE_FILE) {
|
||||
int l = fileName.lastIndexOf('_');
|
||||
if (l == -1) {
|
||||
l = fileName.length();
|
||||
}
|
||||
String s = fileName.substring(0, l);
|
||||
return s;
|
||||
} else if (this == HILLSHADE_FILE) {
|
||||
return fileName.replace('_', ' ');
|
||||
} else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)
|
||||
|| fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
int l = fileName.lastIndexOf('_');
|
||||
if (l == -1) {
|
||||
l = fileName.length();
|
||||
}
|
||||
String baseNameWithoutVersion = fileName.substring(0, l);
|
||||
if (this == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
return baseNameWithoutVersion + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
|
||||
}
|
||||
if (this == DownloadActivityType.ROADS_FILE) {
|
||||
baseNameWithoutVersion += "-roads";
|
||||
}
|
||||
baseNameWithoutVersion += IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
return baseNameWithoutVersion;
|
||||
} else if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
return fileName.replace('_', ' ');
|
||||
} else if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
|
||||
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length())
|
||||
+ IndexConstants.EXTRA_EXT;
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
public String getBasename(IndexItem indexItem) {
|
||||
String fileName = indexItem.fileName;
|
||||
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
|
||||
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
|
||||
}
|
||||
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' ');
|
||||
}
|
||||
if (this == VOICE_FILE) {
|
||||
int l = fileName.lastIndexOf('_');
|
||||
if (l == -1) {
|
||||
l = fileName.length();
|
||||
}
|
||||
String s = fileName.substring(0, l);
|
||||
return s;
|
||||
}
|
||||
int ls = fileName.lastIndexOf('_');
|
||||
if (ls >= 0) {
|
||||
return fileName.substring(0, ls);
|
||||
} else if(fileName.indexOf('.') > 0){
|
||||
return fileName.substring(0, fileName.indexOf('.'));
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
|
||||
public class DownloadEntry {
|
||||
public Long dateModified;
|
||||
|
@ -21,7 +22,6 @@ public class DownloadEntry {
|
|||
public String assetName;
|
||||
public DownloadActivityType type;
|
||||
|
||||
public List<String> srtmFilesToDownload;
|
||||
public DownloadEntry attachedEntry;
|
||||
public IndexItem item;
|
||||
|
||||
|
@ -37,4 +37,5 @@ public class DownloadEntry {
|
|||
isAsset = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -229,7 +229,7 @@ public class DownloadIndexesThread {
|
|||
boolean result = downloadFile(entry, filesToReindex, forceWifi);
|
||||
success = result || success;
|
||||
if (result) {
|
||||
if (DownloadActivityType.isCountedInDownloads(entry.item)) {
|
||||
if (DownloadActivityType.isCountedInDownloads(entry.item.getType())) {
|
||||
downloads.set(downloads.get() + 1);
|
||||
}
|
||||
if (entry.existingBackupFile != null) {
|
||||
|
@ -264,7 +264,7 @@ public class DownloadIndexesThread {
|
|||
|
||||
private boolean exceedsFreelimit(DownloadEntry entry) {
|
||||
return Version.isFreeVersion(app) &&
|
||||
DownloadActivityType.isCountedInDownloads(entry.item) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||
DownloadActivityType.isCountedInDownloads(entry.item.getType()) && downloads.get() >= DownloadIndexActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||
}
|
||||
|
||||
private String reindexFiles(List<File> filesToReindex) {
|
||||
|
@ -586,7 +586,7 @@ public class DownloadIndexesThread {
|
|||
Collection<List<DownloadEntry>> vs = getEntriesToDownload().values();
|
||||
for (List<DownloadEntry> v : vs) {
|
||||
for(DownloadEntry e : v) {
|
||||
if(DownloadActivityType.isCountedInDownloads(e.item)) {
|
||||
if(DownloadActivityType.isCountedInDownloads(e.item.getType())) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
@ -33,7 +32,6 @@ import android.text.format.DateFormat;
|
|||
|
||||
public class DownloadOsmandIndexesHelper {
|
||||
private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class);
|
||||
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
|
||||
public static IndexFileList getIndexesList(Context ctx) {
|
||||
|
@ -71,8 +69,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm,
|
||||
OsmandSettings settings) {
|
||||
try {
|
||||
String ext = IndexItem.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION);
|
||||
String extvoice = IndexItem.addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION);
|
||||
String ext = DownloadActivityType.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION);
|
||||
String extvoice = DownloadActivityType.addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION);
|
||||
File voicePath = settings.getContext().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
// list = amanager.list("voice");
|
||||
String date = "";
|
||||
|
@ -90,7 +88,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
if (target.endsWith("-tts/_ttsconfig.p") && target.startsWith("voice/")) {
|
||||
String voice = target.substring("voice/".length(), target.length() - "/_ttsconfig.p".length());
|
||||
File destFile = new File(voicePath, voice + File.separatorChar + "_ttsconfig.p");
|
||||
result.add(new AssetIndexItem(voice +ext, "voice", date, dateModified, "0.1", "", key, destFile.getPath()));
|
||||
result.add(new AssetIndexItem(voice +ext, "voice", date, dateModified, "0.1", "", key, destFile.getPath(),
|
||||
DownloadActivityType.VOICE_FILE));
|
||||
} else if (target.endsWith("/_config.p") && target.startsWith("voice/")) {
|
||||
String voice = target.substring("voice/".length(), target.length() - "/_config.p".length());
|
||||
IndexItem item = result.getIndexFilesByName(key);
|
||||
|
@ -105,7 +104,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
log.error("Parse exception", es);
|
||||
}
|
||||
item.date = date;
|
||||
item.attachedItem = new AssetIndexItem(voice +extvoice, "voice", date, dateModified, "0.1", "", key, destFile.getPath());
|
||||
item.attachedItem = new AssetIndexItem(voice +extvoice, "voice", date, dateModified, "0.1", "", key, destFile.getPath(),
|
||||
DownloadActivityType.VOICE_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,19 +117,6 @@ public class DownloadOsmandIndexesHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static DownloadActivityType getIndexType(String tagName){
|
||||
if("region".equals(tagName) ||
|
||||
"multiregion".equals(tagName)) {
|
||||
return DownloadActivityType.NORMAL_FILE;
|
||||
} else if("road_region".equals(tagName) ) {
|
||||
return DownloadActivityType.ROADS_FILE;
|
||||
} else if("srtmcountry".equals(tagName) ) {
|
||||
return DownloadActivityType.SRTM_COUNTRY_FILE;
|
||||
} else if("hillshade".equals(tagName) ) {
|
||||
return DownloadActivityType.HILLSHADE_FILE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IndexFileList downloadIndexesListFromInternet(Context ctx, String versionAsUrl){
|
||||
try {
|
||||
|
@ -144,17 +131,13 @@ public class DownloadOsmandIndexesHelper {
|
|||
int next;
|
||||
while((next = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if (next == XmlPullParser.START_TAG) {
|
||||
DownloadActivityType tp = getIndexType(parser.getName());
|
||||
DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type"));
|
||||
if (tp != null) {
|
||||
String name = parser.getAttributeValue(null, "name"); //$NON-NLS-1$
|
||||
String size = parser.getAttributeValue(null, "size"); //$NON-NLS-1$
|
||||
String date = parser.getAttributeValue(null, "date"); //$NON-NLS-1$
|
||||
String description = parser.getAttributeValue(null, "description"); //$NON-NLS-1$
|
||||
String parts = parser.getAttributeValue(null, "parts"); //$NON-NLS-1$
|
||||
date = reparseDate(ctx, date);
|
||||
IndexItem it = new IndexItem(name, description, date, size, parts);
|
||||
it.setType(tp);
|
||||
|
||||
IndexItem it = tp.parseIndexItem(ctx, parser);
|
||||
if(it != null) {
|
||||
result.add(it);
|
||||
}
|
||||
} else if ("osmand_regions".equals(parser.getName())) {
|
||||
String mapversion = parser.getAttributeValue(null, "mapversion");
|
||||
result.setMapVersion(mapversion);
|
||||
|
@ -181,15 +164,6 @@ public class DownloadOsmandIndexesHelper {
|
|||
}
|
||||
}
|
||||
|
||||
protected static String reparseDate(Context ctx, String date) {
|
||||
try {
|
||||
Date d = simpleDateFormat.parse(date);
|
||||
return AndroidUtils.formatDate(ctx, d.getTime());
|
||||
} catch (ParseException e) {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AssetIndexItem extends IndexItem {
|
||||
|
||||
private final String assetName;
|
||||
|
@ -197,8 +171,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
private final long dateModified;
|
||||
|
||||
public AssetIndexItem(String fileName, String description, String date,
|
||||
long dateModified, String size, String parts, String assetName, String destFile) {
|
||||
super(fileName, description, date, size, parts);
|
||||
long dateModified, String size, String parts, String assetName, String destFile, DownloadActivityType type) {
|
||||
super(fileName, description, date, size, parts, type);
|
||||
this.dateModified = dateModified;
|
||||
this.assetName = assetName;
|
||||
this.destFile = destFile;
|
||||
|
@ -208,11 +182,6 @@ public class DownloadOsmandIndexesHelper {
|
|||
return dateModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccepted(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type, List<DownloadEntry> res) {
|
||||
res.add(new DownloadEntry(this, assetName, destFile, dateModified));
|
||||
|
|
|
@ -47,9 +47,7 @@ public class IndexFileList implements Serializable {
|
|||
}
|
||||
|
||||
public void add(IndexItem indexItem) {
|
||||
if (indexItem.isAccepted()) {
|
||||
indexFiles.add(indexItem);
|
||||
}
|
||||
if(indexItem.getFileName().toLowerCase().startsWith("world_basemap")) {
|
||||
basemap = indexItem;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
package net.osmand.plus.download;
|
||||
|
||||
import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
import static net.osmand.IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -18,7 +14,6 @@ import net.osmand.PlatformUtil;
|
|||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -36,133 +31,19 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
IndexItem attachedItem;
|
||||
DownloadActivityType type;
|
||||
|
||||
public IndexItem(String fileName, String description, String date, String size, String parts) {
|
||||
public IndexItem(String fileName, String description, String date, String size, String parts, DownloadActivityType tp) {
|
||||
this.fileName = fileName;
|
||||
this.description = description;
|
||||
this.date = date;
|
||||
this.size = size;
|
||||
this.parts = parts;
|
||||
this.type = DownloadActivityType.NORMAL_FILE;
|
||||
this.type = tp;
|
||||
}
|
||||
|
||||
public DownloadActivityType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(DownloadActivityType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getVisibleDescription(Context ctx) {
|
||||
String s = ""; //$NON-NLS-1$
|
||||
if (type == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
return ctx.getString(R.string.download_srtm_maps);
|
||||
} else if (type == DownloadActivityType.ROADS_FILE) {
|
||||
return ctx.getString(R.string.download_roads_only_item);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String getVoiceName(Context ctx) {
|
||||
try {
|
||||
String nm = getBasename().replace('-', '_').replace(' ', '_');
|
||||
if (nm.endsWith("_tts")) {
|
||||
nm = nm.substring(0, nm.length() - 4);
|
||||
}
|
||||
Field f = R.string.class.getField("lang_"+nm);
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return ctx.getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return getBasename();
|
||||
}
|
||||
|
||||
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {
|
||||
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.voice) + "\n" + getVoiceName(ctx);
|
||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.ttsvoice) + "\n" + getVoiceName(ctx);
|
||||
}
|
||||
final String bn = getBasename();
|
||||
final String lc = bn.toLowerCase();
|
||||
String std = getStandardMapName(ctx, lc);
|
||||
if (std != null) {
|
||||
return std;
|
||||
}
|
||||
if (bn.contains("addresses-nationwide")) {
|
||||
final int ind = bn.indexOf("addresses-nationwide");
|
||||
String downloadName = bn.substring(0, ind - 1) + bn.substring(ind + "addresses-nationwide".length());
|
||||
return osmandRegions.getLocaleName(downloadName) +
|
||||
" "+ ctx.getString(R.string.index_item_nation_addresses);
|
||||
}
|
||||
|
||||
return osmandRegions.getLocaleName(lc);
|
||||
}
|
||||
|
||||
private String getStandardMapName(Context ctx, String basename) {
|
||||
if(basename.equals("world-ski")) {
|
||||
return ctx.getString(R.string.index_item_world_ski);
|
||||
} else if(basename.equals("world_altitude_correction_ww15mgh")) {
|
||||
return ctx.getString(R.string.index_item_world_altitude_correction);
|
||||
} else if(basename.equals("world_basemap")) {
|
||||
return ctx.getString(R.string.index_item_world_basemap);
|
||||
} else if(basename.equals("world_bitcoin_payments")) {
|
||||
return ctx.getString(R.string.index_item_world_bitcoin_payments);
|
||||
} else if(basename.equals("world_seamarks")) {
|
||||
return ctx.getString(R.string.index_item_world_seamarks);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isVoiceItem() {
|
||||
return fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP) || fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP);
|
||||
}
|
||||
|
||||
public String getBasename() {
|
||||
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
|
||||
return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length());
|
||||
}
|
||||
if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP)) {
|
||||
String simple = fileName.substring(0, fileName.length() - IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP.length());
|
||||
int ls = simple.lastIndexOf('_');
|
||||
if (ls >= 0) {
|
||||
return simple.substring(0, ls);
|
||||
}
|
||||
return simple;
|
||||
}
|
||||
if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' ');
|
||||
}
|
||||
int ls = fileName.lastIndexOf('_');
|
||||
if (ls >= 0) {
|
||||
return fileName.substring(0, ls);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public boolean isAccepted() {
|
||||
// POI index download is not supported any longer
|
||||
if (fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_MAP_VERSION)) //
|
||||
|| fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) //
|
||||
|| fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) //
|
||||
|| fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION))
|
||||
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)
|
||||
|| fileName.endsWith(IndexConstants.SQLITE_EXT)
|
||||
// || fileName.endsWith(addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION)) drop support for
|
||||
// downloading tts files from inet
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static String addVersionToExt(String ext, int version) {
|
||||
return "_" + version + ext;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
@ -186,47 +67,8 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type,
|
||||
List<DownloadEntry> downloadEntries) {
|
||||
String fileName = this.fileName;
|
||||
File parent = null;
|
||||
String extension = null;
|
||||
boolean unzipDir = false;
|
||||
boolean zipStream = false;
|
||||
boolean preventMediaIndexing = false;
|
||||
if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR);
|
||||
extension = BINARY_SRTM_MAP_INDEX_EXT;
|
||||
zipStream = true;
|
||||
} else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
parent = ctx.getAppPath(IndexConstants.MAPS_PATH);
|
||||
extension = BINARY_MAP_INDEX_EXT;
|
||||
} else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getAppPath(IndexConstants.MAPS_PATH);
|
||||
zipStream = true;
|
||||
extension = BINARY_MAP_INDEX_EXT;
|
||||
} else if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
|
||||
parent = ctx.getAppPath("");
|
||||
// unzipDir = true;
|
||||
zipStream = true;
|
||||
extension = IndexConstants.EXTRA_EXT;
|
||||
} else if (fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
parent = ctx.getAppPath(IndexConstants.TILES_INDEX_DIR);
|
||||
extension = IndexConstants.SQLITE_EXT;
|
||||
} else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
zipStream = true;
|
||||
extension = ""; //$NON-NLS-1$
|
||||
unzipDir = true;
|
||||
preventMediaIndexing = true;
|
||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
parent = ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||
zipStream = true;
|
||||
extension = ""; //$NON-NLS-1$
|
||||
unzipDir = true;
|
||||
}
|
||||
if (type == DownloadActivityType.ROADS_FILE) {
|
||||
extension = "-roads" + extension;
|
||||
} else if (type == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
// extension = "-srtm" + extension;
|
||||
}
|
||||
File parent = type.getDownloadFolder(ctx, this);
|
||||
boolean preventMediaIndexing = type.preventMediaIndexing(ctx, this);
|
||||
if (parent != null) {
|
||||
parent.mkdirs();
|
||||
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery and Music apps
|
||||
|
@ -246,20 +88,9 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
entry = new DownloadEntry(this);
|
||||
entry.type = type;
|
||||
entry.baseName = getBasename();
|
||||
String url = "http://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&";
|
||||
url += Version.getVersionAsURLParam(ctx) + "&";
|
||||
if (type == DownloadActivityType.ROADS_FILE) {
|
||||
url += "road=yes&";
|
||||
}
|
||||
if (type == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
url += "srtmcountry=yes&";
|
||||
}
|
||||
if (type == DownloadActivityType.HILLSHADE_FILE) {
|
||||
url += "hillshade=yes&";
|
||||
}
|
||||
entry.urlToDownload = url + "file=" + fileName;
|
||||
entry.zipStream = zipStream;
|
||||
entry.unzipFolder = unzipDir;
|
||||
entry.urlToDownload = entry.type.getBaseUrl(ctx, fileName) + entry.type.getUrlSuffix(ctx);
|
||||
entry.zipStream = type.isZipStream(ctx, this);
|
||||
entry.unzipFolder = type.isZipFolder(ctx, this);
|
||||
try {
|
||||
final java.text.DateFormat format = DateFormat.getDateFormat((Context) ctx);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
|
||||
|
@ -277,6 +108,7 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
if (parts != null) {
|
||||
entry.parts = Integer.parseInt(parts);
|
||||
}
|
||||
String extension = type.getUnzipExtension(ctx, this);
|
||||
entry.targetFile = new File(parent, entry.baseName + extension);
|
||||
File backup = new File(ctx.getAppPath(IndexConstants.BACKUP_INDEX_DIR), entry.targetFile.getName());
|
||||
if (backup.exists()) {
|
||||
|
@ -294,39 +126,6 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
return downloadEntries;
|
||||
}
|
||||
|
||||
public String getTargetFileName(){
|
||||
String e = getFileName();
|
||||
|
||||
if (e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || e.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
|
||||
int l = e.lastIndexOf('_');
|
||||
if(l == -1) {
|
||||
l = e.length();
|
||||
}
|
||||
String s = e.substring(0, l);
|
||||
if (getType() == DownloadActivityType.ROADS_FILE) {
|
||||
s += "-roads" ;
|
||||
}
|
||||
if (getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
return s + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
|
||||
}
|
||||
s += IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
return s;
|
||||
} else if(e.endsWith(IndexConstants.SQLITE_EXT)){
|
||||
return e.replace('_', ' ');
|
||||
} else if(e.endsWith(IndexConstants.EXTRA_ZIP_EXT)){
|
||||
return e.substring(0, e.length() - IndexConstants.EXTRA_ZIP_EXT.length()) + IndexConstants.EXTRA_EXT;
|
||||
} else if(e.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP) || e.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
int l = e.lastIndexOf('_');
|
||||
if(l == -1) {
|
||||
l = e.length();
|
||||
}
|
||||
String s = e.substring(0, l);
|
||||
return s;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IndexItem another) {
|
||||
if(another == null) {
|
||||
|
@ -339,4 +138,20 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
return listAlreadyDownloaded.containsKey(getTargetFileName());
|
||||
}
|
||||
|
||||
public String getBasename() {
|
||||
return type.getBasename(this);
|
||||
}
|
||||
|
||||
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {
|
||||
return type.getVisibleName(this, ctx, osmandRegions);
|
||||
}
|
||||
|
||||
public String getVisibleDescription(OsmandApplication clctx) {
|
||||
return type.getVisibleDescription(this, clctx);
|
||||
}
|
||||
|
||||
public String getTargetFileName() {
|
||||
return type.getTargetFileName(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.sherpafy;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -10,6 +11,7 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MainMenuActivity;
|
||||
import net.osmand.plus.api.FileSettingsAPIImpl;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
@ -85,4 +87,10 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
|
|||
private Class<?> getTourSelectionActivity() {
|
||||
return MainMenuActivity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDownloadTypes(List<DownloadActivityType> items) {
|
||||
super.getDownloadTypes(items);
|
||||
items.add(0, TourDownloadType.TOUR);
|
||||
}
|
||||
}
|
||||
|
|
61
OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java
Normal file
61
OsmAnd/src/net/osmand/plus/sherpafy/TourDownloadType.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import android.content.Context;
|
||||
|
||||
public class TourDownloadType extends DownloadActivityType {
|
||||
|
||||
public static final TourDownloadType TOUR = new TourDownloadType(R.string.download_tours, "tour");
|
||||
|
||||
public TourDownloadType(int resource, String... tags) {
|
||||
super(resource, tags);
|
||||
}
|
||||
|
||||
public boolean isAccepted(String fileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public File getDownloadFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return ctx.getAppPath(IndexConstants.TOURS_INDEX_DIR);
|
||||
}
|
||||
|
||||
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean preventMediaIndexing(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getUnzipExtension(OsmandApplication ctx, IndexItem indexItem) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getUrlSuffix(OsmandApplication ctx) {
|
||||
return "&tour=yes";
|
||||
}
|
||||
|
||||
public String getVisibleDescription(IndexItem indexItem, Context ctx) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
|
||||
return getBasename(indexItem) + "\n" + indexItem.getDescription();
|
||||
}
|
||||
|
||||
public String getTargetFileName(IndexItem item) {
|
||||
return item.getBasename();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue