aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CacheDetailActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java123
1 files changed, 48 insertions, 75 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index d9b4e96..e6be2b8 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -12,15 +12,14 @@ import cgeo.geocaching.enumerations.CacheAttribute;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.HumanDistance;
-import cgeo.geocaching.geopoint.IConversion;
+import cgeo.geocaching.geopoint.Units;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.ui.CacheDetailsCreator;
import cgeo.geocaching.ui.DecryptTextClickListener;
import cgeo.geocaching.ui.Formatter;
+import cgeo.geocaching.ui.LoggingUI;
import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.ClipboardUtils;
@@ -46,7 +45,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -65,6 +63,7 @@ import android.text.Spannable;
import android.text.Spanned;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
+import android.text.style.ForegroundColorSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.view.ContextMenu;
@@ -139,20 +138,13 @@ public class CacheDetailActivity extends AbstractActivity {
final StringBuilder dist = new StringBuilder();
if (geo.getCoords() != null && cache != null && cache.getCoords() != null) {
- dist.append(HumanDistance.getHumanDistance(geo.getCoords().distanceTo(cache.getCoords())));
+ dist.append(Units.getDistanceFromKilometers(geo.getCoords().distanceTo(cache.getCoords())));
}
if (cache != null && cache.getElevation() != null) {
if (geo.getAltitude() != 0.0) {
- final double diff = cache.getElevation() - geo.getAltitude();
- dist.append(diff >= 0 ? " ↗" : " ↘");
- if (Settings.isUseMetricUnits()) {
- dist.append(Math.abs((int) diff));
- dist.append(" m");
- } else {
- dist.append(Math.abs((int) (diff * IConversion.METERS_TO_FEET)));
- dist.append(" ft");
- }
+ final float diff = (float) (cache.getElevation() - geo.getAltitude());
+ dist.append(' ').append(Units.getElevation(diff));
}
}
@@ -565,7 +557,7 @@ public class CacheDetailActivity extends AbstractActivity {
GeneralAppsFactory.addMenuItems(subMenu, cache);
menu.add(1, MENU_CALENDAR, 0, res.getString(R.string.cache_menu_event)).setIcon(R.drawable.ic_menu_agenda); // add event to calendar
- addVisitMenu(menu, cache);
+ LoggingUI.addMenuItems(menu, cache);
menu.add(0, MENU_CACHES_AROUND, 0, res.getString(R.string.cache_menu_around)).setIcon(R.drawable.ic_menu_rotate); // caches around
menu.add(1, MENU_BROWSER, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_globe); // browser
menu.add(0, MENU_SHARE, 0, res.getString(R.string.cache_menu_share)).setIcon(R.drawable.ic_menu_share); // share cache
@@ -593,10 +585,6 @@ public class CacheDetailActivity extends AbstractActivity {
case MENU_DEFAULT_NAVIGATION:
startDefaultNavigation();
return true;
- case MENU_LOG_VISIT:
- refreshOnResume = true;
- cache.logVisit(this);
- return true;
case MENU_BROWSER:
cache.openInBrowser(this);
return true;
@@ -619,8 +607,11 @@ public class CacheDetailActivity extends AbstractActivity {
if (GeneralAppsFactory.onMenuItemSelected(item, this, cache)) {
return true;
}
+ if (LoggingUI.onMenuItemSelected(item, this, cache)) {
+ refreshOnResume = true;
+ return true;
+ }
- cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
return true;
}
@@ -894,8 +885,8 @@ public class CacheDetailActivity extends AbstractActivity {
}
// Use real owner name vice the one owner chose to display
- if (StringUtils.isNotBlank(cache.getOwnerReal())) {
- clickedItemText = cache.getOwnerReal();
+ if (StringUtils.isNotBlank(cache.getOwnerUserId())) {
+ clickedItemText = cache.getOwnerUserId();
} else {
clickedItemText = ((TextView) view).getText().toString();
}
@@ -1344,6 +1335,9 @@ public class CacheDetailActivity extends AbstractActivity {
if (cache.isDisabled() || cache.isArchived()) { // strike
span.setSpan(new StrikethroughSpan(), 0, span.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
+ if (cache.isArchived()) {
+ span.setSpan(new ForegroundColorSpan(res.getColor(R.color.archived_cache_color)), 0, span.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
details.add(R.string.cache_name, span);
details.add(R.string.cache_type, cache.getType().getL10n());
@@ -1367,12 +1361,12 @@ public class CacheDetailActivity extends AbstractActivity {
}
// cache author
- if (StringUtils.isNotBlank(cache.getOwner()) || StringUtils.isNotBlank(cache.getOwnerReal())) {
+ if (StringUtils.isNotBlank(cache.getOwnerDisplayName()) || StringUtils.isNotBlank(cache.getOwnerUserId())) {
TextView ownerView = details.add(R.string.cache_owner, "");
- if (StringUtils.isNotBlank(cache.getOwner())) {
- ownerView.setText(cache.getOwner(), TextView.BufferType.SPANNABLE);
+ if (StringUtils.isNotBlank(cache.getOwnerDisplayName())) {
+ ownerView.setText(cache.getOwnerDisplayName(), TextView.BufferType.SPANNABLE);
} else { // OwnerReal guaranteed to be not blank based on above
- ownerView.setText(cache.getOwnerReal(), TextView.BufferType.SPANNABLE);
+ ownerView.setText(cache.getOwnerUserId(), TextView.BufferType.SPANNABLE);
}
ownerView.setOnClickListener(new OwnerActionsClickListener());
}
@@ -1830,7 +1824,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
private Bitmap decode(final cgCache cache) {
- return BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(cache.getGeocode(), "preview", false).getPath());
+ return StaticMapsProvider.getPreviewMap(cache.getGeocode());
}
@Override
@@ -2027,8 +2021,10 @@ public class CacheDetailActivity extends AbstractActivity {
publishProgress();
}
- // if description has HTML table, add a note at the end of the long description
- if (unknownTagsHandler.isTableDetected() && descriptionView == view.findViewById(R.id.longdesc)) {
+ // If description has an HTML construct which may be problematic to render, add a note at the end of the long description.
+ // Technically, it may not be a table, but a pre, which has the same problems as a table, so the message is ok even though
+ // sometimes technically incorrect.
+ if (unknownTagsHandler.isProblematicDetected() && descriptionView == view.findViewById(R.id.longdesc)) {
final int startPos = description.length();
((Editable) description).append("\n\n").append(res.getString(R.string.cache_description_table_note));
((Editable) description).setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
@@ -2113,43 +2109,33 @@ public class CacheDetailActivity extends AbstractActivity {
view = (ListView) getLayoutInflater().inflate(R.layout.cacheview_logs, null);
// log count
- if (cache.getLogCounts() != null) {
- final StringBuilder text = new StringBuilder(200);
- text.append(res.getString(R.string.cache_log_types));
- text.append(": ");
-
- // sort the log counts by type id ascending. that way the FOUND, DNF log types are the first and most visible ones
- final List<Entry<LogType, Integer>> sortedLogCounts = new ArrayList<Entry<LogType, Integer>>();
- for (Entry<LogType, Integer> entry : cache.getLogCounts().entrySet()) {
- sortedLogCounts.add(entry); // don't add these entries using addAll(), the iterator in the EntrySet can go wrong (see Findbugs)
+ final Map<LogType, Integer> logCounts = cache.getLogCounts();
+ if (logCounts != null) {
+ final List<Entry<LogType, Integer>> sortedLogCounts = new ArrayList<Entry<LogType, Integer>>(logCounts.size());
+ for (Entry<LogType, Integer> entry : logCounts.entrySet()) {
+ // it may happen that the label is unknown -> then avoid any output for this type
+ if (entry.getKey() != LogType.PUBLISH_LISTING && entry.getKey().getL10n() != null) {
+ sortedLogCounts.add(entry);
+ }
}
- Collections.sort(sortedLogCounts, new Comparator<Entry<LogType, Integer>>() {
-
- @Override
- public int compare(Entry<LogType, Integer> logCountItem1, Entry<LogType, Integer> logCountItem2) {
- return logCountItem1.getKey().compareTo(logCountItem2.getKey());
- }
- });
+ if (sortedLogCounts.size() > 0) {
+ // sort the log counts by type id ascending. that way the FOUND, DNF log types are the first and most visible ones
+ Collections.sort(sortedLogCounts, new Comparator<Entry<LogType, Integer>>() {
- boolean showLogCounter = false;
- for (Entry<LogType, Integer> pair : sortedLogCounts) {
- String logTypeLabel = pair.getKey().getL10n();
- // it may happen that the label is unknown -> then avoid any output for this type
- if (logTypeLabel != null && pair.getKey() != LogType.PUBLISH_LISTING) {
- if (showLogCounter) {
- text.append(", ");
+ @Override
+ public int compare(Entry<LogType, Integer> logCountItem1, Entry<LogType, Integer> logCountItem2) {
+ return logCountItem1.getKey().compareTo(logCountItem2.getKey());
}
- text.append(pair.getValue().intValue());
- text.append("× ");
- text.append(logTypeLabel);
+ });
+
+ ArrayList<String> labels = new ArrayList<String>(sortedLogCounts.size());
+ for (Entry<LogType, Integer> pair : sortedLogCounts) {
+ labels.add(pair.getValue().intValue() + "× " + pair.getKey().getL10n());
}
- showLogCounter = true;
- }
- if (showLogCounter) {
final TextView countView = new TextView(CacheDetailActivity.this);
- countView.setText(text.toString());
+ countView.setText(res.getString(R.string.cache_log_types) + ": " + StringUtils.join(labels, ", "));
view.addHeaderView(countView, null, false);
}
}
@@ -2317,23 +2303,10 @@ public class CacheDetailActivity extends AbstractActivity {
}
// info
- final List<String> infoTextList = new ArrayList<String>(3);
- if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(wpt.getWaypointType())) {
- infoTextList.add(wpt.getWaypointType().getL10n());
- }
- if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(wpt.getPrefix())) {
- infoTextList.add(res.getString(R.string.waypoint_custom));
- } else {
- if (StringUtils.isNotBlank(wpt.getPrefix())) {
- infoTextList.add(wpt.getPrefix());
- }
- if (StringUtils.isNotBlank(wpt.getLookup())) {
- infoTextList.add(wpt.getLookup());
- }
- }
- if (CollectionUtils.isNotEmpty(infoTextList)) {
+ final String waypointInfo = Formatter.formatWaypointInfo(wpt);
+ if (StringUtils.isNotBlank(waypointInfo)) {
final TextView infoView = (TextView) waypointView.findViewById(R.id.info);
- infoView.setText(StringUtils.join(infoTextList, Formatter.SEPARATOR));
+ infoView.setText(waypointInfo);
infoView.setVisibility(View.VISIBLE);
}