Fix modified date (unified UTC solution)

This commit is contained in:
vshcherb 2014-04-28 22:26:43 +02:00
parent 7552c91b01
commit 71b98f79f0
5 changed files with 20 additions and 25 deletions

View file

@ -1,6 +1,5 @@
package net.osmand; package net.osmand;
import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;

View file

@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
@ -31,7 +30,6 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
@ -41,7 +39,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.format.DateFormat;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
@ -506,16 +503,14 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
public static Map<String, String> listWithAlternatives(final Context ctx, File file, final String ext, public static Map<String, String> listWithAlternatives(final java.text.DateFormat dateFormat, File file, final String ext,
final Map<String, String> files) { final Map<String, String> files) {
if (file.isDirectory()) { if (file.isDirectory()) {
final java.text.DateFormat format = DateFormat.getDateFormat(ctx);
format.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
file.list(new FilenameFilter() { file.list(new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String filename) { public boolean accept(File dir, String filename) {
if (filename.endsWith(ext)) { 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); files.put(filename, date);
return true; return true;
} else { } else {

View file

@ -47,7 +47,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear(); list.clear();
list.addAll(cats); list.addAll(cats);
} }
format = DateFormat.getDateFormat(downloadActivity); format = downloadActivity.getMyApplication().getResourceManager().getDateFormat();
okColor = downloadActivity.getResources().getColor(R.color.color_ok); okColor = downloadActivity.getResources().getColor(R.color.color_ok);
TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); TypedArray ta = downloadActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown)); defaultColor = ta.getColor(0, downloadActivity.getResources().getColor(R.color.color_unknown));

View file

@ -43,7 +43,6 @@ import android.os.AsyncTask;
import android.os.AsyncTask.Status; import android.os.AsyncTask.Status;
import android.os.Build; import android.os.Build;
import android.os.StatFs; import android.os.StatFs;
import android.text.format.DateFormat;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
@ -66,7 +65,7 @@ public class DownloadIndexesThread {
this.ctx = ctx; this.ctx = ctx;
app = (OsmandApplication) ctx.getApplicationContext(); app = (OsmandApplication) ctx.getApplicationContext();
downloadFileHelper = new DownloadFileHelper(app); downloadFileHelper = new DownloadFileHelper(app);
dateFormat = DateFormat.getDateFormat(app); dateFormat = app.getResourceManager().getDateFormat();
} }
public void setUiActivity(DownloadIndexActivity uiActivity) { public void setUiActivity(DownloadIndexActivity uiActivity) {
@ -89,12 +88,12 @@ public class DownloadIndexesThread {
public void updateLoadedFiles() { public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames(); Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(app, app.getAppPath(""), DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
IndexConstants.EXTRA_EXT, indexActivatedFileNames); indexActivatedFileNames);
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames(); Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexActivity.listWithAlternatives(app, app.getAppPath(""), DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
IndexConstants.EXTRA_EXT, indexFileNames); indexFileNames);
DownloadIndexActivity.listWithAlternatives(app,app.getAppPath(IndexConstants.TILES_INDEX_DIR), DownloadIndexActivity.listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR),
IndexConstants.SQLITE_EXT, indexFileNames); IndexConstants.SQLITE_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames); app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames; this.indexFileNames = indexFileNames;
@ -535,11 +534,11 @@ public class DownloadIndexesThread {
} }
public boolean isDownloadRunning(){ public boolean isDownloadRunning() {
for(int i =0; i<currentRunningTask.size(); i++) { for (int i = 0; i < currentRunningTask.size(); i++) {
if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) { if (currentRunningTask.get(i) instanceof DownloadIndexesAsyncTask) {
return true; return true;
} }
} }
return false; return false;

View file

@ -14,7 +14,6 @@ import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -135,8 +134,10 @@ public class ResourceManager {
private HandlerThread renderingBufferImageThread; private HandlerThread renderingBufferImageThread;
protected boolean internetIsNotAccessible = false; protected boolean internetIsNotAccessible = false;
private java.text.DateFormat dateFormat;
public ResourceManager(OsmandApplication context) { public ResourceManager(OsmandApplication context) {
this.context = context; this.context = context;
this.renderer = new MapRenderRepositories(context); this.renderer = new MapRenderRepositories(context);
asyncLoadingThread.start(); asyncLoadingThread.start();
@ -144,7 +145,7 @@ public class ResourceManager {
renderingBufferImageThread.start(); renderingBufferImageThread.start();
tileDownloader = MapTileDownloader.getInstance(Version.getFullVersion(context)); tileDownloader = MapTileDownloader.getInstance(Version.getFullVersion(context));
dateFormat = DateFormat.getDateFormat(context);
resetStoreDirectory(); resetStoreDirectory();
WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); WindowManager mgr = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics(); DisplayMetrics dm = new DisplayMetrics();
@ -176,6 +177,9 @@ public class ResourceManager {
} }
} }
public java.text.DateFormat getDateFormat() {
return dateFormat;
}
public OsmandApplication getContext() { public OsmandApplication getContext() {
return context; return context;
@ -436,7 +440,6 @@ public class ResourceManager {
file.mkdirs(); file.mkdirs();
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
if (file.exists() && file.canRead()) { if (file.exists() && file.canRead()) {
final java.text.DateFormat format = DateFormat.getDateFormat(context);
File[] lf = file.listFiles(); File[] lf = file.listFiles();
if (lf != null) { if (lf != null) {
for (File f : lf) { for (File f : lf) {
@ -446,7 +449,7 @@ public class ResourceManager {
conf = new File(f, "_ttsconfig.p"); conf = new File(f, "_ttsconfig.p");
} }
if (conf.exists()) { 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); log.error(e.getMessage(), e);
} }
} }
final java.text.DateFormat format = DateFormat.getDateFormat(context);
for (File f : files) { for (File f : files) {
progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$ progress.startTask(context.getString(R.string.indexing_map) + " " + f.getName(), -1); //$NON-NLS-1$
try { try {
@ -640,7 +642,7 @@ public class ResourceManager {
if (dateCreated == 0) { if (dateCreated == 0) {
dateCreated = f.lastModified(); 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()) { for (String rName : index.getRegionNames()) {
// skip duplicate names (don't make collision between getName() and name in the map) // 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 // it can be dangerous to use one file to different indexes if it is multithreaded