cache tiles without lastModified header field for 2 months instead of

updating them every time
This commit is contained in:
Philipp Schaefer 2014-12-30 13:06:19 +01:00
parent de521112f5
commit 90871774c3

View File

@ -29,8 +29,15 @@ public class DownloadTile extends AsyncTask<String, Void, Boolean> {
tileUrl = new URL(urls[0]);
conn = tileUrl.openConnection();
final File file = new File(mFilePath);
// some tiles don't have the lastModified header field set
// ...update tile every two month
final long updateTime = 2 * 30 * 24 * 60 * 60 * 1000;
final long systemTime = System.currentTimeMillis();
final long urlLM = conn.getLastModified();
final long fileLM = file.lastModified();
if (urlLM == 0 && (fileLM > systemTime - updateTime)) return true;
// update tile if needed, else return
if (conn.getLastModified() < file.lastModified()) return true;
if (urlLM < fileLM) return true;
InputStream is = null;
is = conn.getInputStream();
Log.d("writing to file: " + file.toString());