aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2015-03-26 23:29:33 +0100
committerSamuel Tardieu <sam@rfc1149.net>2015-03-26 23:45:38 +0100
commitfb8a006a8717706209244a9fd07aa6283887aa10 (patch)
tree1a48d771c7b8ddcc0074d62a7641c91889531920 /main
parente2163789c04b483649d079881585125802c4c85a (diff)
downloadcgeo-fb8a006a8717706209244a9fd07aa6283887aa10.zip
cgeo-fb8a006a8717706209244a9fd07aa6283887aa10.tar.gz
cgeo-fb8a006a8717706209244a9fd07aa6283887aa10.tar.bz2
fix #4763: membership detection not working
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConstants.java7
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCLogin.java31
-rw-r--r--main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java2
3 files changed, 25 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
index a069b68..cfd3642 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -68,10 +68,9 @@ public final class GCConstants {
// Info box top-right
public static final Pattern PATTERN_LOGIN_NAME = Pattern.compile("\"SignedInProfileLink\">(.*?)</a>");
- public static final Pattern PATTERN_MEMBER_STATUS = Pattern.compile("<span id=\"ctl00_litPMLevel\">([^<]+)</span>");
- static final String MEMBER_STATUS_RENEW = "<a id=\"ctl00_hlRenew";
- public static final String MEMBER_STATUS_PREMIUM = "Premium Member";
- public static final String MEMBER_STATUS_CHARTER = "Charter Member";
+ public static final Pattern PATTERN_MEMBERSHIP = Pattern.compile("<dl class=\"membership-details\">.*?<dt>Membership</dt>.*?<dd>\\s*(\\p{Alpha}+)\\s*</dd>", Pattern.DOTALL);
+ public static final String MEMBER_STATUS_PREMIUM = "Premium";
+ public static final String MEMBER_STATUS_CHARTER = "Charter";
/** Use replaceAll("[,.]","") on the resulting string before converting to an int */
static final Pattern PATTERN_CACHES_FOUND = Pattern.compile("<span[^>]*>.*?([\\d,.]+) Find?", Pattern.DOTALL);
static final Pattern PATTERN_AVATAR_IMAGE_PROFILE_PAGE = Pattern.compile("src=\"(https?://(img(?:cdn)?\\.geocaching\\.com|[^>\"]+\\.cloudfront\\.net)/avatar/[0-9a-f-]+\\.jpg)\"[^>]*alt=\"");
diff --git a/main/src/cgeo/geocaching/connector/gc/GCLogin.java b/main/src/cgeo/geocaching/connector/gc/GCLogin.java
index 514cb2c..16de511 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCLogin.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCLogin.java
@@ -32,6 +32,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.regex.Matcher;
public class GCLogin extends AbstractLogin {
@@ -87,6 +88,7 @@ public class GCLogin extends AbstractLogin {
return login(false);
}
setHomeLocation();
+ refreshMemberStatus();
detectGcCustomDate();
return StatusCode.NO_ERROR; // logged in
}
@@ -124,6 +126,8 @@ public class GCLogin extends AbstractLogin {
}
Log.i("Successfully logged in Geocaching.com as " + username + " (" + Settings.getGCMemberStatus() + ')');
Settings.setCookieStore(Cookies.dumpCookieStore());
+ setHomeLocation();
+ refreshMemberStatus();
detectGcCustomDate();
return StatusCode.NO_ERROR; // logged in
}
@@ -192,10 +196,6 @@ public class GCLogin extends AbstractLogin {
Log.e("getLoginStatus: bad cache count", e);
}
setActualCachesFound(cachesCount);
- Settings.setGCMemberStatus(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, null));
- if (page.contains(GCConstants.MEMBER_STATUS_RENEW)) {
- Settings.setGCMemberStatus(GCConstants.MEMBER_STATUS_PREMIUM);
- }
return true;
}
@@ -242,16 +242,11 @@ public class GCLogin extends AbstractLogin {
return false;
}
- public Observable<Drawable> downloadAvatarAndGetMemberStatus() {
+ public Observable<Drawable> downloadAvatar() {
try {
final String responseData = StringUtils.defaultString(Network.getResponseData(Network.getRequest("http://www.geocaching.com/my/")));
final String profile = TextUtils.replaceWhitespace(responseData);
- Settings.setGCMemberStatus(TextUtils.getMatch(profile, GCConstants.PATTERN_MEMBER_STATUS, true, null));
- if (profile.contains(GCConstants.MEMBER_STATUS_RENEW)) {
- Settings.setGCMemberStatus(GCConstants.MEMBER_STATUS_PREMIUM);
- }
-
setActualCachesFound(Integer.parseInt(removeDotAndComma(TextUtils.getMatch(profile, GCConstants.PATTERN_CACHES_FOUND, true, "-1"))));
final String avatarURL = TextUtils.getMatch(profile, GCConstants.PATTERN_AVATAR_IMAGE_PROFILE_PAGE, false, null);
@@ -287,6 +282,22 @@ public class GCLogin extends AbstractLogin {
});
}
+ private static void refreshMemberStatus() {
+ RxUtils.networkScheduler.createWorker().schedule(new Action0() {
+ @Override
+ public void call() {
+ final String page = StringUtils.defaultString(Network.getResponseData(Network.getRequest("https://www.geocaching.com/account/settings/membership")));
+ final Matcher match = GCConstants.PATTERN_MEMBERSHIP.matcher(page);
+ if (match.find()) {
+ Log.d("Setting member status to " + match.group(1));
+ Settings.setGCMemberStatus(match.group(1));
+ } else {
+ Log.w("Cannot determine member status");
+ }
+ }
+ });
+ }
+
/**
* Detect user date settings on geocaching.com
*/
diff --git a/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java b/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java
index 6d4d9c2..04f406f 100644
--- a/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java
+++ b/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java
@@ -31,7 +31,7 @@ public class CheckGcCredentialsPreference extends AbstractCheckCredentialsPrefer
final StatusCode loginResult = GCLogin.getInstance().login();
switch (loginResult) {
case NO_ERROR:
- return ImmutablePair.of(StatusCode.NO_ERROR, GCLogin.getInstance().downloadAvatarAndGetMemberStatus());
+ return ImmutablePair.of(StatusCode.NO_ERROR, GCLogin.getInstance().downloadAvatar());
default:
return ImmutablePair.of(loginResult, null);
}