aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/connector/AbstractConnector.java5
-rw-r--r--main/src/cgeo/geocaching/connector/IConnector.java9
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECApi.java34
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECConnector.java23
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECConstants.java2
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECGPXParser.java10
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECLoggingManager.java3
-rw-r--r--main/src/cgeo/geocaching/connector/ec/ECLogin.java6
-rw-r--r--main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java5
-rw-r--r--main/src/cgeo/geocaching/ui/CacheDetailsCreator.java12
10 files changed, 46 insertions, 63 deletions
diff --git a/main/src/cgeo/geocaching/connector/AbstractConnector.java b/main/src/cgeo/geocaching/connector/AbstractConnector.java
index b10366e..a369a7c 100644
--- a/main/src/cgeo/geocaching/connector/AbstractConnector.java
+++ b/main/src/cgeo/geocaching/connector/AbstractConnector.java
@@ -200,4 +200,9 @@ public abstract class AbstractConnector implements IConnector {
// Default: just return the name
return name;
}
+
+ @Override
+ public int getMaxTerrain() {
+ return 5;
+ }
}
diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java
index a96ee10..4ac8c55 100644
--- a/main/src/cgeo/geocaching/connector/IConnector.java
+++ b/main/src/cgeo/geocaching/connector/IConnector.java
@@ -232,9 +232,16 @@ public interface IConnector {
/**
* Get the 'prefix' (key) for a waypoint from the 'name' in the gpx file
- *
+ *
* @param name
* @return
*/
public String getWaypointPrefix(String name);
+
+ /**
+ * Get the maximum value for Terrain
+ *
+ * @return
+ */
+ public int getMaxTerrain();
}
diff --git a/main/src/cgeo/geocaching/connector/ec/ECApi.java b/main/src/cgeo/geocaching/connector/ec/ECApi.java
index 62571ae..d458e88 100644
--- a/main/src/cgeo/geocaching/connector/ec/ECApi.java
+++ b/main/src/cgeo/geocaching/connector/ec/ECApi.java
@@ -7,6 +7,7 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.StatusCode;
+import cgeo.geocaching.files.GPX10Parser;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.list.StoredList;
@@ -34,7 +35,8 @@ import java.util.TimeZone;
public class ECApi {
- private static final String API_URL = "http://extremcaching.com/exports/api.php";
+ private static final String API_HOST = "http://extremcaching.com/exports/";
+
private static final FastDateFormat LOG_DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC"), Locale.US);
public static String cleanCode(String geocode) {
@@ -42,9 +44,8 @@ public class ECApi {
}
public static Geocache searchByGeoCode(final String geocode) {
- final Parameters params = new Parameters("id", cleanCode(geocode));
- params.add("cgeo", "1");
- final HttpResponse response = apiRequest("http://extremcaching.com/exports/gpx.php", params);
+ final Parameters params = new Parameters("id", cleanCode(geocode), "cgeo", "1");
+ final HttpResponse response = apiRequest("gpx.php", params);
final Collection<Geocache> caches = importCachesFromGPXResponse(response);
if (CollectionUtils.isNotEmpty(caches)) {
@@ -91,7 +92,7 @@ public class ECApi {
params.add("log", log);
params.add("date", LOG_DATE_FORMAT.format(date.getTime()));
- final String uri = "http://extremcaching.com/exports/log.php";
+ final String uri = API_HOST + "log.php";
final HttpResponse response = Network.postRequest(uri, params);
if (response == null) {
@@ -107,7 +108,7 @@ public class ECApi {
}
final String data = Network.getResponseDataAlways(response);
- if (data != null && !StringUtils.isBlank(data) && StringUtils.contains(data, "success")) {
+ if (!StringUtils.isBlank(data) && StringUtils.contains(data, "success")) {
final String uid = StringUtils.remove(data, "success:");
return new LogResult(StatusCode.NO_ERROR, uid);
}
@@ -117,7 +118,7 @@ public class ECApi {
private static HttpResponse apiRequest(final Parameters params) {
- return apiRequest(API_URL, params, false);
+ return apiRequest("api.php", params, false);
}
private static HttpResponse apiRequest(final String uri, final Parameters params) {
@@ -125,7 +126,7 @@ public class ECApi {
}
private static HttpResponse apiRequest(final String uri, final Parameters params, final boolean isRetry) {
- final HttpResponse response = Network.getRequest(uri, params);
+ final HttpResponse response = Network.getRequest(API_HOST + uri, params);
if (response == null) {
return null;
@@ -145,14 +146,13 @@ public class ECApi {
if (response == null) {
return Collections.emptyList();
}
- Collection<Geocache> caches;
+
try {
- caches = new ECGPXParser(StoredList.TEMPORARY_LIST_ID).parse(response.getEntity().getContent(), null);
+ return new GPX10Parser(StoredList.TEMPORARY_LIST_ID).parse(response.getEntity().getContent(), null);
} catch (Exception e) {
Log.e("Error importing gpx from extremcaching.com", e);
return Collections.emptyList();
}
- return caches;
}
private static List<Geocache> importCachesFromJSON(final HttpResponse response) {
@@ -160,14 +160,17 @@ public class ECApi {
if (response != null) {
try {
final String data = Network.getResponseDataAlways(response);
- if (data == null || StringUtils.isBlank(data) || StringUtils.equals(data, "[]")) {
+ if (StringUtils.isBlank(data) || StringUtils.equals(data, "[]")) {
return Collections.emptyList();
}
final JSONArray json = new JSONArray(data);
- final List<Geocache> caches = new ArrayList<Geocache>(json.length());
- for (int i = 0; i < json.length(); i++) {
+ final int len = json.length();
+ final List<Geocache> caches = new ArrayList<Geocache>(len);
+ for (int i = 0; i < len; i++) {
final Geocache cache = parseCache(json.getJSONObject(i));
- caches.add(cache);
+ if (cache != null) {
+ caches.add(cache);
+ }
}
return caches;
} catch (final JSONException e) {
@@ -194,6 +197,7 @@ public class ECApi {
DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_CACHE));
} catch (final JSONException e) {
Log.e("ECApi.parseCache", e);
+ return null;
}
return cache;
}
diff --git a/main/src/cgeo/geocaching/connector/ec/ECConnector.java b/main/src/cgeo/geocaching/connector/ec/ECConnector.java
index 8c5f0a1..2edf0da 100644
--- a/main/src/cgeo/geocaching/connector/ec/ECConnector.java
+++ b/main/src/cgeo/geocaching/connector/ec/ECConnector.java
@@ -84,12 +84,8 @@ public class ECConnector extends AbstractConnector implements ISearchByGeocode,
CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage);
final Geocache cache = ECApi.searchByGeoCode(geocode);
- if (cache == null) {
- return null;
- }
- final SearchResult searchResult = new SearchResult(cache);
- return searchResult;
+ return cache != null ? new SearchResult(cache) : null;
}
@Override
@@ -114,7 +110,6 @@ public class ECConnector extends AbstractConnector implements ISearchByGeocode,
@Override
public boolean isOwner(final ICache cache) {
- //return StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), Settings.getUsername());
return false;
}
@@ -173,16 +168,9 @@ public class ECConnector extends AbstractConnector implements ISearchByGeocode,
public int getCacheMapMarkerId(boolean disabled) {
final String icons = Settings.getECIconSet();
if (StringUtils.equals(icons, "1")) {
- if (disabled) {
- return R.drawable.marker_disabled_other;
- }
- return R.drawable.marker_other;
- }
-
- if (disabled) {
- return R.drawable.marker_disabled_oc;
+ return disabled ? R.drawable.marker_disabled_other : R.drawable.marker_other;
}
- return R.drawable.marker_oc;
+ return disabled ? R.drawable.marker_disabled_oc : R.drawable.marker_oc;
}
@Override
@@ -222,4 +210,9 @@ public class ECConnector extends AbstractConnector implements ISearchByGeocode,
return logTypes;
}
+ @Override
+ public int getMaxTerrain() {
+ return 7;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/connector/ec/ECConstants.java b/main/src/cgeo/geocaching/connector/ec/ECConstants.java
index 9b7353b..7c02d8e 100644
--- a/main/src/cgeo/geocaching/connector/ec/ECConstants.java
+++ b/main/src/cgeo/geocaching/connector/ec/ECConstants.java
@@ -10,7 +10,7 @@ public final class ECConstants {
public static final Pattern PATTERN_LOGIN_NAME = Pattern.compile("\"mod_login_greetingfrontpage-teaser\">Hallo, ([^<]+)</span>");
public static final Pattern PATTERN_LOGIN_SECURITY = Pattern.compile("<input type=\"hidden\" name=\"return\" value=\"(.*)\" />[^<]*<input type=\"hidden\" name=\"(.*)\" value=\"1\" />");
- public static final Pattern PATTERN_CACHES_FOUND = Pattern.compile("Gefundene Caches::</label><div class=\"cb_field\"><div id=\"cbfv_71\">([0-9]+)</div>");
+ public static final Pattern PATTERN_CACHES_FOUND = Pattern.compile("Gefundene Caches.*?>([0-9]+)<");
private ECConstants() {
// this class shall not have instances
diff --git a/main/src/cgeo/geocaching/connector/ec/ECGPXParser.java b/main/src/cgeo/geocaching/connector/ec/ECGPXParser.java
deleted file mode 100644
index f2ffb5e..0000000
--- a/main/src/cgeo/geocaching/connector/ec/ECGPXParser.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package cgeo.geocaching.connector.ec;
-
-import cgeo.geocaching.files.GPX10Parser;
-
-public class ECGPXParser extends GPX10Parser {
-
- public ECGPXParser(int listIdIn) {
- super(listIdIn);
- }
-}
diff --git a/main/src/cgeo/geocaching/connector/ec/ECLoggingManager.java b/main/src/cgeo/geocaching/connector/ec/ECLoggingManager.java
index 716c0a3..c736fe3 100644
--- a/main/src/cgeo/geocaching/connector/ec/ECLoggingManager.java
+++ b/main/src/cgeo/geocaching/connector/ec/ECLoggingManager.java
@@ -33,8 +33,7 @@ public class ECLoggingManager implements ILoggingManager {
@Override
public final LogResult postLog(final Geocache cache, final LogType logType, final Calendar date, final String log, final String logPassword, final List<TrackableLog> trackableLogs) {
- final LogResult result = ECApi.postLog(cache, logType, date, log);
- return result;
+ return ECApi.postLog(cache, logType, date, log);
}
@Override
diff --git a/main/src/cgeo/geocaching/connector/ec/ECLogin.java b/main/src/cgeo/geocaching/connector/ec/ECLogin.java
index 8eaa8ee..2fda8c3 100644
--- a/main/src/cgeo/geocaching/connector/ec/ECLogin.java
+++ b/main/src/cgeo/geocaching/connector/ec/ECLogin.java
@@ -41,7 +41,6 @@ public abstract class ECLogin {
}
ECLogin.setActualStatus(CgeoApplication.getInstance().getString(R.string.init_login_popup_working));
- //HttpResponse loginResponse = Network.getRequest("http://extremcaching.com/component/users/?view=login");
HttpResponse loginResponse = Network.getRequest("https://extremcaching.com/community/profil1");
String loginData = Network.getResponseData(loginResponse);
@@ -55,9 +54,6 @@ public abstract class ECLogin {
return StatusCode.NO_ERROR; // logged in
}
- //Cookies.clearCookies();
- //Settings.setCookieStore(null);
-
final Parameters params = new Parameters(
"username", login.left,
"password", login.right,
@@ -89,7 +85,7 @@ public abstract class ECLogin {
return StatusCode.NO_ERROR; // logged in
}
- if (loginData.contains("Benutzername und Passwort falsch")) {
+ if (loginData.contains("Benutzername und Passwort falsch")) { // Yes, it's hardcoded in German (translation is done using Javascript and Google Translate)
Log.i("Failed to log in Extremcaching.com as " + login.left + " because of wrong username/password");
return StatusCode.WRONG_LOGIN_DATA; // wrong login
}
diff --git a/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java b/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java
index fabd5a5..7424fe6 100644
--- a/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java
+++ b/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java
@@ -78,8 +78,6 @@ public class CheckECCredentialsPreference extends Preference {
if (loginDialog != null && loginDialog.isShowing()) {
loginDialog.dismiss();
}
- // enable/disable basic member preferences
- //activity.initBasicMemberPreferences();
}
}
};
@@ -110,8 +108,7 @@ public class CheckECCredentialsPreference extends Preference {
final StatusCode loginResult = ECLogin.login();
Object payload = loginResult;
if (loginResult == StatusCode.NO_ERROR) {
- //Login.detectGcCustomDate();
- payload = null;// Login.downloadAvatarAndGetMemberStatus();
+ payload = null;
}
logInHandler.obtainMessage(0, payload).sendToTarget();
}
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
index dad87f0..7fe77c4 100644
--- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
+++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.Waypoint;
-import cgeo.geocaching.connector.ec.ECConnector;
+import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Units;
@@ -72,10 +72,6 @@ public final class CacheDetailsCreator {
return layout;
}
- private void createStarImages(final ViewGroup starsContainer, final float value) {
- createStarImages(starsContainer, value, 5);
- }
-
private void createStarImages(final ViewGroup starsContainer, final float value, final int max) {
final LayoutInflater inflater = LayoutInflater.from(activity);
@@ -139,11 +135,7 @@ public final class CacheDetailsCreator {
public void addTerrain(Geocache cache) {
if (cache.getTerrain() > 0) {
- if (ECConnector.getInstance().canHandle(cache.getGeocode())) {
- addStars(R.string.cache_terrain, cache.getTerrain(), 7);
- } else {
- addStars(R.string.cache_terrain, cache.getTerrain());
- }
+ addStars(R.string.cache_terrain, cache.getTerrain(), ConnectorFactory.getConnector(cache).getMaxTerrain());
}
}