aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2013-03-30 20:21:01 +0100
committerBananeweizen <Bananeweizen@gmx.de>2013-03-30 20:21:01 +0100
commit32460d132a0906fd39e92c1ce1c5088920ddf23c (patch)
tree5994d33ebcda1738530233c8d7339d0adbfe59a8 /main
parentbd66d5eeb4ea95325630dae58aaf7f1043085781 (diff)
downloadcgeo-32460d132a0906fd39e92c1ce1c5088920ddf23c.zip
cgeo-32460d132a0906fd39e92c1ce1c5088920ddf23c.tar.gz
cgeo-32460d132a0906fd39e92c1ce1c5088920ddf23c.tar.bz2
refactoring of cache logging code
* simplify control flow * move sanity checks into GCVote and twitter methods
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/VisitCacheActivity.java32
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java5
-rw-r--r--main/src/cgeo/geocaching/gcvote/GCVote.java7
-rw-r--r--main/src/cgeo/geocaching/twitter/Twitter.java6
4 files changed, 28 insertions, 22 deletions
diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java
index d95f6df..8f47606 100644
--- a/main/src/cgeo/geocaching/VisitCacheActivity.java
+++ b/main/src/cgeo/geocaching/VisitCacheActivity.java
@@ -571,18 +571,16 @@ public class VisitCacheActivity extends AbstractLoggingActivity implements DateD
}
public StatusCode postLogFn(String log) {
-
StatusCode result = StatusCode.LOG_POST_ERROR;
try {
- final ImmutablePair<StatusCode, String> logResult = GCParser.postLog(geocode, cacheid, viewstates, typeSelected,
+ final ImmutablePair<StatusCode, String> postResult = GCParser.postLog(geocode, cacheid, viewstates, typeSelected,
date.get(Calendar.YEAR), (date.get(Calendar.MONTH) + 1), date.get(Calendar.DATE),
log, trackables);
+ result = postResult.left;
- result = logResult.left;
-
- if (logResult.left == StatusCode.NO_ERROR) {
+ if (result == StatusCode.NO_ERROR) {
final LogEntry logNow = new LogEntry(date, typeSelected, log);
cache.getLogs().add(0, logNow);
@@ -592,24 +590,18 @@ public class VisitCacheActivity extends AbstractLoggingActivity implements DateD
}
cgData.saveChangedCache(cache);
- }
-
- if (logResult.left == StatusCode.NO_ERROR) {
cgData.clearLogOffline(geocode);
- }
- if (logResult.left == StatusCode.NO_ERROR && typeSelected == LogType.FOUND_IT && Settings.isUseTwitter()
- && Settings.isTwitterLoginValid()
- && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
- Twitter.postTweetCache(geocode);
- }
-
- if (logResult.left == StatusCode.NO_ERROR && typeSelected == LogType.FOUND_IT && Settings.isGCvoteLogin()) {
- GCVote.setRating(cache, rating);
- }
+ if (typeSelected == LogType.FOUND_IT) {
+ if (tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
+ Twitter.postTweetCache(geocode);
+ }
+ GCVote.setRating(cache, rating);
+ }
- if (logResult.left == StatusCode.NO_ERROR && StringUtils.isNotBlank(imageUri.getPath())) {
- result = GCParser.uploadLogImage(logResult.right, imageCaption, imageDescription, imageUri);
+ if (StringUtils.isNotBlank(imageUri.getPath())) {
+ result = GCParser.uploadLogImage(postResult.right, imageCaption, imageDescription, imageUri);
+ }
}
return result;
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 9af9953..76351c1 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -1100,6 +1100,11 @@ public abstract class GCParser {
return StatusCode.LOGIMAGE_POST_ERROR;
}
+ /**
+ * Post a log to GC.com.
+ *
+ * @return status code of the upload and ID of the log
+ */
public static StatusCode postLogTrackable(final String tbid, final String trackingCode, final String[] viewstates,
final LogType logType, final int year, final int month, final int day, final String log) {
if (Login.isEmpty(viewstates)) {
diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java
index a053f31..f6cfb84 100644
--- a/main/src/cgeo/geocaching/gcvote/GCVote.java
+++ b/main/src/cgeo/geocaching/gcvote/GCVote.java
@@ -173,12 +173,15 @@ public final class GCVote {
/**
* Transmit user vote to gcvote.com
- *
+ *
* @param cache
* @param vote
- * @return
+ * @return {@code true} if the rating was submitted successfully
*/
public static boolean setRating(Geocache cache, double vote) {
+ if (!Settings.isGCvoteLogin()) {
+ return false;
+ }
if (!cache.supportsGCVote()) {
return false;
}
diff --git a/main/src/cgeo/geocaching/twitter/Twitter.java b/main/src/cgeo/geocaching/twitter/Twitter.java
index f30830e..d3b2718 100644
--- a/main/src/cgeo/geocaching/twitter/Twitter.java
+++ b/main/src/cgeo/geocaching/twitter/Twitter.java
@@ -56,6 +56,12 @@ public final class Twitter {
}
public static void postTweetCache(String geocode) {
+ if (!Settings.isUseTwitter()) {
+ return;
+ }
+ if (!Settings.isTwitterLoginValid()) {
+ return;
+ }
final Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
String status;
final String url = cache.getUrl();