Use timestamp instead of date
This commit is contained in:
parent
381492698a
commit
740c829fab
9 changed files with 69 additions and 78 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -201,15 +201,8 @@ public class DownloadFileHelper {
|
|||
List<File> toReIndex, DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
||||
try {
|
||||
final List<InputStream> downloadInputStreams = new ArrayList<InputStream>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
de.fileToDownload = de.targetFile;
|
||||
if(!de.unzipFolder) {
|
||||
de.fileToDownload = new File(de.targetFile.getParentFile(), de.targetFile.getName() +".download");
|
||||
|
@ -298,11 +291,8 @@ public class DownloadFileHelper {
|
|||
progress.remaining(remaining / 1024);
|
||||
}
|
||||
out.close();
|
||||
|
||||
if (de.dateModified != null) {
|
||||
targetFile.setLastModified(de.dateModified);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setInterruptDownloading(boolean interruptDownloading) {
|
||||
|
|
|
@ -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<IndexItem> 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);
|
||||
|
|
|
@ -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<BasicProgressAsyncTask<?, ?, ?> > currentRunningTask = Collections.synchronizedList(new ArrayList<BasicProgressAsyncTask<?, ?, ?>>());
|
||||
private Map<String, String> indexFileNames = new LinkedHashMap<String, String>();
|
||||
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<String, String>();
|
||||
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> downloadEntry = basemap
|
||||
.createDownloadEntry(uiActivity.getMyApplication(), uiActivity.getType(),
|
||||
new ArrayList<DownloadEntry>());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<IndexItem> {
|
|||
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<IndexItem> {
|
|||
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<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type,
|
||||
List<DownloadEntry> downloadEntries) {
|
||||
|
@ -91,23 +91,8 @@ public class IndexItem implements Comparable<IndexItem> {
|
|||
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<IndexItem> {
|
|||
return type.getTargetFileName(this);
|
||||
}
|
||||
|
||||
public String getDate(java.text.DateFormat format) {
|
||||
return format.format(new Date(timestamp));
|
||||
}
|
||||
|
||||
}
|
|
@ -437,7 +437,6 @@ public class ResourceManager {
|
|||
List<String> warnings = new ArrayList<String>();
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue