aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-06-30 09:13:46 +0200
committerBananeweizen <bananeweizen@gmx.de>2012-06-30 09:13:46 +0200
commitd1399dadad3886d8b60eb271a7631699e61dd5ee (patch)
treea1d121c2971023cfe09d42614fb6eccefd7c16d9 /main
parent46dff33397a4f71578cdb921b64e120a2994a997 (diff)
downloadcgeo-d1399dadad3886d8b60eb271a7631699e61dd5ee.zip
cgeo-d1399dadad3886d8b60eb271a7631699e61dd5ee.tar.gz
cgeo-d1399dadad3886d8b60eb271a7631699e61dd5ee.tar.bz2
fix #1850: log summary starts with comma
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java50
1 files changed, 20 insertions, 30 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 6ee351c..e6be2b8 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -2109,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);
}
}