diff options
Diffstat (limited to 'main/src/cgeo/geocaching/LogCacheActivity.java')
| -rw-r--r-- | main/src/cgeo/geocaching/LogCacheActivity.java | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java index 78ec82d..f17a008 100644 --- a/main/src/cgeo/geocaching/LogCacheActivity.java +++ b/main/src/cgeo/geocaching/LogCacheActivity.java @@ -19,7 +19,7 @@ import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import android.app.Activity; @@ -47,7 +47,6 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; -import java.util.Locale; public class LogCacheActivity extends AbstractLoggingActivity implements DateDialog.DateDialogParent { static final String EXTRAS_GEOCODE = "geocode"; @@ -80,7 +79,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia private ILoggingManager loggingManager; // Data to be saved while reconfiguring - private double rating; + private float rating; private LogType typeSelected; private Calendar date; private String imageCaption; @@ -215,13 +214,13 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia if (!postButton.isEnabled()) { return res.getString(R.string.log_post_not_possible); } - if (!Settings.isGCvoteLogin() || !cache.supportsGCVote()) { + if (!GCVote.isVotingPossible(cache)) { return res.getString(R.string.log_post); } - if (rating == 0) { - return res.getString(R.string.log_post_no_rate); + if (GCVote.isValidRating(rating)) { + return res.getString(R.string.log_post_rate) + " " + GCVote.getRatingText(rating) + "*"; } - return res.getString(R.string.log_post_rate) + " " + ratingTextValue(rating) + "*"; + return res.getString(R.string.log_post_no_rate); } @Override @@ -236,13 +235,13 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia } if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) { - cacheid = cgData.getCacheidForGeocode(geocode); + cacheid = DataStore.getCacheidForGeocode(geocode); } if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(cacheid)) { - geocode = cgData.getGeocodeForGuid(cacheid); + geocode = DataStore.getGeocodeForGuid(cacheid); } - cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); + cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); possibleLogTypes = cache.getPossibleLogTypes(); if (StringUtils.isNotBlank(cache.getName())) { @@ -262,7 +261,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia // Restore previous state if (savedInstanceState != null) { - rating = savedInstanceState.getDouble(SAVED_STATE_RATING); + rating = savedInstanceState.getFloat(SAVED_STATE_RATING); typeSelected = LogType.getById(savedInstanceState.getInt(SAVED_STATE_TYPE)); date.setTimeInMillis(savedInstanceState.getLong(SAVED_STATE_DATE)); imageCaption = savedInstanceState.getString(SAVED_STATE_IMAGE_CAPTION); @@ -270,7 +269,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia imageUri = Uri.parse(savedInstanceState.getString(SAVED_STATE_IMAGE_URI)); } else { // If log had been previously saved, load it now, otherwise initialize signature as needed - final LogEntry log = cgData.loadLogOffline(geocode); + final LogEntry log = DataStore.loadLogOffline(geocode); if (log != null) { typeSelected = log.type; date.setTime(new Date(log.date)); @@ -278,7 +277,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia } else if (StringUtils.isNotBlank(Settings.getSignature()) && Settings.isAutoInsertSignature() && StringUtils.isBlank(currentLogText())) { - insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache)), false); + insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(cache, null)), false); } } updatePostButtonText(); @@ -342,16 +341,20 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia private void setDefaultValues() { date = Calendar.getInstance(); - rating = 0.0; + rating = GCVote.NO_RATING; if (cache.isEventCache()) { final Date eventDate = cache.getHiddenDate(); - boolean expired = DateUtils.daysSince(eventDate.getTime()) >= 0; + boolean expired = DateUtils.isPastEvent(cache); if (cache.hasOwnLog(LogType.WILL_ATTEND) || expired) { typeSelected = cache.hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED; } else { typeSelected = LogType.WILL_ATTEND; } + // it this is an attended event log, use the event date by default instead of the current date + if (expired && typeSelected == LogType.ATTENDED) { + date.setTime(eventDate); + } } else { if (cache.isFound()) { typeSelected = LogType.NOTE; @@ -418,8 +421,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - final boolean voteAvailable = Settings.isGCvoteLogin() && StringUtils.isNotBlank(cache.getGuid()) && cache.supportsGCVote(); - menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable); + menu.findItem(SUBMENU_VOTE).setVisible(GCVote.isVotingPossible(cache)); return true; } @@ -432,9 +434,9 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia final int id = item.getItemId(); if (id >= 10 && id <= 19) { - rating = (id - 9) / 2.0; - if (rating < 1) { - rating = 0; + rating = (id - 9) / 2.0f; + if (!GCVote.isValidRating(rating)) { + rating = GCVote.NO_RATING; } updatePostButtonText(); return true; @@ -443,10 +445,6 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia return false; } - private static String ratingTextValue(final double rating) { - return String.format(Locale.getDefault(), "%.1f", rating); - } - @Override protected void onSaveInstanceState(final Bundle outState) { super.onSaveInstanceState(outState); @@ -533,7 +531,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia final LogResult logResult = loggingManager.postLog(cache, typeSelected, date, log, logPwd, trackables); if (logResult.getPostLogResult() == StatusCode.NO_ERROR) { - final LogEntry logNow = new LogEntry(date, typeSelected, log); + final LogEntry logNow = new LogEntry(date.getTimeInMillis(), typeSelected, log); cache.getLogs().add(0, logNow); @@ -542,15 +540,15 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia cache.setVisitedDate(new Date().getTime()); } - cgData.saveChangedCache(cache); + DataStore.saveChangedCache(cache); cache.clearOfflineLog(); if (typeSelected == LogType.FOUND_IT) { if (tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) { - Twitter.postTweetCache(geocode); + Twitter.postTweetCache(geocode, logNow); } } - if (rating > 0) { + if (GCVote.isValidRating(rating)) { GCVote.setRating(cache, rating); } @@ -559,14 +557,14 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia final String uploadedImageUrl = imageResult.getImageUri(); if (StringUtils.isNotEmpty(uploadedImageUrl)) { logNow.addLogImage(new Image(uploadedImageUrl, imageCaption, imageDescription)); - cgData.saveChangedCache(cache); + DataStore.saveChangedCache(cache); } return imageResult.getPostResult(); } } return logResult.getPostLogResult(); - } catch (Exception e) { + } catch (RuntimeException e) { Log.e("VisitCacheActivity.Poster.doInBackgroundInternal", e); } @@ -611,7 +609,7 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia @Override protected LogContext getLogContext() { - return new LogContext(cache); + return new LogContext(cache, null); } private void selectAllTrackablesAction() { |
