Added $date$ placeholder

pull/209/head
M66B 2 years ago
parent fac57be4bc
commit a3ed7f244e

@ -48,9 +48,12 @@ import org.json.JSONObject;
import java.io.Serializable;
import java.text.Collator;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -178,6 +181,30 @@ public class EntityAnswer implements Serializable {
text = text.replace("$lastname$", last == null ? "" : Html.escapeHtml(last));
text = text.replace("$email$", email == null ? "" : Html.escapeHtml(email));
int s = text.indexOf("$date");
while (s >= 0) {
int e = text.indexOf('$', s + 5);
if (e < 0)
break;
Calendar c = null;
String v = text.substring(s + 5, e);
if (v.startsWith("-") || v.startsWith("+")) {
Integer days = Helper.parseInt(v.substring(1));
if (days != null) {
c = Calendar.getInstance();
c.add(Calendar.DATE, days * (v.startsWith("-") ? -1 : 1));
}
} else if (TextUtils.isEmpty(v))
c = Calendar.getInstance();
if (c != null) {
v = Html.escapeHtml(SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG).format(c.getTime()));
text = text.substring(0, s) + v + text.substring(e);
s = text.indexOf("$date", s + v.length());
}
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
for (String key : prefs.getAll().keySet())
if (key.startsWith(PREF_PLACEHOLDER)) {

@ -321,6 +321,9 @@ public class FragmentAnswer extends FragmentBase {
} else if (itemId == R.id.menu_placeholder_lastname) {
onMenuPlaceholder("$lastname$");
return true;
} else if (itemId == R.id.menu_placeholder_date) {
onMenuPlaceholder("$date$");
return true;
}
}
return super.onOptionsItemSelected(item);

@ -22,6 +22,9 @@
<item
android:id="@+id/menu_placeholder_lastname"
android:title="@string/title_answer_placeholder_lastname" />
<item
android:id="@+id/menu_placeholder_date"
android:title="@string/title_answer_placeholder_date" />
</menu>
</item>
</menu>

@ -1682,6 +1682,7 @@
<string name="title_answer_placeholder_email">Sender\'s email address</string>
<string name="title_answer_placeholder_firstname">Sender\'s first name</string>
<string name="title_answer_placeholder_lastname">Sender\'s last name</string>
<string name="title_answer_placeholder_date">Current date</string>
<string name="title_rule_noop">No action</string>
<string name="title_rule_seen">Mark read</string>

Loading…
Cancel
Save