aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java')
-rw-r--r--main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java42
1 files changed, 32 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java b/main/src/cgeo/geocaching/ui/logs/CacheLogsViewCreator.java
index 6855aab..e52003d 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,27 +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(final CacheDetailActivity cacheDetailActivity, final boolean allLogs) {
super(cacheDetailActivity);
+ this.cacheDetailActivity = cacheDetailActivity;
this.allLogs = allLogs;
}
- /**
- * May return null!
- *
- */
private Geocache getCache() {
- if (this.activity instanceof CacheDetailActivity) {
- final 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
@@ -94,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 (null == convertView) {
+ if (isOfflineLog(log)) {
+ holder.author.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity));
+ holder.text.setOnClickListener(new EditOfflineLogListener(getCache(), cacheDetailActivity));
+ }
+ }
+ }
+
+ 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;
}