diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java')
-rw-r--r-- | main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java index 7e49c97..076c412 100644 --- a/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java +++ b/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java @@ -2,6 +2,7 @@ package cgeo.geocaching.ui.logs; import cgeo.geocaching.CacheDetailActivity; import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; import cgeo.geocaching.R; @@ -24,28 +25,33 @@ import java.util.Map.Entry; public class CacheLogsViewCreator extends LogsViewCreator { private final boolean allLogs; private final Resources res = CgeoApplication.getInstance().getResources(); + private final CacheDetailActivity cacheDetailActivity; - public CacheLogsViewCreator(CacheDetailActivity cacheDetailActivity, boolean allLogs) { + public CacheLogsViewCreator(final CacheDetailActivity cacheDetailActivity, final boolean allLogs) { super(cacheDetailActivity); + this.cacheDetailActivity = cacheDetailActivity; this.allLogs = allLogs; } - /** - * May return null! - * - * @return - */ private Geocache getCache() { - if (this.activity instanceof CacheDetailActivity) { - CacheDetailActivity details = (CacheDetailActivity) this.activity; - return details.getCache(); - } - return null; + return cacheDetailActivity.getCache(); } @Override protected List<LogEntry> getLogs() { - return allLogs ? getCache().getLogs() : getCache().getFriendsLogs(); + final Geocache cache = getCache(); + final List<LogEntry> logs = allLogs ? cache.getLogs() : cache.getFriendsLogs(); + return addOwnOfflineLog(cache, logs); + } + + private List<LogEntry> addOwnOfflineLog(final Geocache cache, final List<LogEntry> logsIn) { + final LogEntry log = DataStore.loadLogOffline(cache.getGeocode()); + final ArrayList<LogEntry> logs = new ArrayList<>(logsIn); + if (log != null) { + log.author = res.getString(R.string.log_your_saved_log); + logs.add(0, log); + } + return logs; } @Override @@ -56,7 +62,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { final List<Entry<LogType, Integer>> sortedLogCounts = new ArrayList<>(logCounts.size()); for (final 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 && entry.getValue() != 0) { + if (entry.getKey() != LogType.PUBLISH_LISTING && entry.getValue() != 0) { sortedLogCounts.add(entry); } } @@ -66,7 +72,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { Collections.sort(sortedLogCounts, new Comparator<Entry<LogType, Integer>>() { @Override - public int compare(Entry<LogType, Integer> logCountItem1, Entry<LogType, Integer> logCountItem2) { + public int compare(final Entry<LogType, Integer> logCountItem1, final Entry<LogType, Integer> logCountItem2) { return logCountItem1.getKey().compareTo(logCountItem2.getKey()); } }); @@ -84,7 +90,7 @@ public class CacheLogsViewCreator extends LogsViewCreator { } @Override - protected void fillCountOrLocation(LogViewHolder holder, final LogEntry log) { + protected void fillCountOrLocation(final LogViewHolder holder, final LogEntry log) { // finds count if (log.found == -1) { holder.countOrLocation.setVisibility(View.GONE); @@ -95,6 +101,21 @@ public class CacheLogsViewCreator extends LogsViewCreator { } @Override + protected void fillViewHolder(final View convertView, final LogViewHolder holder, final LogEntry log) { + super.fillViewHolder(convertView, holder, log); + if (isOfflineLog(log)) { + holder.author.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity)); + holder.text.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity)); + holder.marker.setVisibility(View.VISIBLE); + holder.marker.setImageResource(R.drawable.mark_orange); + } + } + + private boolean isOfflineLog(final LogEntry log) { + return log.author.equals(activity.getString(R.string.log_your_saved_log)); + } + + @Override protected boolean isValid() { return getCache() != null; } |