mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Added $date$ placeholder
This commit is contained in:
parent
fac57be4bc
commit
a3ed7f244e
4 changed files with 34 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue