From 71b98f79f06f48d5f0db7b2a977c866807ad7525 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 28 Apr 2014 22:26:43 +0200 Subject: [PATCH] Fix modified date (unified UTC solution) --- .../net/osmand/GeoidAltitudeCorrection.java | 1 - .../activities/DownloadIndexActivity.java | 9 ++------- .../plus/download/DownloadIndexAdapter.java | 2 +- .../plus/download/DownloadIndexesThread.java | 19 +++++++++---------- .../plus/resources/ResourceManager.java | 14 ++++++++------ 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/GeoidAltitudeCorrection.java b/OsmAnd-java/src/net/osmand/GeoidAltitudeCorrection.java index 9a090ba768..fa682d6f75 100644 --- a/OsmAnd-java/src/net/osmand/GeoidAltitudeCorrection.java +++ b/OsmAnd-java/src/net/osmand/GeoidAltitudeCorrection.java @@ -1,6 +1,5 @@ package net.osmand; -import java.io.EOFException; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 922d4923b2..3b8a093594 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.TimeZone; import net.osmand.IndexConstants; import net.osmand.access.AccessibleAlertBuilder; @@ -31,7 +30,6 @@ import net.osmand.plus.srtmplugin.SRTMPlugin; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; @@ -41,7 +39,6 @@ import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; -import android.text.format.DateFormat; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; @@ -506,16 +503,14 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { } - public static Map listWithAlternatives(final Context ctx, File file, final String ext, + public static Map listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext, final Map files) { if (file.isDirectory()) { - final java.text.DateFormat format = DateFormat.getDateFormat(ctx); - format.setTimeZone(TimeZone.getTimeZone("GMT+01:00")); file.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(ext)) { - String date = format.format(new File(dir, filename).lastModified()); + String date = dateFormat.format(new File(dir, filename).lastModified()); files.put(filename, date); return true; } else { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java index bf28261c74..d8ebf10300 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java @@ -47,7 +47,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem list.clear(); list.addAll(cats); } - format = DateFormat.getDateFormat(downloadActivity); + format = downloadActivity.getMyApplication().getResourceManager().getDateFormat(); 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)); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index c018bf73e3..4abaa829f7 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -43,7 +43,6 @@ 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; @@ -66,7 +65,7 @@ public class DownloadIndexesThread { this.ctx = ctx; app = (OsmandApplication) ctx.getApplicationContext(); downloadFileHelper = new DownloadFileHelper(app); - dateFormat = DateFormat.getDateFormat(app); + dateFormat = app.getResourceManager().getDateFormat(); } public void setUiActivity(DownloadIndexActivity uiActivity) { @@ -89,12 +88,12 @@ public class DownloadIndexesThread { public void updateLoadedFiles() { Map indexActivatedFileNames = app.getResourceManager().getIndexFileNames(); - DownloadIndexActivity.listWithAlternatives(app, app.getAppPath(""), - IndexConstants.EXTRA_EXT, indexActivatedFileNames); + DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, + indexActivatedFileNames); Map indexFileNames = app.getResourceManager().getIndexFileNames(); - DownloadIndexActivity.listWithAlternatives(app, app.getAppPath(""), - IndexConstants.EXTRA_EXT, indexFileNames); - DownloadIndexActivity.listWithAlternatives(app,app.getAppPath(IndexConstants.TILES_INDEX_DIR), + DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, + indexFileNames); + DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR), IndexConstants.SQLITE_EXT, indexFileNames); app.getResourceManager().getBackupIndexes(indexFileNames); this.indexFileNames = indexFileNames; @@ -535,11 +534,11 @@ public class DownloadIndexesThread { } - public boolean isDownloadRunning(){ - for(int i =0; i warnings = new ArrayList(); if (file.exists() && file.canRead()) { - final java.text.DateFormat format = DateFormat.getDateFormat(context); File[] lf = file.listFiles(); if (lf != null) { for (File f : lf) { @@ -446,7 +449,7 @@ public class ResourceManager { conf = new File(f, "_ttsconfig.p"); } if (conf.exists()) { - indexFileNames.put(f.getName(), format.format(conf.lastModified())); //$NON-NLS-1$ + indexFileNames.put(f.getName(), dateFormat.format(conf.lastModified())); //$NON-NLS-1$ } } } @@ -614,7 +617,6 @@ public class ResourceManager { log.error(e.getMessage(), e); } } - final java.text.DateFormat format = DateFormat.getDateFormat(context); for (File f : files) { progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$ try { @@ -640,7 +642,7 @@ public class ResourceManager { if (dateCreated == 0) { dateCreated = f.lastModified(); } - indexFileNames.put(f.getName(), format.format(dateCreated)); //$NON-NLS-1$ + indexFileNames.put(f.getName(), dateFormat.format(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