diff options
| author | SammysHP <sven@sammyshp.de> | 2011-08-29 17:50:52 +0200 |
|---|---|---|
| committer | SammysHP <sven@sammyshp.de> | 2011-08-29 17:50:52 +0200 |
| commit | baf6f5470e7ba572c88688a5879a1380b97f1b68 (patch) | |
| tree | 372a452b127e3187ef7b4feb2203fb80c2306f85 /src | |
| parent | 99be6fdac0c173ffe7d615122ccdbf646173d840 (diff) | |
| download | cgeo-baf6f5470e7ba572c88688a5879a1380b97f1b68.zip cgeo-baf6f5470e7ba572c88688a5879a1380b97f1b68.tar.gz cgeo-baf6f5470e7ba572c88688a5879a1380b97f1b68.tar.bz2 | |
Add detection of custom format at gc.com, fixes #307
Diffstat (limited to 'src')
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 32 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgSettings.java | 15 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoinit.java | 7 |
3 files changed, 51 insertions, 3 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 03223c1..2483438 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -125,7 +125,8 @@ public class cgBase { "yyyy/MM/dd", "dd/MMM/yyyy", "MMM/dd/yyyy", - "dd MMM yy" + "dd MMM yy", + "dd/MM/yyyy" }; HashMap<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>(); @@ -1893,7 +1894,7 @@ public class cgBase { // And BTW: You cannot even see that effect in the debugger, but must use a separate memory profiler! } - private static Date parseGcCustomDate(String input) + public Date parseGcCustomDate(String input) throws ParseException { if (input == null) @@ -1902,6 +1903,17 @@ public class cgBase { } input = input.trim(); + + if (null != settings + //&& null != settings.getGcCustomDate() + && gcCustomDateFormats.containsKey(settings.getGcCustomDate())) + { + try + { + return gcCustomDateFormats.get(settings.getGcCustomDate()).parse(input); + } + catch (ParseException e) {} + } for (SimpleDateFormat format : gcCustomDateFormats.values()) { @@ -1914,6 +1926,22 @@ public class cgBase { throw new ParseException("No matching pattern", 0); } + + public void detectGcCustomDate() + { + final String host = "www.geocaching.com"; + final String path = "/account/ManagePreferences.aspx"; + + final String result = request(false, host, path, "GET", null, false, false, false).getData(); + + final Pattern pattern = Pattern.compile("<option selected=\"selected\" value=\"([ /Mdy-]+)\">", Pattern.CASE_INSENSITIVE); + final Matcher matcher = pattern.matcher(result); + + if (matcher.find()) + { + settings.setGcCustomDate(matcher.group(1)); + } + } public cgRating getRating(String guid, String geocode) { ArrayList<String> guids = null; diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java index b2d2cf5..7c6be93 100644 --- a/src/cgeo/geocaching/cgSettings.java +++ b/src/cgeo/geocaching/cgSettings.java @@ -56,6 +56,7 @@ public class cgSettings { private static final String KEY_COORD_INPUT_FORMAT = "coordinputformat"; private static final String KEY_LOG_OFFLINE = "log_offline"; private static final String KEY_LOAD_DIRECTION_IMG = "loaddirectionimg"; + private static final String KEY_GC_CUSTOM_DATE = "gccustomdate"; private interface PrefRunnable { void edit(final Editor edit); @@ -608,4 +609,18 @@ public class cgSettings { public boolean getLoadDirImg() { return prefs.getBoolean(KEY_LOAD_DIRECTION_IMG, true); } + + void setGcCustomDate(final String format) { + editSettings(new PrefRunnable() { + + @Override + public void edit(Editor edit) { + edit.putString(KEY_GC_CUSTOM_DATE, format); + } + }); + } + + public String getGcCustomDate() { + return prefs.getString(KEY_GC_CUSTOM_DATE, null); + } } diff --git a/src/cgeo/geocaching/cgeoinit.java b/src/cgeo/geocaching/cgeoinit.java index 46ba767..e3111e2 100644 --- a/src/cgeo/geocaching/cgeoinit.java +++ b/src/cgeo/geocaching/cgeoinit.java @@ -1024,7 +1024,12 @@ public class cgeoinit extends AbstractActivity { @Override public void run() { - logInHandler.sendEmptyMessage(base.login()); + final int loginResult = base.login(); + if (1 == loginResult) + { + base.detectGcCustomDate(); + } + logInHandler.sendEmptyMessage(loginResult); } }).start(); } |
