aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-11-24 15:42:06 +0100
committerSamuel Tardieu <sam@rfc1149.net>2014-11-24 15:42:06 +0100
commite0e44802cdd1a5cc7faa112afe2e49f2d8e98393 (patch)
tree5dd7269faf678f69e7ea76b01d850a47457ebaa9 /main/src
parent0b5fc80537ba89395cfa94cf35a1655faafa8fc9 (diff)
downloadcgeo-e0e44802cdd1a5cc7faa112afe2e49f2d8e98393.zip
cgeo-e0e44802cdd1a5cc7faa112afe2e49f2d8e98393.tar.gz
cgeo-e0e44802cdd1a5cc7faa112afe2e49f2d8e98393.tar.bz2
fix #4492: GCVote not always shown in logging window
If the cache GUID is missing at online log time for a gc.com cache, it is retrieved from the log page.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/LogCacheActivity.java40
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConstants.java1
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java15
3 files changed, 35 insertions, 21 deletions
diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java
index 6cc8046..4c25679 100644
--- a/main/src/cgeo/geocaching/LogCacheActivity.java
+++ b/main/src/cgeo/geocaching/LogCacheActivity.java
@@ -85,10 +85,9 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia
private String imageDescription;
private Uri imageUri;
private boolean sendButtonEnabled;
-
+ private boolean isRatingBarShown = false;
public void onLoadFinished() {
-
if (loggingManager.hasLoaderError()) {
showErrorLoadingData();
return;
@@ -109,6 +108,8 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia
showToast(res.getString(R.string.info_log_type_changed));
}
+ initializeRatingBar();
+
enablePostButton(true);
initializeTrackablesAction();
@@ -230,8 +231,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia
tweetCheck = (CheckBox) findViewById(R.id.tweet);
logPasswordBox = (LinearLayout) findViewById(R.id.log_password_box);
- final RatingBar ratingBar = (RatingBar) findViewById(R.id.gcvoteRating);
- initializeRatingBar(ratingBar);
+ initializeRatingBar();
// initialize with default values
setDefaultValues();
@@ -289,25 +289,27 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia
requestKeyboardForLogging();
}
- private void initializeRatingBar(final RatingBar ratingBar) {
- final TextView label = (TextView) findViewById(R.id.gcvoteLabel);
- if (GCVote.isVotingPossible(cache)) {
+ private void initializeRatingBar() {
+ if (GCVote.isVotingPossible(cache) && !isRatingBarShown) {
+ final RatingBar ratingBar = (RatingBar) findViewById(R.id.gcvoteRating);
+ final TextView label = (TextView) findViewById(R.id.gcvoteLabel);
+ isRatingBarShown = true;
ratingBar.setVisibility(View.VISIBLE);
label.setVisibility(View.VISIBLE);
- }
- ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
+ ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
- @Override
- public void onRatingChanged(final RatingBar ratingBar, final float stars, final boolean fromUser) {
- // 0.5 is not a valid rating, therefore we must limit
- rating = GCVote.isValidRating(stars) ? stars : 0;
- if (rating < stars) {
- ratingBar.setRating(rating);
+ @Override
+ public void onRatingChanged(final RatingBar ratingBar, final float stars, final boolean fromUser) {
+ // 0.5 is not a valid rating, therefore we must limit
+ rating = GCVote.isValidRating(stars) ? stars : 0;
+ if (rating < stars) {
+ ratingBar.setRating(rating);
+ }
+ label.setText(GCVote.getDescription(rating));
}
- label.setText(GCVote.getDescription(rating));
- }
- });
- ratingBar.setRating(cache.getMyVote());
+ });
+ ratingBar.setRating(cache.getMyVote());
+ }
}
private void setDefaultValues() {
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
index 05639cf..332bf54 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -169,6 +169,7 @@ public final class GCConstants {
final static Pattern PATTERN_USERSESSION = Pattern.compile("UserSession\\('([^']+)'");
final static Pattern PATTERN_SESSIONTOKEN = Pattern.compile("sessionToken:'([^']+)'");
+ static final Pattern PATTERN_LOG_GUID = Pattern.compile("<a id=\"ctl00_ContentBody_LogBookPanel1_WaypointLink\"[^>]* href=\"https?://www\\.geocaching\\.com/seek/cache_details\\.aspx\\?guid=([0-9a-f-]+)\"");
final static Pattern PATTERN_LOG_IMAGE_UPLOAD = Pattern.compile("/seek/upload\\.aspx\\?LID=(\\d+)", Pattern.CASE_INSENSITIVE);
final static String STRING_PREMIUMONLY_2 = "Sorry, the owner of this listing has made it viewable to Premium Members only.";
diff --git a/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java b/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java
index ce32ac6..ffb4325 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCLoggingManager.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector.gc;
+import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogCacheActivity;
import cgeo.geocaching.R;
@@ -14,6 +15,7 @@ import cgeo.geocaching.loaders.UrlLoader;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.TextUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -55,14 +57,23 @@ class GCLoggingManager extends AbstractLoggingManager implements LoaderManager.L
@Override
public void onLoadFinished(final Loader<String> arg0, final String page) {
-
if (page == null) {
hasLoaderError = true;
} else {
-
viewstates = GCLogin.getViewstates(page);
trackables = GCParser.parseTrackableLog(page);
possibleLogTypes = GCParser.parseTypes(page);
+ if (StringUtils.isBlank(cache.getGuid())) {
+ // Acquire the cache GUID from the log page. This will not only complete the information in the database,
+ // but also allow the user to post a rating using GCVote since it requires the GUID to do so.
+ final String guid = TextUtils.getMatch(page, GCConstants.PATTERN_LOG_GUID, null);
+ if (StringUtils.isNotBlank(guid)) {
+ cache.setGuid(guid);
+ DataStore.saveChangedCache(cache);
+ } else {
+ Log.w("Could not acquire GUID from log page for " + cache.getGeocode());
+ }
+ }
hasLoaderError = possibleLogTypes.isEmpty();
}