diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-07-18 21:26:42 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-07-18 21:26:42 +0200 |
| commit | a3e7256c505f9df3335aca417f36e4a8e96a5b4a (patch) | |
| tree | 6331afee572dedf22a2609bce28bca72818340ad | |
| parent | 770f8a0894da84fd74d2e01da5abf8785eeacd75 (diff) | |
| download | cgeo-a3e7256c505f9df3335aca417f36e4a8e96a5b4a.zip cgeo-a3e7256c505f9df3335aca417f36e4a8e96a5b4a.tar.gz cgeo-a3e7256c505f9df3335aca417f36e4a8e96a5b4a.tar.bz2 | |
refactoring: extract constant
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/Network.java | 13 |
2 files changed, 12 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index 0f3e0e1..ec09433 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -31,6 +31,9 @@ import java.io.OutputStream; */ public class LocalStorage { + public static final String HEADER_LAST_MODIFIED = "last-modified"; + public static final String HEADER_ETAG = "etag"; + /** Name of the local private directory used to hold cached information */ public final static String cache = ".cgeo"; @@ -177,8 +180,8 @@ public class LocalStorage { try { final boolean saved = saveToFile(response.getEntity().getContent(), targetFile); - saveHeader("etag", saved ? response : null, targetFile); - saveHeader("last-modified", saved ? response : null, targetFile); + saveHeader(HEADER_ETAG, saved ? response : null, targetFile); + saveHeader(HEADER_LAST_MODIFIED, saved ? response : null, targetFile); return saved; } catch (IOException e) { Log.e("LocalStorage.saveEntityToFile", e); diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index 14a9513..fc11dc8 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -1,9 +1,9 @@ package cgeo.geocaching.network; -import cgeo.geocaching.settings.Settings; import cgeo.geocaching.files.LocalStorage; -import cgeo.geocaching.utils.TextUtils; +import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.Log; +import cgeo.geocaching.utils.TextUtils; import ch.boye.httpclientandroidlib.Header; import ch.boye.httpclientandroidlib.HeaderElement; @@ -317,12 +317,13 @@ public abstract class Network { return null; } - final String etag = LocalStorage.getSavedHeader(cacheFile, "etag"); + final String etag = LocalStorage.getSavedHeader(cacheFile, LocalStorage.HEADER_ETAG); if (etag != null) { return new Parameters("If-None-Match", etag); + //FIXME: This seems to be wrong. Shouldn't we check for both headers instead of returning after finding the first? } - final String lastModified = LocalStorage.getSavedHeader(cacheFile, "last-modified"); + final String lastModified = LocalStorage.getSavedHeader(cacheFile, LocalStorage.HEADER_LAST_MODIFIED); if (lastModified != null) { return new Parameters("If-Modified-Since", lastModified); } @@ -476,10 +477,10 @@ public abstract class Network { /** * Checks if the device has network connection. - * + * * @param context * context of the application, cannot be null - * + * * @return <code>true</code> if the device is connected to the network. */ public static boolean isNetworkConnected(Context context) { |
