aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-07-17 07:54:12 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-07-17 07:54:12 +0200
commit8af7e6965a46ef46c628c164262b044fb271d263 (patch)
tree4711035e0868198e58d9d6de8dc797f41c6fefdc /main/src
parent769721803cc75ab97e69a172e1c99ec6f6762886 (diff)
downloadcgeo-8af7e6965a46ef46c628c164262b044fb271d263.zip
cgeo-8af7e6965a46ef46c628c164262b044fb271d263.tar.gz
cgeo-8af7e6965a46ef46c628c164262b044fb271d263.tar.bz2
fix #2994: have [NUMBER] template respect cache source
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/utils/LogTemplateProvider.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
index 3497dac..98201b5 100644
--- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
@@ -3,9 +3,9 @@ package cgeo.geocaching.utils;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.Trackable;
-import cgeo.geocaching.connector.gc.GCConstants;
-import cgeo.geocaching.connector.gc.Login;
-import cgeo.geocaching.network.Network;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.connector.capability.ILogin;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.Formatter;
@@ -135,24 +135,32 @@ public final class LogTemplateProvider {
@Override
public String getValue(final LogContext context) {
- Geocache cache = context.getCache();
+ final Geocache cache = context.getCache();
if (cache == null) {
return StringUtils.EMPTY;
}
- int current = Login.getActualCachesFound();
+
+ int current = 0;
+ final IConnector connector = ConnectorFactory.getConnector(cache);
+ if (connector instanceof ILogin) {
+ current = ((ILogin) connector).getCachesFound();
+ }
+
+ // try updating the login information, if the counter is zero
if (current == 0) {
if (context.isOffline()) {
return StringUtils.EMPTY;
}
- final String page = Network.getResponseData(Network.getRequest("http://www.geocaching.com/email/"));
- current = parseFindCount(page);
+ if (connector instanceof ILogin) {
+ ((ILogin) connector).login(null, null);
+ current = ((ILogin) connector).getCachesFound();
+ }
}
- String findCount = StringUtils.EMPTY;
if (current >= 0) {
- findCount = String.valueOf(current + 1);
+ return String.valueOf(current + 1);
}
- return findCount;
+ return StringUtils.EMPTY;
}
});
templates.add(new LogTemplate("OWNER", R.string.init_signature_template_owner) {
@@ -192,17 +200,4 @@ public final class LogTemplateProvider {
}
return result;
}
-
- private static int parseFindCount(final String page) {
- if (StringUtils.isBlank(page)) {
- return -1;
- }
-
- try {
- return Integer.parseInt(TextUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "-1").replaceAll("[,.]", StringUtils.EMPTY));
- } catch (NumberFormatException e) {
- Log.e("parseFindCount", e);
- return -1;
- }
- }
}