Added signature location setting

pull/174/head
M66B 5 years ago
parent 8fdce42d8f
commit 3e9aa38613

@ -236,6 +236,13 @@ public class ApplicationEx extends Application {
editor.putBoolean("move_1_confirmed", automove);
editor.remove("automove");
}
} else if (version < 972) {
if (prefs.contains("signature_end")) {
boolean signature_end = prefs.getBoolean("signature_end", false);
if (signature_end)
editor.putInt("signature_location", 2);
editor.remove("signature_end");
}
}
if (BuildConfig.DEBUG && false) {

@ -3264,16 +3264,11 @@ public class FragmentCompose extends FragmentBase {
EntityIdentity identity = null;
if (data.draft.identity != null)
identity = db.identity().getIdentity(data.draft.identity);
boolean signature_end = prefs.getBoolean("signature_end", false);
if (!signature_end && identity != null)
addSignature(context, document, data.draft, identity);
for (Element e : ref)
document.body().appendChild(e);
if (signature_end && identity != null)
addSignature(context, document, data.draft, identity);
addSignature(context, document, data.draft, identity);
String html = JsoupEx.parse(document.html()).html();
Helper.writeText(file, html);
@ -3670,22 +3665,16 @@ public class FragmentCompose extends FragmentBase {
(extras != null && extras.containsKey("html"))) {
dirty = true;
boolean signature_end = prefs.getBoolean("signature_end", false);
// Get saved body
Document d;
if (extras != null && extras.containsKey("html")) {
// Save current revision
Document c = JsoupEx.parse(body);
if (!signature_end)
addSignature(context, c, draft, identity);
for (Element e : ref)
c.body().appendChild(e);
if (signature_end)
addSignature(context, c, draft, identity);
addSignature(context, c, draft, identity);
Helper.writeText(draft.getFile(context, draft.revision), c.html());
@ -3693,14 +3682,10 @@ public class FragmentCompose extends FragmentBase {
} else {
d = JsoupEx.parse(body);
if (!signature_end)
addSignature(context, d, draft, identity);
for (Element e : ref)
d.body().appendChild(e);
if (signature_end)
addSignature(context, d, draft, identity);
addSignature(context, d, draft, identity);
}
body = d.html();
@ -4007,11 +3992,13 @@ public class FragmentCompose extends FragmentBase {
identity == null || TextUtils.isEmpty(identity.signature))
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int signature_location = prefs.getInt("signature_location", 1);
boolean usenet = prefs.getBoolean("usenet_signature", false);
Element div = document.createElement("div");
div.attr("fairemail", "signature");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean usenet = prefs.getBoolean("usenet_signature", false);
if (usenet) {
// https://www.ietf.org/rfc/rfc3676.txt
Element span = document.createElement("span");
@ -4021,7 +4008,14 @@ public class FragmentCompose extends FragmentBase {
}
div.append(identity.signature);
document.body().appendChild(div);
Elements ref = document.select("div[fairemail=reference]");
if (signature_location == 0)
document.body().prependChild(div);
else if (ref.size() == 0 || signature_location == 2)
document.body().appendChild(div);
else if (signature_location == 1)
ref.first().before(div);
}
private void showDraft(final EntityMessage draft) {

@ -51,7 +51,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swExtendedReply;
private SwitchCompat swQuoteReply;
private SwitchCompat swPlainOnly;
private SwitchCompat swSignatureEnd;
private Spinner spSignatureLocation;
private SwitchCompat swUsenetSignature;
private SwitchCompat swRemoveSignatures;
private SwitchCompat swResizeImages;
@ -65,8 +65,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{
"keyboard", "suggest_sent", "suggested_received",
"prefix_once", "extended_reply", "quote_reply", "signature_end",
"plain_only", "usenet_signature", "remove_signatures",
"prefix_once", "extended_reply", "quote_reply",
"plain_only", "signature_location", "usenet_signature", "remove_signatures",
"resize_images", "resize_attachments", "send_reminders", "receipt_default", "resize", "lookup_mx", "send_delayed"
};
@ -88,7 +88,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swExtendedReply = view.findViewById(R.id.swExtendedReply);
swQuoteReply = view.findViewById(R.id.swQuoteReply);
swPlainOnly = view.findViewById(R.id.swPlainOnly);
swSignatureEnd = view.findViewById(R.id.swSignatureEnd);
spSignatureLocation = view.findViewById(R.id.spSignatureLocation);
swUsenetSignature = view.findViewById(R.id.swUsenetSignature);
swRemoveSignatures = view.findViewById(R.id.swRemoveSignatures);
swResizeImages = view.findViewById(R.id.swResizeImages);
@ -163,10 +163,15 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
}
});
swSignatureEnd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
spSignatureLocation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("signature_end", checked).apply();
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
prefs.edit().putInt("signature_location", position).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("signature_location").apply();
}
});
@ -301,7 +306,10 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));
swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true));
swPlainOnly.setChecked(prefs.getBoolean("plain_only", false));
swSignatureEnd.setChecked(prefs.getBoolean("signature_end", false));
int signature_location = prefs.getInt("signature_location", 1);
spSignatureLocation.setSelection(signature_location);
swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", false));
swRemoveSignatures.setChecked(prefs.getBoolean("remove_signatures", false));

@ -130,16 +130,27 @@
app:layout_constraintTop_toBottomOf="@id/swQuoteReply"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSignatureEnd"
<TextView
android:id="@+id/tvSignatureLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_signature_end"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_signature_location"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPlainOnly"
app:switchPadding="12dp" />
app:layout_constraintTop_toBottomOf="@id/swPlainOnly" />
<Spinner
android:id="@+id/spSignatureLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/signatureNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSignatureLocation" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUsenetSignature"
@ -149,7 +160,7 @@
android:text="@string/title_advanced_usenet_signature"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSignatureEnd"
app:layout_constraintTop_toBottomOf="@id/spSignatureLocation"
app:switchPadding="12dp" />
<TextView

Loading…
Cancel
Save