aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-10-05 11:24:18 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-10-05 11:43:37 +0200
commit9a9aa1e0c86a6a8ae224dfe0a50ad927136bf79d (patch)
treefa83edc61af2c33a2a39248abea20a9288033f6c /main/src
parent9bd05f7ffc6cf51d7f5c648eb205e2e0fcf01546 (diff)
downloadcgeo-9a9aa1e0c86a6a8ae224dfe0a50ad927136bf79d.zip
cgeo-9a9aa1e0c86a6a8ae224dfe0a50ad927136bf79d.tar.gz
cgeo-9a9aa1e0c86a6a8ae224dfe0a50ad927136bf79d.tar.bz2
Use symbolic errors instead of hardcoded integers
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/cgBase.java94
-rw-r--r--main/src/cgeo/geocaching/cgCacheWrap.java4
-rw-r--r--main/src/cgeo/geocaching/cgSearch.java4
-rw-r--r--main/src/cgeo/geocaching/cgTrackable.java4
-rw-r--r--main/src/cgeo/geocaching/cgeo.java13
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java5
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java11
-rw-r--r--main/src/cgeo/geocaching/cgeoinit.java18
-rw-r--r--main/src/cgeo/geocaching/cgeotouch.java65
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java4
-rw-r--r--main/src/cgeo/geocaching/cgeovisit.java60
-rw-r--r--main/src/cgeo/geocaching/connector/GCConnector.java2
-rw-r--r--main/src/cgeo/geocaching/enumerations/StatusCode.java50
13 files changed, 169 insertions, 165 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 03fa5fd..51bf807 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.files.LocParser;
import cgeo.geocaching.geopoint.DistanceParser;
@@ -137,7 +138,6 @@ public class cgBase {
public final static Map<Integer, String> logTypes2 = new HashMap<Integer, String>();
public final static Map<Integer, String> logTypesTrackable = new HashMap<Integer, String>();
public final static Map<Integer, String> logTypesTrackableAction = new HashMap<Integer, String>();
- public final static Map<Integer, String> errorRetrieve = new HashMap<Integer, String>();
public final static Map<String, SimpleDateFormat> gcCustomDateFormats;
static {
final String[] formats = new String[] {
@@ -334,17 +334,6 @@ public class cgBase {
logTypesTrackableAction.put(1, "_Visited"); // visit cache
logTypesTrackableAction.put(2, "_DroppedOff"); // drop here
- // retrieving errors (because of ____ )
- errorRetrieve.put(1, res.getString(R.string.err_none));
- errorRetrieve.put(0, res.getString(R.string.err_start));
- errorRetrieve.put(-1, res.getString(R.string.err_parse));
- errorRetrieve.put(-2, res.getString(R.string.err_server));
- errorRetrieve.put(-3, res.getString(R.string.err_login));
- errorRetrieve.put(-4, res.getString(R.string.err_unknown));
- errorRetrieve.put(-5, res.getString(R.string.err_comm));
- errorRetrieve.put(-6, res.getString(R.string.err_wrong));
- errorRetrieve.put(-7, res.getString(R.string.err_license));
-
// init
app = appIn;
@@ -479,7 +468,7 @@ public class cgBase {
}
}
- public static int login() {
+ public static StatusCode login() {
HttpResponse loginResponse = null;
String loginData = null;
@@ -488,7 +477,7 @@ public class cgBase {
final ImmutablePair<String, String> loginStart = Settings.getLogin();
if (loginStart == null) {
- return -3; // no login information stored
+ return StatusCode.NO_LOGIN_INFO_STORED; // no login information stored
}
loginResponse = request("https://www.geocaching.com/login/default.aspx", null, false, false, false);
@@ -499,25 +488,25 @@ public class cgBase {
switchToEnglish(viewstates);
- return 1; // logged in
+ return StatusCode.NO_ERROR; // logged in
}
viewstates = getViewstates(loginData);
if (isEmpty(viewstates)) {
Log.e(Settings.tag, "cgeoBase.login: Failed to find viewstates");
- return -1; // no viewstates
+ return StatusCode.LOGIN_PARSE_ERROR; // no viewstates
}
} else {
Log.e(Settings.tag, "cgeoBase.login: Failed to retrieve login page (1st)");
- return -2; // no loginpage
+ return StatusCode.CONNECTION_FAILED; // no loginpage
}
final ImmutablePair<String, String> login = Settings.getLogin();
if (login == null || StringUtils.isEmpty(login.left) || StringUtils.isEmpty(login.right)) {
Log.e(Settings.tag, "cgeoBase.login: No login information stored");
- return -3;
+ return StatusCode.NO_LOGIN_INFO_STORED;
}
clearCookies();
@@ -540,22 +529,22 @@ public class cgBase {
switchToEnglish(getViewstates(loginData));
- return 1; // logged in
+ return StatusCode.NO_ERROR; // logged in
} else {
if (loginData.contains("Your username/password combination does not match.")) {
Log.i(Settings.tag, "Failed to log in Geocaching.com as " + login.left + " because of wrong username/password");
- return -6; // wrong login
+ return StatusCode.WRONG_LOGIN_DATA; // wrong login
} else {
Log.i(Settings.tag, "Failed to log in Geocaching.com as " + login.left + " for some unknown reason");
- return -4; // can't login
+ return StatusCode.UNKNOWN_ERROR; // can't login
}
}
} else {
Log.e(Settings.tag, "cgeoBase.login: Failed to retrieve login page (2nd)");
- return -5; // no login page
+ return StatusCode.COMMUNICATION_ERROR; // no login page
}
}
@@ -918,7 +907,7 @@ public class cgBase {
if (coordinates.contains("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) {
Log.i(Settings.tag, "User has not agreed to the license agreement. Can\'t download .loc file.");
- caches.error = errorRetrieve.get(-7);
+ caches.error = StatusCode.UNAPPROVED_LICENSE;
return caches;
}
@@ -1060,17 +1049,17 @@ public class cgBase {
final cgCache cache = new cgCache();
if (page.contains("Cache is Unpublished")) {
- caches.error = "cache was unpublished";
+ caches.error = StatusCode.UNPUBLISHED_CACHE;
return caches;
}
if (page.contains("Sorry, the owner of this listing has made it viewable to Premium Members only.")) {
- caches.error = "requested cache is for premium members only";
+ caches.error = StatusCode.PREMIUM_ONLY;
return caches;
}
if (page.contains("has chosen to make this cache listing visible to Premium Members only.")) {
- caches.error = "requested cache is for premium members only";
+ caches.error = StatusCode.PREMIUM_ONLY;
return caches;
}
@@ -2163,13 +2152,13 @@ public class cgBase {
String page = getResponseData(postRequest(uri, params));
if (checkLogin(page) == false) {
- int loginState = login();
- if (loginState == 1) {
+ final StatusCode loginState = login();
+ if (loginState == StatusCode.NO_ERROR) {
page = getResponseData(postRequest(uri, params));
- } else if (loginState == -3) {
+ } else if (loginState == StatusCode.NO_LOGIN_INFO_STORED) {
Log.i(Settings.tag, "Working as guest.");
} else {
- app.setError(searchId, errorRetrieve.get(loginState));
+ app.setError(searchId, loginState);
Log.e(Settings.tag, "cgeoBase.searchByNextPage: Can not log in geocaching");
return searchId;
}
@@ -2442,7 +2431,7 @@ public class cgBase {
public static List<cgCache> processSearchResults(final cgSearch search, final cgCacheWrap caches, final boolean excludeDisabled, final boolean excludeMine, final String cacheType) {
List<cgCache> cacheList = new ArrayList<cgCache>();
if (caches != null) {
- if (StringUtils.isNotBlank(caches.error)) {
+ if (caches.error != null) {
search.error = caches.error;
}
if (StringUtils.isNotBlank(caches.url)) {
@@ -2499,22 +2488,22 @@ public class cgBase {
return trackable;
}
- public static int postLog(final cgeoapplication app, final String geocode, final String cacheid, final String[] viewstates,
+ public static StatusCode postLog(final cgeoapplication app, final String geocode, final String cacheid, final String[] viewstates,
final int logType, final int year, final int month, final int day,
final String log, final List<cgTrackableLog> trackables) {
if (isEmpty(viewstates)) {
Log.e(Settings.tag, "cgeoBase.postLog: No viewstate given");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
if (logTypes2.containsKey(logType) == false) {
Log.e(Settings.tag, "cgeoBase.postLog: Unknown logtype");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
if (StringUtils.isBlank(log)) {
Log.e(Settings.tag, "cgeoBase.postLog: No log text given");
- return 1001;
+ return StatusCode.NO_LOG_TEXT;
}
// fix log (non-Latin characters converted to HTML entities)
@@ -2573,8 +2562,8 @@ public class cgBase {
final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/seek/log.aspx").encodedQuery("ID=" + cacheid).build().toString();
String page = getResponseData(postRequest(uri, params));
if (!checkLogin(page)) {
- int loginState = login();
- if (loginState == 1) {
+ final StatusCode loginState = login();
+ if (loginState == StatusCode.NO_ERROR) {
page = getResponseData(postRequest(uri, params));
} else {
Log.e(Settings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")");
@@ -2584,7 +2573,7 @@ public class cgBase {
if (StringUtils.isBlank(page)) {
Log.e(Settings.tag, "cgeoBase.postLog: No data from server");
- return 1002;
+ return StatusCode.NO_DATA_FROM_SERVER;
}
// maintenance, archived needs to be confirmed
@@ -2597,7 +2586,7 @@ public class cgBase {
if (isEmpty(viewstatesConfirm)) {
Log.e(Settings.tag, "cgeoBase.postLog: No viewstate for confirm log");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
params.clear();
@@ -2648,31 +2637,31 @@ public class cgBase {
app.saveVisitDate(geocode);
}
- return 1;
+ return StatusCode.NO_ERROR;
}
} catch (Exception e) {
Log.e(Settings.tag, "cgeoBase.postLog.check: " + e.toString());
}
Log.e(Settings.tag, "cgeoBase.postLog: Failed to post log because of unknown error");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
- public static int postLogTrackable(final String tbid, final String trackingCode, final String[] viewstates,
+ public static StatusCode postLogTrackable(final String tbid, final String trackingCode, final String[] viewstates,
final int logType, final int year, final int month, final int day, final String log) {
if (isEmpty(viewstates)) {
Log.e(Settings.tag, "cgeoBase.postLogTrackable: No viewstate given");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
if (logTypes2.containsKey(logType) == false) {
Log.e(Settings.tag, "cgeoBase.postLogTrackable: Unknown logtype");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
if (StringUtils.isBlank(log)) {
Log.e(Settings.tag, "cgeoBase.postLogTrackable: No log text given");
- return 1001;
+ return StatusCode.NO_LOG_TEXT;
}
Log.i(Settings.tag, "Trying to post log for trackable #" + trackingCode + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log);
@@ -2703,8 +2692,8 @@ public class cgBase {
final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/track/log.aspx").encodedQuery("wid=" + tbid).build().toString();
String page = getResponseData(postRequest(uri, params));
if (checkLogin(page) == false) {
- int loginState = login();
- if (loginState == 1) {
+ final StatusCode loginState = login();
+ if (loginState == StatusCode.NO_ERROR) {
page = getResponseData(postRequest(uri, params));
} else {
Log.e(Settings.tag, "cgeoBase.postLogTrackable: Can not log in geocaching (error: " + loginState + ")");
@@ -2714,7 +2703,7 @@ public class cgBase {
if (StringUtils.isBlank(page)) {
Log.e(Settings.tag, "cgeoBase.postLogTrackable: No data from server");
- return 1002;
+ return StatusCode.NO_DATA_FROM_SERVER;
}
try {
@@ -2722,14 +2711,14 @@ public class cgBase {
final Matcher matcherOk = patternOk.matcher(page);
if (matcherOk.find()) {
Log.i(Settings.tag, "Log successfully posted to trackable #" + trackingCode);
- return 1;
+ return StatusCode.NO_ERROR;
}
} catch (Exception e) {
Log.e(Settings.tag, "cgeoBase.postLogTrackable.check: " + e.toString());
}
Log.e(Settings.tag, "cgeoBase.postLogTrackable: Failed to post log because of unknown error");
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
/**
@@ -2902,7 +2891,7 @@ public class cgBase {
public static String postRequestLogged(final String uri) {
final String data = getResponseData(postRequest(uri, null));
if (!checkLogin(data)) {
- if (login() == 1) {
+ if (login() == StatusCode.NO_ERROR) {
return getResponseData(postRequest(uri, null));
} else {
Log.i(Settings.tag, "Working as guest.");
@@ -2916,8 +2905,7 @@ public class cgBase {
String data = getResponseData(response);
if (checkLogin(data) == false) {
- int loginState = login();
- if (loginState == 1) {
+ if (login() == StatusCode.NO_ERROR) {
response = request(uri, params, xContentType, my, addF);
data = getResponseData(response);
} else {
diff --git a/main/src/cgeo/geocaching/cgCacheWrap.java b/main/src/cgeo/geocaching/cgCacheWrap.java
index e8668b5..b1ccb12 100644
--- a/main/src/cgeo/geocaching/cgCacheWrap.java
+++ b/main/src/cgeo/geocaching/cgCacheWrap.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.StatusCode;
+
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +9,7 @@ import java.util.List;
* List of caches
*/
public class cgCacheWrap {
- public String error = null;
+ public StatusCode error = null;
public String url = "";
public String[] viewstates = null;
public int totalCnt = 0;
diff --git a/main/src/cgeo/geocaching/cgSearch.java b/main/src/cgeo/geocaching/cgSearch.java
index 75c5572..fb217fb 100644
--- a/main/src/cgeo/geocaching/cgSearch.java
+++ b/main/src/cgeo/geocaching/cgSearch.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.StatusCode;
+
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -8,7 +10,7 @@ public class cgSearch {
private UUID id;
private List<String> geocodes = new ArrayList<String>();
- public String error = null;
+ public StatusCode error = null;
public String url = "";
public String[] viewstates = null;
public int totalCnt = 0;
diff --git a/main/src/cgeo/geocaching/cgTrackable.java b/main/src/cgeo/geocaching/cgTrackable.java
index 2cdca39..2a46ed2 100644
--- a/main/src/cgeo/geocaching/cgTrackable.java
+++ b/main/src/cgeo/geocaching/cgTrackable.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.StatusCode;
+
import android.text.Spannable;
import java.util.ArrayList;
@@ -13,7 +15,7 @@ public class cgTrackable {
static final public int SPOTTED_UNKNOWN = 3;
static final public int SPOTTED_OWNER = 4;
- public int errorRetrieve = 0;
+ public StatusCode errorRetrieve = null;
public String error = "";
public String guid = "";
public String geocode = "";
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index d68d07a..5c8c9f1 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -2,6 +2,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.ActivityMixin;
+import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.utils.CollectionUtils;
@@ -129,9 +130,9 @@ public class cgeo extends AbstractActivity {
@Override
public void handleMessage(Message msg) {
try {
- int reason = msg.what;
+ final StatusCode reason = (StatusCode) msg.obj;
- if (reason < 0) { //LoginFailed
+ if (reason != null && reason != StatusCode.NO_ERROR) { //LoginFailed
showToast(res.getString(R.string.err_login_failed_toast));
}
} catch (Exception e) {
@@ -730,19 +731,19 @@ public class cgeo extends AbstractActivity {
return;
}
- final int status = cgBase.login();
+ final StatusCode status = cgBase.login();
- if (status == 1) {
+ if (status == StatusCode.NO_ERROR) {
app.firstRun = false;
cgBase.detectGcCustomDate();
}
if (app.showLoginToast) {
- firstLoginHandler.sendEmptyMessage(status);
+ firstLoginHandler.sendMessage(firstLoginHandler.obtainMessage(0, status));
app.showLoginToast = false;
// invoke settings activity to insert login details
- if (status == -3) {
+ if (status == StatusCode.NO_LOGIN_INFO_STORED) {
final Context context = cgeo.this;
final Intent initIntent = new Intent(context, cgeoinit.class);
context.startActivity(initIntent);
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index 073ca43..c1524aa 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -1,5 +1,6 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.lang3.StringUtils;
@@ -215,7 +216,7 @@ public class cgeoapplication extends Application {
return getStorage().getCacheidForGeocode(geocode);
}
- public String getError(final UUID searchId) {
+ public StatusCode getError(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -223,7 +224,7 @@ public class cgeoapplication extends Application {
return searches.get(searchId).error;
}
- public boolean setError(final UUID searchId, String error) {
+ public boolean setError(final UUID searchId, final StatusCode error) {
if (searchId == null || searches.containsKey(searchId) == false) {
return false;
}
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index 02554d5..3e57fbd 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.apps.cachelist.CacheListAppFactory;
import cgeo.geocaching.enumerations.CacheSize;
+import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.filter.cgFilter;
import cgeo.geocaching.filter.cgFilterBySize;
import cgeo.geocaching.filter.cgFilterByTrackables;
@@ -211,7 +212,7 @@ public class cgeocaches extends AbstractListActivity {
}
}
- if (cacheList != null && app.getError(searchId) != null && app.getError(searchId).equalsIgnoreCase(cgBase.errorRetrieve.get(-7))) {
+ if (cacheList != null && app.getError(searchId) == StatusCode.UNAPPROVED_LICENSE) {
AlertDialog.Builder dialog = new AlertDialog.Builder(cgeocaches.this);
dialog.setTitle(res.getString(R.string.license));
dialog.setMessage(res.getString(R.string.err_license));
@@ -233,8 +234,8 @@ public class cgeocaches extends AbstractListActivity {
AlertDialog alert = dialog.create();
alert.show();
- } else if (app != null && StringUtils.isNotBlank(app.getError(searchId))) {
- showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + ".");
+ } else if (app != null && app.getError(searchId) != null) {
+ showToast(res.getString(R.string.err_download_fail) + app.getError(searchId).getErrorString(res) + ".");
hideLoading();
showProgress(false);
@@ -310,8 +311,8 @@ public class cgeocaches extends AbstractListActivity {
}
}
- if (StringUtils.isNotBlank(app.getError(searchId))) {
- showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + ".");
+ if (app.getError(searchId) != null) {
+ showToast(res.getString(R.string.err_download_fail) + app.getError(searchId).getErrorString(res) + ".");
listFooter.setOnClickListener(new moreCachesListener());
hideLoading();
diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java
index e92ba6b..7a15743 100644
--- a/main/src/cgeo/geocaching/cgeoinit.java
+++ b/main/src/cgeo/geocaching/cgeoinit.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.LogTemplateProvider.LogTemplate;
import cgeo.geocaching.Settings.mapSourceEnum;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.compatibility.Compatibility;
+import cgeo.geocaching.enumerations.StatusCode;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
@@ -49,15 +50,12 @@ public class cgeoinit extends AbstractActivity {
loginDialog.dismiss();
}
- if (msg.what == 1) {
+ final StatusCode error = (StatusCode) msg.obj;
+ if (error == null || error == StatusCode.NO_ERROR) {
helpDialog(res.getString(R.string.init_login_popup), res.getString(R.string.init_login_popup_ok));
} else {
- if (cgBase.errorRetrieve.containsKey(msg.what)) {
- helpDialog(res.getString(R.string.init_login_popup),
- res.getString(R.string.init_login_popup_failed_reason) + " " + cgBase.errorRetrieve.get(msg.what) + ".");
- } else {
- helpDialog(res.getString(R.string.init_login_popup), res.getString(R.string.init_login_popup_failed));
- }
+ helpDialog(res.getString(R.string.init_login_popup),
+ res.getString(R.string.init_login_popup_failed_reason) + " " + error.getErrorString(res) + ".");
}
} catch (Exception e) {
showToast(res.getString(R.string.err_login_failed));
@@ -688,12 +686,12 @@ public class cgeoinit extends AbstractActivity {
@Override
public void run() {
- final int loginResult = cgBase.login();
- if (1 == loginResult)
+ final StatusCode loginResult = cgBase.login();
+ if (loginResult == StatusCode.NO_ERROR)
{
cgBase.detectGcCustomDate();
}
- logInHandler.sendEmptyMessage(loginResult);
+ logInHandler.sendMessage(logInHandler.obtainMessage(0, loginResult));
}
}).start();
}
diff --git a/main/src/cgeo/geocaching/cgeotouch.java b/main/src/cgeo/geocaching/cgeotouch.java
index 9a2ddb3..fc9b255 100644
--- a/main/src/cgeo/geocaching/cgeotouch.java
+++ b/main/src/cgeo/geocaching/cgeotouch.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import cgeo.geocaching.enumerations.StatusCode;
+
import org.apache.commons.lang3.StringUtils;
import android.app.Dialog;
@@ -76,32 +78,16 @@ public class cgeotouch extends cgLogForm {
private Handler postLogHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- if (msg.what == 1) {
- showToast(res.getString(R.string.info_log_posted));
+ if (waitDialog != null) {
+ waitDialog.dismiss();
+ }
- if (waitDialog != null) {
- waitDialog.dismiss();
- }
+ final StatusCode error = (StatusCode) msg.obj;
+ if (error == StatusCode.NO_ERROR) {
+ showToast(res.getString(R.string.info_log_posted));
finish();
- return;
- } else if (msg.what >= 1000) {
- if (msg.what == 1001) {
- showToast(res.getString(R.string.warn_log_text_fill));
- } else if (msg.what == 1002) {
- showToast(res.getString(R.string.err_log_failed_server));
- } else {
- showToast(res.getString(R.string.err_log_post_failed));
- }
} else {
- if (cgBase.errorRetrieve.get(msg.what) != null) {
- showToast(res.getString(R.string.err_log_post_failed_because) + cgBase.errorRetrieve.get(msg.what) + ".");
- } else {
- showToast(res.getString(R.string.err_log_post_failed));
- }
- }
-
- if (waitDialog != null) {
- waitDialog.dismiss();
+ showToast(error.getErrorString(res));
}
}
};
@@ -417,29 +403,24 @@ public class cgeotouch extends cgLogForm {
}
private class postLog extends Thread {
- Handler handler = null;
- String tracking = null;
- String log = null;
-
- public postLog(Handler handlerIn, String trackingIn, String logIn) {
- handler = handlerIn;
- tracking = trackingIn;
- log = logIn;
+ final private Handler handler;
+ final private String tracking;
+ final private String log;
+
+ public postLog(final Handler handler, final String tracking, final String log) {
+ this.handler = handler;
+ this.tracking = tracking;
+ this.log = log;
}
@Override
public void run() {
- int ret = -1;
-
- ret = postLogFn(tracking, log);
-
- handler.sendEmptyMessage(ret);
+ final StatusCode error = postLogFn(tracking, log);
+ handler.sendMessage(handler.obtainMessage(0, error));
}
}
- public int postLogFn(String tracking, String log) {
- int status = -1;
-
+ public StatusCode postLogFn(String tracking, String log) {
try {
if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
@@ -448,9 +429,9 @@ public class cgeotouch extends cgLogForm {
tweetCheck = (CheckBox) findViewById(R.id.tweet);
}
- status = cgBase.postLogTrackable(guid, tracking, viewstates, typeSelected, date.get(Calendar.YEAR), (date.get(Calendar.MONTH) + 1), date.get(Calendar.DATE), log);
+ final StatusCode status = cgBase.postLogTrackable(guid, tracking, viewstates, typeSelected, date.get(Calendar.YEAR), (date.get(Calendar.MONTH) + 1), date.get(Calendar.DATE), log);
- if (status == 1 && Settings.isUseTwitter() &&
+ if (status == StatusCode.NO_ERROR && Settings.isUseTwitter() &&
Settings.isTwitterLoginValid() &&
tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
cgBase.postTweetTrackable(app, geocode);
@@ -461,6 +442,6 @@ public class cgeotouch extends cgLogForm {
Log.e(Settings.tag, "cgeotouch.postLogFn: " + e.toString());
}
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
}
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index a10a8ce..cfeac98 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -46,8 +46,8 @@ public class cgeotrackable extends AbstractActivity {
TextView itemName;
TextView itemValue;
- if (trackable != null && trackable.errorRetrieve != 0) {
- showToast(res.getString(R.string.err_tb_details_download) + " " + cgBase.errorRetrieve.get(trackable.errorRetrieve) + ".");
+ if (trackable != null && trackable.errorRetrieve != null) {
+ showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.errorRetrieve.getErrorString(res) + ".");
finish();
return;
diff --git a/main/src/cgeo/geocaching/cgeovisit.java b/main/src/cgeo/geocaching/cgeovisit.java
index f22203c..5ab8dbe 100644
--- a/main/src/cgeo/geocaching/cgeovisit.java
+++ b/main/src/cgeo/geocaching/cgeovisit.java
@@ -1,6 +1,7 @@
package cgeo.geocaching;
import cgeo.geocaching.LogTemplateProvider.LogTemplate;
+import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.utils.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -176,19 +177,18 @@ public class cgeovisit extends cgLogForm {
private Handler postLogHandler = new Handler() {
@Override
- public void handleMessage(Message msg) {
- if (msg.what == 1) {
- showToast(res.getString(R.string.info_log_posted));
-
- if (waitDialog != null) {
- waitDialog.dismiss();
- }
+ public void handleMessage(final Message msg) {
+ if (waitDialog != null) {
+ waitDialog.dismiss();
+ }
+ final StatusCode error = (StatusCode) msg.obj;
+ if (error == StatusCode.NO_ERROR) {
+ showToast(res.getString(R.string.info_log_posted));
// No need to save the log when quitting if it has been posted.
text = currentLogText();
finish();
- return;
- } else if (msg.what == 2) {
+ } else if (error == StatusCode.LOG_SAVED) {
showToast(res.getString(R.string.info_log_saved));
if (waitDialog != null) {
@@ -196,25 +196,8 @@ public class cgeovisit extends cgLogForm {
}
finish();
- return;
- } else if (msg.what >= 1000) {
- if (msg.what == 1001) {
- showToast(res.getString(R.string.warn_log_text_fill));
- } else if (msg.what == 1002) {
- showToast(res.getString(R.string.err_log_failed_server));
- } else {
- showToast(res.getString(R.string.err_log_post_failed));
- }
} else {
- if (cgBase.errorRetrieve.get(msg.what) != null) {
- showToast(res.getString(R.string.err_log_post_failed_because) + " " + cgBase.errorRetrieve.get(msg.what) + ".");
- } else {
- showToast(res.getString(R.string.err_log_post_failed));
- }
- }
-
- if (waitDialog != null) {
- waitDialog.dismiss();
+ showToast(error.getErrorString(res));
}
}
};
@@ -717,17 +700,12 @@ public class cgeovisit extends cgLogForm {
@Override
public void run() {
- int ret = -1;
-
- ret = postLogFn(log);
-
- handler.sendEmptyMessage(ret);
+ final StatusCode status = postLogFn(log);
+ handler.sendMessage(handler.obtainMessage(0, status));
}
}
- public int postLogFn(String log) {
- int status = -1;
-
+ public StatusCode postLogFn(String log) {
try {
if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
@@ -736,11 +714,11 @@ public class cgeovisit extends cgLogForm {
tweetCheck = (CheckBox) findViewById(R.id.tweet);
}
- status = cgBase.postLog(app, geocode, cacheid, viewstates, typeSelected,
+ final StatusCode status = cgBase.postLog(app, geocode, cacheid, viewstates, typeSelected,
date.get(Calendar.YEAR), (date.get(Calendar.MONTH) + 1), date.get(Calendar.DATE),
log, trackables);
- if (status == 1) {
+ if (status == StatusCode.NO_ERROR) {
cgLog logNow = new cgLog();
logNow.author = Settings.getUsername();
logNow.date = date.getTimeInMillis();
@@ -766,17 +744,17 @@ public class cgeovisit extends cgLogForm {
}
}
- if (status == 1) {
+ if (status == StatusCode.NO_ERROR) {
app.clearLogOffline(geocode);
}
- if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && Settings.isUseTwitter()
+ if (status == StatusCode.NO_ERROR && typeSelected == cgBase.LOG_FOUND_IT && Settings.isUseTwitter()
&& Settings.isTwitterLoginValid()
&& tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
cgBase.postTweetCache(app, geocode);
}
- if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && Settings.isGCvoteLogin()) {
+ if (status == StatusCode.NO_ERROR && typeSelected == cgBase.LOG_FOUND_IT && Settings.isGCvoteLogin()) {
GCVote.setRating(cache, rating);
}
@@ -785,7 +763,7 @@ public class cgeovisit extends cgLogForm {
Log.e(Settings.tag, "cgeovisit.postLogFn: " + e.toString());
}
- return 1000;
+ return StatusCode.LOG_POST_ERROR;
}
private void saveLog(final boolean force) {
diff --git a/main/src/cgeo/geocaching/connector/GCConnector.java b/main/src/cgeo/geocaching/connector/GCConnector.java
index bd5e196..c635766 100644
--- a/main/src/cgeo/geocaching/connector/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/GCConnector.java
@@ -101,7 +101,7 @@ public class GCConnector extends AbstractConnector implements IConnector {
final cgCacheWrap caches = cgBase.parseCache(page, reason);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- if (caches != null && StringUtils.isNotBlank(caches.error)) {
+ if (caches != null && caches.error != null) {
search.error = caches.error;
}
if (caches != null && StringUtils.isNotBlank(caches.url)) {
diff --git a/main/src/cgeo/geocaching/enumerations/StatusCode.java b/main/src/cgeo/geocaching/enumerations/StatusCode.java
new file mode 100644
index 0000000..239d9bc
--- /dev/null
+++ b/main/src/cgeo/geocaching/enumerations/StatusCode.java
@@ -0,0 +1,50 @@
+package cgeo.geocaching.enumerations;
+
+import cgeo.geocaching.R;
+
+import android.content.Context;
+import android.content.res.Resources;
+
+public enum StatusCode {
+
+ COMMUNICATION_NOT_STARTED(0, R.string.err_start),
+ NO_ERROR(1, R.string.err_none),
+ LOG_SAVED(2, R.string.info_log_saved),
+ LOGIN_PARSE_ERROR(-1, R.string.err_parse),
+ CONNECTION_FAILED(-2, R.string.err_server),
+ NO_LOGIN_INFO_STORED(-3, R.string.err_login),
+ UNKNOWN_ERROR(-4, R.string.err_unknown),
+ COMMUNICATION_ERROR(-5, R.string.err_comm),
+ WRONG_LOGIN_DATA(-6, R.string.err_wrong),
+ UNAPPROVED_LICENSE(-7, R.string.err_license),
+ UNPUBLISHED_CACHE(-8, R.string.err_unpublished),
+ PREMIUM_ONLY(-9, R.string.err_premium_only),
+ LOG_POST_ERROR(1000, R.string.err_log_post_failed),
+ NO_LOG_TEXT(1001, R.string.warn_log_text_fill),
+ NO_DATA_FROM_SERVER(1002, R.string.err_log_failed_server);
+
+ final private int error_code;
+ final private int error_string;
+
+ StatusCode(int error_code, int error_string) {
+ this.error_code = error_code;
+ this.error_string = error_string;
+ }
+
+ public int getCode() {
+ return error_code;
+ }
+
+ public int getErrorString() {
+ return error_string;
+ }
+
+ public String getErrorString(final Resources res) {
+ return res.getString(error_string);
+ }
+
+ public String getErrorString(final Context context) {
+ return getErrorString(context.getResources());
+ }
+
+}