Added reply header template

pull/215/head
M66B 3 months ago
parent be5bd8c589
commit ba24ebd0f3

@ -557,6 +557,7 @@ public class EntityMessage implements Serializable {
Element getReplyHeader(Context context, Document document, boolean separate, boolean extended) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean hide_timezone = prefs.getBoolean("hide_timezone", false);
String template_reply = prefs.getString("template_reply", null);
boolean language_detection = prefs.getBoolean("language_detection", false);
String compose_font = prefs.getString("compose_font", "");
String l = (language_detection ? language : null);
@ -604,8 +605,17 @@ public class EntityMessage implements Serializable {
p.appendText(subject);
p.appendElement("br");
}
} else
} else if (TextUtils.isEmpty(template_reply))
p.text(date + " " + MessageHelper.formatAddresses(from) + ":");
else {
template_reply = template_reply.replace("$from$", MessageHelper.formatAddresses(from));
template_reply = template_reply.replace("$to$", MessageHelper.formatAddresses(to));
template_reply = template_reply.replace("$cc$", MessageHelper.formatAddresses(cc));
template_reply = template_reply.replace("$time$", date);
template_reply = template_reply.replace("$subject$", subject);
p.html(template_reply);
}
Element div = document.createElement("div")
.attr("fairemail", "reply");

@ -32,6 +32,7 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
@ -48,6 +49,7 @@ import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -102,6 +104,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private RadioGroup rgFwd;
private SwitchCompat swSeparateReply;
private SwitchCompat swExtendedReply;
private EditText etTemplateReply;
private TextView tvTemplateReplyHint;
private SwitchCompat swWriteBelow;
private SwitchCompat swQuoteReply;
private SwitchCompat swQuoteLimit;
@ -143,7 +147,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
"sound_sent",
"compose_color", "compose_font", "compose_monospaced",
"prefix_once", "prefix_count", "alt_re", "alt_fwd",
"separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit",
"separate_reply", "extended_reply", "template_reply", "write_below", "quote_reply", "quote_limit",
"resize_reply", "resize_paste",
"signature_location", "signature_new", "signature_reply", "signature_reply_once", "signature_forward",
"send_at_top", "attach_new", "auto_link", "plain_only", "plain_only_reply",
@ -198,6 +202,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
rgFwd = view.findViewById(R.id.rgFwd);
swSeparateReply = view.findViewById(R.id.swSeparateReply);
swExtendedReply = view.findViewById(R.id.swExtendedReply);
etTemplateReply = view.findViewById(R.id.etTemplateReply);
tvTemplateReplyHint = view.findViewById(R.id.tvTemplateReplyHint);
swWriteBelow = view.findViewById(R.id.swWriteBelow);
swQuoteReply = view.findViewById(R.id.swQuoteReply);
swQuoteLimit = view.findViewById(R.id.swQuoteLimit);
@ -603,9 +609,33 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("extended_reply", checked).apply();
etTemplateReply.setEnabled(!checked);
}
});
etTemplateReply.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
String template = s.toString();
if (TextUtils.isEmpty(template.trim()))
prefs.edit().remove("template_reply").apply();
else
prefs.edit().putString("template_reply", template).apply();
}
});
tvTemplateReplyHint.setText(getString(R.string.title_advanced_template_reply_hint, "$from$ $to$ $cc$ $time$ $subject$"));
swWriteBelow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -863,6 +893,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (!RESET_OPTIONS.contains(key))
return;
if ("template_reply".equals(key))
return;
if ("purge_contact_age".equals(key) || "purge_contact_freq".equals(key))
return;
if ("send_retry_max".equals(key))
@ -973,6 +1005,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swSeparateReply.setChecked(prefs.getBoolean("separate_reply", false));
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));
etTemplateReply.setText(prefs.getString("template_reply", null));
etTemplateReply.setEnabled(!swExtendedReply.isChecked());
swWriteBelow.setChecked(prefs.getBoolean("write_below", false));
swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true));
swQuoteLimit.setChecked(prefs.getBoolean("quote_limit", true));

@ -694,6 +694,46 @@
app:layout_constraintTop_toBottomOf="@id/swSeparateReply"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvTemplateReply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_template_reply"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExtendedReply" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etTemplateReply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="48dp"
android:hint="$time$ $from$:"
android:imeOptions="actionDone"
android:inputType="text|textNoSuggestions"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTemplateReply" />
<TextView
android:id="@+id/tvTemplateReplyHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_template_reply_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etTemplateReply" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWriteBelow"
android:layout_width="0dp"
@ -703,7 +743,7 @@
android:text="@string/title_advanced_write_below"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExtendedReply"
app:layout_constraintTop_toBottomOf="@id/tvTemplateReplyHint"
app:switchPadding="12dp" />
<TextView

@ -497,6 +497,7 @@
<string name="title_advanced_prefix_count">Add count to reply prefix</string>
<string name="title_advanced_separate_reply">Insert a horizontal line before a reply/forward header</string>
<string name="title_advanced_extended_reply">Use extended reply/forward header</string>
<string name="title_advanced_template_reply">Reply/forward header template</string>
<string name="title_advanced_write_above">Write above the sender\'s text</string>
<string name="title_advanced_write_below">Write below the sender\'s text</string>
<string name="title_advanced_quote_reply">Quote replied text</string>
@ -1063,6 +1064,7 @@
<string name="title_advanced_send_reminders_hint">Show a warning when the message text or the subject is empty or when an attachment might be missing</string>
<string name="title_advanced_reply_move_hint">The email server could still add the messages to the sent message folder</string>
<string name="title_advanced_compose_color_hint">Very light or very dark colors will result in illegible messages on the recipients\' side</string>
<string name="title_advanced_template_reply_hint">HTML is allowed. Available placeholders: %1$s</string>
<string name="title_advanced_write_below_hint">A recipient might miss your reply, for example when a longer message is being truncated</string>
<string name="title_advanced_attach_new_hint">Otherwise, add shared addresses or files to the current draft message</string>
<string name="title_advanced_usenet_hint">Insert \'-- \' between the text and the signature</string>

Loading…
Cancel
Save