aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgeovisit.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgeo/geocaching/cgeovisit.java')
-rw-r--r--src/cgeo/geocaching/cgeovisit.java111
1 files changed, 32 insertions, 79 deletions
diff --git a/src/cgeo/geocaching/cgeovisit.java b/src/cgeo/geocaching/cgeovisit.java
index 118cc29..4f5a2d3 100644
--- a/src/cgeo/geocaching/cgeovisit.java
+++ b/src/cgeo/geocaching/cgeovisit.java
@@ -25,8 +25,12 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
+import cgeo.geocaching.LogTemplateProvider.LogTemplate;
public class cgeovisit extends cgLogForm {
+ private static final int MENU_SIGNATURE = 1;
+ private static final int SUBMENU_VOTE = 2;
+
private LayoutInflater inflater = null;
private cgCache cache = null;
private ArrayList<Integer> types = new ArrayList<Integer>();
@@ -50,12 +54,7 @@ public class cgeovisit extends cgLogForm {
private LinearLayout tweetBox = null;
private double rating = 0.0;
private boolean tbChanged = false;
- // constants
- private final static int LOG_SIGNATURE = 0x1;
- private final static int LOG_TIME = 0x2;
- private final static int LOG_DATE = 0x4;
- private final static int LOG_DATE_TIME = 0x6;
- private final static int LOG_SIGNATURE_DATE_TIME = 0x7;
+
// handlers
private Handler showProgressHandler = new Handler() {
@Override
@@ -277,13 +276,12 @@ public class cgeovisit extends cgLogForm {
SubMenu menuLog = null;
menuLog = menu.addSubMenu(0, 0, 0, res.getString(R.string.log_add)).setIcon(android.R.drawable.ic_menu_add);
- menuLog.add(0, LOG_DATE_TIME, 0, res.getString(R.string.log_date_time));
- menuLog.add(0, LOG_DATE, 0, res.getString(R.string.log_date));
- menuLog.add(0, LOG_TIME, 0, res.getString(R.string.log_time));
- menuLog.add(0, LOG_SIGNATURE, 0, res.getString(R.string.init_signature));
- menuLog.add(0, LOG_SIGNATURE_DATE_TIME, 0, res.getString(R.string.log_date_time) + " & " + res.getString(R.string.init_signature));
+ for (LogTemplate template : LogTemplateProvider.getTemplates()) {
+ menuLog.add(0, template.getItemId(), 0, template.getResourceId());
+ }
+ menuLog.add(0, MENU_SIGNATURE, 0, res.getString(R.string.init_signature));
- SubMenu menuStars = menu.addSubMenu(0, 9, 0, res.getString(R.string.log_rating)).setIcon(android.R.drawable.ic_menu_sort_by_size);
+ SubMenu menuStars = menu.addSubMenu(0, SUBMENU_VOTE, 0, res.getString(R.string.log_rating)).setIcon(android.R.drawable.ic_menu_sort_by_size);
menuStars.add(0, 10, 0, res.getString(R.string.log_no_rating));
menuStars.add(0, 19, 0, res.getString(R.string.log_stars_5));
menuStars.add(0, 18, 0, res.getString(R.string.log_stars_45));
@@ -301,11 +299,10 @@ public class cgeovisit extends cgLogForm {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean signatureAvailable = settings.getSignature() != null;
- menu.findItem(LOG_SIGNATURE).setVisible(signatureAvailable);
- menu.findItem(LOG_SIGNATURE_DATE_TIME).setVisible(signatureAvailable);
+ menu.findItem(MENU_SIGNATURE).setVisible(signatureAvailable);
boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && cache.guid != null && cache.guid.length() > 0;
- menu.findItem(9).setVisible(voteAvailable);
+ menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable);
return true;
}
@@ -314,9 +311,13 @@ public class cgeovisit extends cgLogForm {
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
- if ((id >= LOG_SIGNATURE && id <= LOG_SIGNATURE_DATE_TIME)) {
- addSignature(id);
-
+ if (id == MENU_SIGNATURE) {
+ EditText log = (EditText) findViewById(R.id.log);
+ String content = log.getText().toString();
+ if (content.length() > 0) {
+ insertIntoLog("\n");
+ }
+ insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
return true;
} else if (id >= 10 && id <= 19) {
rating = (id - 9) / 2.0;
@@ -329,11 +330,22 @@ public class cgeovisit extends cgLogForm {
} else {
post.setText(res.getString(R.string.log_post_rate) + " " + ratingTextValue(rating) + "*");
}
+ return true;
+ }
+ LogTemplate template = LogTemplateProvider.getTemplate(id);
+ if (template != null) {
+ String newText = template.getValue(base);
+ insertIntoLog(newText);
+ return true;
}
-
return false;
}
+ private void insertIntoLog(String newText) {
+ EditText log = (EditText) findViewById(R.id.log);
+ cgBase.insertAtPosition(log, newText, true);
+ }
+
private static String ratingTextValue(final double rating) {
return String.format(Locale.getDefault(), "%.1f", rating);
}
@@ -363,65 +375,6 @@ public class cgeovisit extends cgLogForm {
return result.trim().equalsIgnoreCase("ok");
}
- public void addSignature(int id) {
- final long now = System.currentTimeMillis();
- final String dateString = base.formatFullDate(now);
- final String timeString = base.formatTime(now);
- EditText text = null;
- String textContent = null;
- StringBuilder addText = new StringBuilder();
-
- text = (EditText) findViewById(R.id.log);
- textContent = text.getText().toString();
-
-
- if ((id & LOG_DATE) == LOG_DATE) {
- addText.append(dateString);
- if ((id & LOG_TIME) == LOG_TIME) {
- addText.append(" | ");
- }
- }
-
- if ((id & LOG_TIME) == LOG_TIME) {
- addText.append(timeString);
- }
-
- if ((id & LOG_SIGNATURE) == LOG_SIGNATURE && settings.getSignature() != null) {
- String findCount = "";
- if (addText.length() > 0) {
- addText.append("\n");
- }
-
- if (settings.getSignature().contains("[NUMBER]")) {
- final HashMap<String, String> params = new HashMap<String, String>();
- final String page = base.request(false, "www.geocaching.com", "/my/", "GET", params, false, false, false).getData();
- int current = cgBase.parseFindCount(page);
-
- if (current >= 0) {
- findCount = "" + (current + 1);
- }
- }
-
- String signature = settings.getSignature()
- .replaceAll("\\[DATE\\]", dateString)
- .replaceAll("\\[TIME\\]", timeString)
- .replaceAll("\\[USER\\]", settings.getUsername())
- .replaceAll("\\[NUMBER\\]", findCount);
-
- addText.append(signature);
- }
-
- final String addTextDone;
- if (textContent.length() > 0 && addText.length() > 0 ) {
- addTextDone = textContent + "\n" + addText.toString();
- } else {
- addTextDone = textContent + addText.toString();
- }
-
- text.setText(addTextDone, TextView.BufferType.NORMAL);
- text.setSelection(text.getText().toString().length());
- }
-
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
super.onCreateContextMenu(menu, view, info);
@@ -580,7 +533,7 @@ public class cgeovisit extends cgLogForm {
&& settings.signatureAutoinsert
&& settings.getSignature().length() > 0
&& 0 == ((EditText) findViewById(R.id.log)).getText().length()) {
- addSignature(LOG_SIGNATURE);
+ insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
}
if (types.contains(typeSelected) == false) {