Fix date formatting to local
This commit is contained in:
parent
ec8bc2474a
commit
c9a6d47c82
6 changed files with 42 additions and 20 deletions
|
@ -407,7 +407,7 @@ public class ResourceManager {
|
|||
conf = new File(f, "_ttsconfig.p");
|
||||
}
|
||||
if (conf.exists()) {
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(conf.lastModified()))); //$NON-NLS-1$
|
||||
indexFileNames.put(f.getName(), Algorithms.formatDate(conf.lastModified())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ public class ResourceManager {
|
|||
if (dateCreated == 0) {
|
||||
dateCreated = f.lastModified();
|
||||
}
|
||||
indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(dateCreated))); //$NON-NLS-1$
|
||||
indexFileNames.put(f.getName(), Algorithms.formatDate(dateCreated)); //$NON-NLS-1$
|
||||
for (String rName : index.getRegionNames()) {
|
||||
// skip duplicate names (don't make collision between getName() and name in the map)
|
||||
// it can be dangerous to use one file to different indexes if it is multithreaded
|
||||
|
@ -923,7 +923,7 @@ public class ResourceManager {
|
|||
if (lf != null) {
|
||||
for (File f : lf) {
|
||||
if (f != null && f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
map.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(f.lastModified()))); //$NON-NLS-1$
|
||||
map.put(f.getName(), Algorithms.formatDate(f.lastModified())); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
@ -132,8 +133,8 @@ public class ContributionVersionActivity extends OsmandListActivity {
|
|||
if (showMessage) {
|
||||
AccessibleToast.makeText(
|
||||
this,
|
||||
MessageFormat.format(getString(R.string.build_installed), currentSelectedBuild.tag, dateFormat
|
||||
.format(currentSelectedBuild.date)), Toast.LENGTH_LONG).show();
|
||||
MessageFormat.format(getString(R.string.build_installed), currentSelectedBuild.tag,
|
||||
Algorithms.formatDate(currentSelectedBuild.date.getTime())), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
getMyApplication().getSettings().CONTRIBUTION_INSTALL_APP_DATE.set(dateFormat.format(d));
|
||||
}
|
||||
|
@ -196,7 +197,8 @@ public class ContributionVersionActivity extends OsmandListActivity {
|
|||
super.onListItemClick(l, v, position, id);
|
||||
final OsmAndBuild item = (OsmAndBuild) getListAdapter().getItem(position);
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.install_selected_build), item.tag, dateFormat.format(item.date), item.size));
|
||||
builder.setMessage(MessageFormat.format(getString(R.string.install_selected_build), item.tag,
|
||||
Algorithms.formatDate(item.date.getTime()), item.size));
|
||||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
|
@ -249,7 +251,7 @@ public class ContributionVersionActivity extends OsmandListActivity {
|
|||
|
||||
TextView description = (TextView) row.findViewById(R.id.download_descr);
|
||||
StringBuilder format = new StringBuilder();
|
||||
format.append(dateFormat.format(build.date))/*.append(" : ").append(build.size).append(" MB")*/;
|
||||
format.append(Algorithms.formatDate(build.date.getTime()))/*.append(" : ").append(build.size).append(" MB")*/;
|
||||
description.setText(format.toString());
|
||||
|
||||
if(currentInstalledDate != null){
|
||||
|
|
|
@ -575,7 +575,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
if (filename.endsWith(ext)) {
|
||||
String date = MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(new File(dir, filename).lastModified()));
|
||||
String date = Algorithms.formatDate(new File(dir, filename).lastModified());
|
||||
files.put(filename, date);
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -13,6 +13,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.binary.BinaryIndexPart;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
|
||||
|
@ -45,18 +47,26 @@ public class LocalIndexHelper {
|
|||
|
||||
private final OsmandApplication app;
|
||||
|
||||
private MessageFormat dateformat = new MessageFormat("{0,date,dd.MM.yyyy}", Locale.US);
|
||||
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public LocalIndexHelper(OsmandApplication app){
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public String formatDate(long t) {
|
||||
if(dateFormat == null) {
|
||||
dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
}
|
||||
return dateFormat.format(new Date(t));
|
||||
}
|
||||
|
||||
public String getInstalledDate(File f){
|
||||
return getInstalledDate(f.lastModified());
|
||||
}
|
||||
|
||||
public String getInstalledDate(long t){
|
||||
return app.getString(R.string.local_index_installed) + " : " + dateformat.format(new Object[]{new Date(t)});
|
||||
return app.getString(R.string.local_index_installed) + " : " + formatDate(t);
|
||||
}
|
||||
|
||||
public void updateDescription(LocalIndexInfo info){
|
||||
|
|
|
@ -232,21 +232,21 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
String nm = name == null? "" : name ;
|
||||
if(isPhoto()){
|
||||
return ctx.getString(R.string.recording_photo_description, nm,
|
||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||
Algorithms.formatDateTime(file.lastModified())).trim();
|
||||
}
|
||||
updateInternalDescription();
|
||||
return ctx.getString(R.string.recording_description, nm, getDuration(ctx),
|
||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||
Algorithms.formatDateTime(file.lastModified())).trim();
|
||||
}
|
||||
|
||||
public String getSmallDescription(Context ctx){
|
||||
String nm = name == null? "" : name ;
|
||||
if(isPhoto()){
|
||||
return ctx.getString(R.string.recording_photo_description, nm,
|
||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||
return ctx.getString(R.string.recording_photo_description, nm,
|
||||
Algorithms.formatDateTime(file.lastModified())).trim();
|
||||
}
|
||||
return ctx.getString(R.string.recording_description, nm, "",
|
||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||
Algorithms.formatDateTime(file.lastModified())).trim();
|
||||
}
|
||||
|
||||
private String getDuration(Context ctx) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.download;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -13,6 +14,7 @@ import net.osmand.plus.ClientContext;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -27,6 +29,7 @@ import android.content.res.AssetManager;
|
|||
|
||||
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) {
|
||||
|
@ -56,10 +59,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
long dateModified = System.currentTimeMillis();
|
||||
try {
|
||||
ApplicationInfo appInfo = pm.getApplicationInfo(OsmandApplication.class.getPackage().getName(), 0);
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
||||
dateModified = new File(appInfo.sourceDir).lastModified();
|
||||
Date installed = new Date(dateModified);
|
||||
date = format.format(installed);
|
||||
date = Algorithms.formatDate(dateModified);
|
||||
} catch (NameNotFoundException e) {
|
||||
//do nothing...
|
||||
}
|
||||
|
@ -74,9 +75,8 @@ public class DownloadOsmandIndexesHelper {
|
|||
IndexItem item = result.getIndexFilesByName(key);
|
||||
if (item != null) {
|
||||
File destFile = new File(voicePath, voice + File.separatorChar + "_config.p");
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
|
||||
try {
|
||||
Date d = format.parse(item.getDate());
|
||||
Date d = Algorithms.getDateFormat().parse(item.getDate());
|
||||
if (d.getTime() > dateModified) {
|
||||
continue;
|
||||
}
|
||||
|
@ -127,6 +127,7 @@ public class DownloadOsmandIndexesHelper {
|
|||
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(date);
|
||||
IndexItem it = new IndexItem(name, description, date, size, parts);
|
||||
it.setType(tp);
|
||||
result.add(it);
|
||||
|
@ -156,6 +157,15 @@ public class DownloadOsmandIndexesHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static String reparseDate(String date) {
|
||||
try {
|
||||
Date d = simpleDateFormat.parse(date);
|
||||
return Algorithms.formatDate(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AssetIndexItem extends IndexItem {
|
||||
|
||||
private final String assetName;
|
||||
|
|
Loading…
Reference in a new issue