aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
-rw-r--r--main/src/cgeo/geocaching/utils/LogTemplateProvider.java53
1 files changed, 34 insertions, 19 deletions
diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
index 2d4fc80..1ddede5 100644
--- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
@@ -36,9 +36,9 @@ public final class LogTemplateProvider {
private Geocache cache;
private Trackable trackable;
private boolean offline = false;
- private LogEntry logEntry;
+ private final LogEntry logEntry;
- public LogContext(final Geocache cache, LogEntry logEntry) {
+ public LogContext(final Geocache cache, final LogEntry logEntry) {
this(cache, logEntry, false);
}
@@ -47,7 +47,7 @@ public final class LogTemplateProvider {
this.logEntry = logEntry;
}
- public LogContext(final Geocache cache, LogEntry logEntry, final boolean offline) {
+ public LogContext(final Geocache cache, final LogEntry logEntry, final boolean offline) {
this.cache = cache;
this.offline = offline;
this.logEntry = logEntry;
@@ -104,8 +104,11 @@ public final class LogTemplateProvider {
}
}
- public static ArrayList<LogTemplate> getTemplates() {
- ArrayList<LogTemplate> templates = new ArrayList<LogTemplateProvider.LogTemplate>();
+ /**
+ * @return all templates, but not the signature template itself
+ */
+ public static ArrayList<LogTemplate> getTemplatesWithoutSignature() {
+ final ArrayList<LogTemplate> templates = new ArrayList<LogTemplateProvider.LogTemplate>();
templates.add(new LogTemplate("DATE", R.string.init_signature_template_date) {
@Override
@@ -171,11 +174,11 @@ public final class LogTemplateProvider {
@Override
public String getValue(final LogContext context) {
- Trackable trackable = context.getTrackable();
+ final Trackable trackable = context.getTrackable();
if (trackable != null) {
return trackable.getOwner();
}
- Geocache cache = context.getCache();
+ final Geocache cache = context.getCache();
if (cache != null) {
return cache.getOwnerDisplayName();
}
@@ -184,12 +187,12 @@ public final class LogTemplateProvider {
});
templates.add(new LogTemplate("NAME", R.string.init_signature_template_name) {
@Override
- public String getValue(LogContext context) {
- Trackable trackable = context.getTrackable();
+ public String getValue(final LogContext context) {
+ final Trackable trackable = context.getTrackable();
if (trackable != null) {
return trackable.getName();
}
- Geocache cache = context.getCache();
+ final Geocache cache = context.getCache();
if (cache != null) {
return cache.getName();
}
@@ -199,12 +202,12 @@ public final class LogTemplateProvider {
templates.add(new LogTemplate("URL", R.string.init_signature_template_url) {
@Override
- public String getValue(LogContext context) {
- Trackable trackable = context.getTrackable();
+ public String getValue(final LogContext context) {
+ final Trackable trackable = context.getTrackable();
if (trackable != null) {
return trackable.getBrowserUrl();
}
- Geocache cache = context.getCache();
+ final Geocache cache = context.getCache();
if (cache != null) {
return cache.getBrowserUrl();
}
@@ -213,25 +216,37 @@ public final class LogTemplateProvider {
});
templates.add(new LogTemplate("LOG", R.string.init_signature_template_log) {
@Override
- public String getValue(LogContext context) {
- LogEntry logEntry = context.getLogEntry();
+ public String getValue(final LogContext context) {
+ final LogEntry logEntry = context.getLogEntry();
if (logEntry != null) {
return logEntry.getDisplayText();
}
return StringUtils.EMPTY;
}
});
+ return templates;
+ }
+
+ /**
+ * @return all templates, including the signature template
+ */
+ public static ArrayList<LogTemplate> getTemplatesWithSignature() {
+ final ArrayList<LogTemplate> templates = getTemplatesWithoutSignature();
templates.add(new LogTemplate("SIGNATURE", R.string.init_signature) {
@Override
- public String getValue(LogContext context) {
- return StringUtils.defaultString(Settings.getSignature());
+ public String getValue(final LogContext context) {
+ final String nestedTemplate = StringUtils.defaultString(Settings.getSignature());
+ if (StringUtils.contains(nestedTemplate, "SIGNATURE")) {
+ return "invalid signature template";
+ }
+ return LogTemplateProvider.applyTemplates(nestedTemplate, context);
}
});
return templates;
}
public static LogTemplate getTemplate(final int itemId) {
- for (LogTemplate template : getTemplates()) {
+ for (final LogTemplate template : getTemplatesWithSignature()) {
if (template.getItemId() == itemId) {
return template;
}
@@ -244,7 +259,7 @@ public final class LogTemplateProvider {
return StringUtils.EMPTY;
}
String result = signature;
- for (LogTemplate template : getTemplates()) {
+ for (final LogTemplate template : getTemplatesWithSignature()) {
result = template.apply(result, context);
}
return result;