diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index f0c6f9b65d..7469863406 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -25,6 +25,17 @@ public class Algorithms { return s == null || s.length() == 0; } + public static long parseLongSilently(String input, long def) { + if(input != null && input.length() > 0) { + try { + return Long.parseLong(input); + } catch (NumberFormatException e) { + return def; + } + } + return def; + } + public static int findFirstNumberEndIndex(String value) { int i = 0; boolean valid = false; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index e168b27545..ecb1574c6f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -11,14 +11,16 @@ 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 net.osmand.util.Algorithms; + +import org.xmlpull.v1.XmlPullParser; + import android.content.Context; public class DownloadActivityType { @@ -28,8 +30,8 @@ public class 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"); + public static final DownloadActivityType SRTM_COUNTRY_FILE = new DownloadActivityType(R.string.download_srtm_maps, "srtm_map"); + public static final DownloadActivityType HILLSHADE_FILE = new DownloadActivityType(R.string.download_hillshade_maps, "hillshade"); private int resource; private String[] tags; @@ -151,12 +153,14 @@ public class DownloadActivityType { 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); - + long containerSize = Algorithms.parseLongSilently( + parser.getAttributeValue(null, "containerSize"), 0); + long contentSize = Algorithms.parseLongSilently( + parser.getAttributeValue(null, "contentSize"), 0); + long timestamp = Algorithms.parseLongSilently( + parser.getAttributeValue(null, "timestamp"), 0); + IndexItem it = new IndexItem(name, description, timestamp, size, contentSize, containerSize, this); return it; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadEntry.java b/OsmAnd/src/net/osmand/plus/download/DownloadEntry.java index 7b4345de54..a2fa63e7ad 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadEntry.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadEntry.java @@ -2,10 +2,8 @@ package net.osmand.plus.download; import java.io.File; -import net.osmand.IndexConstants; - public class DownloadEntry { - public Long dateModified; + public long dateModified; public double sizeMB; public File targetFile; @@ -16,7 +14,6 @@ public class DownloadEntry { public String baseName; public String urlToDownload; - public int parts; public File existingBackupFile; public boolean isAsset; public String assetName; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java index 241ae42e11..9a499afc47 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java @@ -201,15 +201,8 @@ public class DownloadFileHelper { List toReIndex, DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException { try { final List downloadInputStreams = new ArrayList(); - if (de.parts == 1) { - URL url = new URL(de.urlToDownload); //$NON-NLS-1$ - downloadInputStreams.add(getInputStreamToDownload(url, forceWifi)); - } else { - for (int i = 1; i <= de.parts; i++) { - URL url = new URL(de.urlToDownload + "-" + i); //$NON-NLS-1$ - downloadInputStreams.add(getInputStreamToDownload(url, forceWifi)); - } - } + URL url = new URL(de.urlToDownload); //$NON-NLS-1$ + downloadInputStreams.add(getInputStreamToDownload(url, forceWifi)); de.fileToDownload = de.targetFile; if(!de.unzipFolder) { de.fileToDownload = new File(de.targetFile.getParentFile(), de.targetFile.getName() +".download"); @@ -298,10 +291,7 @@ public class DownloadFileHelper { progress.remaining(remaining / 1024); } out.close(); - - if (de.dateModified != null) { - targetFile.setLastModified(de.dateModified); - } + targetFile.setLastModified(de.dateModified); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java index 007f1423b6..bf28261c74 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java @@ -14,6 +14,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; +import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -36,6 +37,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem private int defaultColor; private int updateColor; private OsmandRegions osmandRegions; + private java.text.DateFormat format; public DownloadIndexAdapter(DownloadIndexActivity downloadActivity, List indexFiles) { this.downloadActivity = downloadActivity; @@ -45,6 +47,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem list.clear(); list.addAll(cats); } + format = DateFormat.getDateFormat(downloadActivity); okColor = downloadActivity.getResources().getColor(R.color.color_ok); TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown)); @@ -239,7 +242,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem OsmandApplication clctx = downloadActivity.getMyApplication(); String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx, osmandRegions); item.setText(eName.trim()); //$NON-NLS-1$ - String d = e.getDate() + "\n" + e.getSizeDescription(clctx); + String d = e.getDate(format) + "\n" + e.getSizeDescription(clctx); description.setText(d.trim()); CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item); @@ -271,14 +274,14 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem } else { item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); } - } else if (e.getDate() != null) { + } else if (e.getDate(format) != null) { String sfName = e.getTargetFileName(); - if (e.getDate().equals(indexActivatedFileNames.get(sfName))) { + if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) { item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " + indexActivatedFileNames.get(sfName)); item.setTextColor(okColor); // GREEN item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); - } else if (e.getDate().equals(indexFileNames.get(sfName))) { + } else if (e.getDate(format).equals(indexFileNames.get(sfName))) { item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : " + indexFileNames.get(sfName)); item.setTextColor(okColor); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 7ffc6dbb9b..c018bf73e3 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -43,6 +43,7 @@ import android.os.AsyncTask; import android.os.AsyncTask.Status; import android.os.Build; import android.os.StatFs; +import android.text.format.DateFormat; import android.view.View; import android.widget.Toast; @@ -58,11 +59,14 @@ public class DownloadIndexesThread { private List > currentRunningTask = Collections.synchronizedList(new ArrayList>()); private Map indexFileNames = new LinkedHashMap(); private Map indexActivatedFileNames = new LinkedHashMap(); + private java.text.DateFormat dateFormat; + public DownloadIndexesThread(Context ctx) { this.ctx = ctx; app = (OsmandApplication) ctx.getApplicationContext(); downloadFileHelper = new DownloadFileHelper(app); + dateFormat = DateFormat.getDateFormat(app); } public void setUiActivity(DownloadIndexActivity uiActivity) { @@ -369,7 +373,7 @@ public class DownloadIndexesThread { IndexItem basemap = indexFiles.getBasemap(); if (basemap != null ) { String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName()); - if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate())) { + if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) { List downloadEntry = basemap .createDownloadEntry(uiActivity.getMyApplication(), uiActivity.getType(), new ArrayList()); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 3652bc7a0c..ad6ebdc4c8 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -88,23 +88,19 @@ 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(), - DownloadActivityType.VOICE_FILE)); + result.add(new AssetIndexItem(voice +ext, "voice", date, dateModified, + "0.1", 1024*100, 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); if (item != null) { File destFile = new File(voicePath, voice + File.separatorChar + "_config.p"); - try { - Date d = DateFormat.getDateFormat((Context) settings.getContext()).parse(item.getDate()); - if (d.getTime() > dateModified) { - continue; - } - } catch (Exception es) { - log.error("Parse exception", es); - } - item.date = date; - item.attachedItem = new AssetIndexItem(voice +extvoice, "voice", date, dateModified, "0.1", "", key, destFile.getPath(), + // always use bundled config +// if (item.getTimestamp() > dateModified) { +// continue; +// } + item.timestamp = dateModified; + item.attachedItem = new AssetIndexItem(voice +extvoice, "voice", date, dateModified, "0.1", 1024*100, key, destFile.getPath(), DownloadActivityType.VOICE_FILE); } } @@ -133,7 +129,6 @@ public class DownloadOsmandIndexesHelper { if (next == XmlPullParser.START_TAG) { DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type")); if (tp != null) { - IndexItem it = tp.parseIndexItem(ctx, parser); if(it != null) { result.add(it); @@ -171,8 +166,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, DownloadActivityType type) { - super(fileName, description, date, size, parts, type); + long dateModified, String size, long sizeL, String assetName, String destFile, DownloadActivityType type) { + super(fileName, description, dateModified, size, sizeL, sizeL, type); this.dateModified = dateModified; this.assetName = assetName; this.destFile = destFile; diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index 87d858d08a..a03820929e 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -2,12 +2,10 @@ package net.osmand.plus.download; import java.io.File; import java.io.IOException; -import java.text.ParseException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.TimeZone; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -24,19 +22,23 @@ public class IndexItem implements Comparable { private static final Log log = PlatformUtil.getLog(IndexItem.class); String description; - String date; - String parts; String fileName; String size; + long timestamp; + long contentSize; + long containerSize; IndexItem attachedItem; DownloadActivityType type; - public IndexItem(String fileName, String description, String date, String size, String parts, DownloadActivityType tp) { + + public IndexItem(String fileName, String description, long timestamp, String size, long contentSize, + long containerSize, DownloadActivityType tp) { this.fileName = fileName; this.description = description; - this.date = date; + this.timestamp = timestamp; this.size = size; - this.parts = parts; + this.contentSize = contentSize; + this.containerSize = containerSize; this.type = tp; } @@ -52,17 +54,15 @@ public class IndexItem implements Comparable { return description; } - public String getDate() { - return date; + public long getTimestamp() { + return timestamp; } + public String getSizeDescription(Context ctx) { return size + " MB"; } - - public String getSize() { - return size; - } + public List createDownloadEntry(OsmandApplication ctx, DownloadActivityType type, List downloadEntries) { @@ -91,23 +91,8 @@ public class IndexItem implements Comparable { 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")); - Date d = format.parse(date); - entry.dateModified = d.getTime(); - } catch (ParseException e1) { - log.error("ParseException", e1); - } - try { - entry.sizeMB = Double.parseDouble(size); - } catch (NumberFormatException e1) { - log.error("ParseException", e1); - } - entry.parts = 1; - if (parts != null) { - entry.parts = Integer.parseInt(parts); - } + entry.dateModified = timestamp; + entry.sizeMB = contentSize / (1024f*1024f); 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()); @@ -154,4 +139,8 @@ public class IndexItem implements Comparable { return type.getTargetFileName(this); } + public String getDate(java.text.DateFormat format) { + return format.format(new Date(timestamp)); + } + } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 3732fcba2c..d8fa86cbda 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -437,7 +437,6 @@ public class ResourceManager { List warnings = new ArrayList(); if (file.exists() && file.canRead()) { final java.text.DateFormat format = DateFormat.getDateFormat(context); - format.setTimeZone(TimeZone.getTimeZone("GMT+01:00")); File[] lf = file.listFiles(); if (lf != null) { for (File f : lf) { @@ -616,7 +615,6 @@ public class ResourceManager { } } final java.text.DateFormat format = DateFormat.getDateFormat(context); - format.setTimeZone(TimeZone.getTimeZone("GMT+01:00")); for (File f : files) { progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$ try {