aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/connector/gc
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc')
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConnector.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java15
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java19
-rw-r--r--main/src/cgeo/geocaching/connector/gc/Login.java24
-rw-r--r--main/src/cgeo/geocaching/connector/gc/SearchHandler.java21
5 files changed, 57 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
index e6fff79..835359a 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
@@ -299,7 +299,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
final StatusCode status = Login.login();
if (status == StatusCode.NO_ERROR) {
- cgeoapplication.getInstance().firstRun = false;
+ cgeoapplication.getInstance().checkLogin = false;
Login.detectGcCustomDate();
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index 4bc55fe..6a602a7 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -2,7 +2,6 @@ package cgeo.geocaching.connector.gc;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.SearchResult;
-import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.cgData;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.CacheSize;
@@ -11,9 +10,11 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy;
import cgeo.geocaching.enumerations.LiveMapStrategy.StrategyFlag;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter.Format;
import cgeo.geocaching.geopoint.Units;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.network.Parameters;
+import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.LeastRecentlyUsedMap;
import cgeo.geocaching.utils.Log;
@@ -208,8 +209,7 @@ public class GCMap {
cache.setReliableLatLon(false);
cache.setGeocode(id);
cache.setName(nameCache.get(id));
- cache.setZoomlevel(tile.getZoomlevel());
- cache.setCoords(tile.getCoord(xy));
+ cache.setCoords(tile.getCoord(xy), tile.getZoomlevel());
if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && bitmap != null) {
for (UTFGridPosition singlePos : singlePositions.get(id)) {
if (IconDecoder.parseMapPNG(cache, bitmap, singlePos, tile.getZoomlevel())) {
@@ -286,11 +286,18 @@ public class GCMap {
Log.d("GCMap.searchByViewport" + viewport.toString());
final SearchResult searchResult = new SearchResult();
- searchResult.setUrl(GCConstants.URL_LIVE_MAP + "?ll=" + viewport.getCenter().getLatitude() + "," + viewport.getCenter().getLongitude());
+
+ if (Settings.isDebug()) {
+ searchResult.setUrl(viewport.getCenter().format(Format.LAT_LON_DECMINUTE));
+ }
if (strategy.flags.contains(StrategyFlag.LOAD_TILES)) {
final Set<Tile> tiles = Tile.getTilesForViewport(viewport);
+ if (Settings.isDebug()) {
+ searchResult.setUrl(new StringBuilder().append(tiles.iterator().next().getZoomlevel()).append(Formatter.SEPARATOR).append(searchResult.getUrl()).toString());
+ }
+
for (Tile tile : tiles) {
if (!Tile.Cache.contains(tile)) {
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index e32f72d..7dc048a 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -78,20 +78,15 @@ public abstract class GCParser {
searchResult.viewstates = Login.getViewstates(page);
// recaptcha
- String recaptchaChallenge = null;
if (showCaptcha) {
final String recaptchaJsParam = TextUtils.getMatch(page, GCConstants.PATTERN_SEARCH_RECAPTCHA, false, null);
if (recaptchaJsParam != null) {
- final Parameters params = new Parameters("k", recaptchaJsParam.trim());
- final String recaptchaJs = Network.getResponseData(Network.getRequest("http://www.google.com/recaptcha/api/challenge", params));
+ thread.setKey(recaptchaJsParam.trim());
- if (StringUtils.isNotBlank(recaptchaJs)) {
- recaptchaChallenge = TextUtils.getMatch(recaptchaJs, GCConstants.PATTERN_SEARCH_RECAPTCHACHALLENGE, true, 1, null, true);
- }
+ thread.fetchChallenge();
}
- if (thread != null && StringUtils.isNotBlank(recaptchaChallenge)) {
- thread.setChallenge(recaptchaChallenge);
+ if (thread != null && StringUtils.isNotBlank(thread.getChallenge())) {
thread.notifyNeed();
}
}
@@ -276,7 +271,7 @@ public abstract class GCParser {
}
String recaptchaText = null;
- if (thread != null && recaptchaChallenge != null) {
+ if (thread != null && StringUtils.isNotBlank(thread.getChallenge())) {
if (thread.getText() == null) {
thread.waitForUser();
}
@@ -284,7 +279,7 @@ public abstract class GCParser {
recaptchaText = thread.getText();
}
- if (!cids.isEmpty() && (Settings.isPremiumMember() || showCaptcha) && (recaptchaChallenge == null || StringUtils.isNotBlank(recaptchaText))) {
+ if (!cids.isEmpty() && (Settings.isPremiumMember() || showCaptcha) && ((thread == null || StringUtils.isBlank(thread.getChallenge())) || StringUtils.isNotBlank(recaptchaText))) {
Log.i("Trying to get .loc for " + cids.size() + " caches");
try {
@@ -305,8 +300,8 @@ public abstract class GCParser {
params.put("CID", cid);
}
- if (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)) {
- params.put("recaptcha_challenge_field", recaptchaChallenge);
+ if (thread != null && StringUtils.isNotBlank(thread.getChallenge()) && StringUtils.isNotBlank(recaptchaText)) {
+ params.put("recaptcha_challenge_field", thread.getChallenge());
params.put("recaptcha_response_field", recaptchaText);
}
params.put("ctl00$ContentBody$uxDownloadLoc", "Download Waypoints");
diff --git a/main/src/cgeo/geocaching/connector/gc/Login.java b/main/src/cgeo/geocaching/connector/gc/Login.java
index 4b4c93f..2629339 100644
--- a/main/src/cgeo/geocaching/connector/gc/Login.java
+++ b/main/src/cgeo/geocaching/connector/gc/Login.java
@@ -1,13 +1,13 @@
package cgeo.geocaching.connector.gc;
import cgeo.geocaching.R;
-import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.network.Cookies;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
+import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.MatcherWrapper;
import cgeo.geocaching.utils.TextUtils;
@@ -68,8 +68,8 @@ public abstract class Login {
private static StatusCode login(boolean retry) {
final ImmutablePair<String, String> login = Settings.getGcLogin();
- if (login == null || StringUtils.isEmpty(login.left) || StringUtils.isEmpty(login.right)) {
- Login.setActualStatus(cgeoapplication.getInstance().getString(R.string.err_login));
+ if (StringUtils.isEmpty(login.left) || StringUtils.isEmpty(login.right)) {
+ clearLoginInfo();
Log.e("Login.login: No login information stored");
return StatusCode.NO_LOGIN_INFO_STORED;
}
@@ -153,9 +153,23 @@ public abstract class Login {
return StatusCode.MAINTENANCE;
}
+ resetLoginStatus();
+
+ return StatusCode.NO_ERROR;
+ }
+
+ private static void resetLoginStatus() {
Cookies.clearCookies();
Settings.setCookieStore(null);
- return StatusCode.NO_ERROR;
+
+ setActualLoginStatus(false);
+ }
+
+ private static void clearLoginInfo() {
+ resetLoginStatus();
+
+ setActualCachesFound(-1);
+ setActualStatus(cgeoapplication.getInstance().getString(R.string.err_login));
}
static void setActualCachesFound(final int found) {
@@ -475,7 +489,7 @@ public abstract class Login {
/**
* Unfortunately the cache details page contains user generated whitespace in the personal note, therefore we cannot
* remove the white space from cache details pages.
- *
+ *
* @param uri
* @return
*/
diff --git a/main/src/cgeo/geocaching/connector/gc/SearchHandler.java b/main/src/cgeo/geocaching/connector/gc/SearchHandler.java
index 45832e4..4358399 100644
--- a/main/src/cgeo/geocaching/connector/gc/SearchHandler.java
+++ b/main/src/cgeo/geocaching/connector/gc/SearchHandler.java
@@ -15,11 +15,13 @@ import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
+import android.widget.ImageButton;
import android.widget.ImageView;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.URL;
public class SearchHandler extends Handler {
@@ -37,7 +39,7 @@ public class SearchHandler extends Handler {
imageView.setImageBitmap(img);
}
} catch (Exception e) {
- // nothing
+ Log.e("Error setting reCAPTCHA image", e);
}
}
};
@@ -58,6 +60,20 @@ public class SearchHandler extends Handler {
imageView = (ImageView) view.findViewById(R.id.image);
+ ImageButton reloadButton = (ImageButton) view.findViewById(R.id.button_recaptcha_refresh);
+ reloadButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ recaptchaThread.fetchChallenge();
+ try {
+ (new GetCaptchaThread(new URL("http://www.google.com/recaptcha/api/image?c=" + recaptchaThread.getChallenge()))).start();
+ } catch (MalformedURLException e) {
+ Log.e("Bad reCAPTCHA image url", e);
+ }
+ }
+ });
+
(new GetCaptchaThread(new URL("http://www.google.com/recaptcha/api/image?c=" + recaptchaThread.getChallenge()))).start();
dlg.setTitle(res.getString(R.string.caches_recaptcha_title));
@@ -76,7 +92,7 @@ public class SearchHandler extends Handler {
dlg.create().show();
}
} catch (Exception e) {
- // nothing
+ Log.e("Error in reCAPTCHA handler", e);
}
}
@@ -90,6 +106,7 @@ public class SearchHandler extends Handler {
@Override
public void run() {
try {
+ Log.d("Getting reCAPTCHA image from: " + uri.toString());
HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
connection.setDoInput(true);
connection.connect();