Improved re/fwd processing

This commit is contained in:
M66B 2019-12-01 12:24:03 +01:00
parent 4fb0451d88
commit 50646724df
2 changed files with 37 additions and 38 deletions

View File

@ -33,8 +33,6 @@ import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
@ -49,10 +47,8 @@ import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.LocaleList;
import android.os.OperationCanceledException;
import android.provider.ContactsContract;
import android.provider.MediaStore;
@ -2429,16 +2425,14 @@ public class FragmentCompose extends FragmentBase {
String subject = (ref.subject == null ? "" : ref.subject);
if ("reply".equals(action) || "reply_all".equals(action)) {
if (prefix_once) {
String re = context.getString(R.string.title_subject_reply, "");
subject = unprefix(subject, re);
}
if (prefix_once)
for (String re : Helper.getStrings(context, R.string.title_subject_reply, ""))
subject = unprefix(subject, re);
data.draft.subject = context.getString(R.string.title_subject_reply, subject);
} else if ("forward".equals(action)) {
if (prefix_once) {
String fwd = context.getString(R.string.title_subject_forward, "");
subject = unprefix(subject, fwd);
}
if (prefix_once)
for (String fwd : Helper.getStrings(context, R.string.title_subject_forward, ""))
subject = unprefix(subject, fwd);
data.draft.subject = context.getString(R.string.title_subject_forward, subject);
} else if ("editasnew".equals(action)) {
data.draft.subject = ref.subject;
@ -2454,17 +2448,9 @@ public class FragmentCompose extends FragmentBase {
} else if ("receipt".equals(action)) {
data.draft.subject = context.getString(R.string.title_receipt_subject, subject);
Element p = document.createElement("p");
p.text(context.getString(R.string.title_receipt_text));
document.body().appendChild(p);
if (!Locale.getDefault().getLanguage().equals("en")) {
Configuration configuration = new Configuration(context.getResources().getConfiguration());
configuration.setLocale(new Locale("en"));
Resources res = context.createConfigurationContext(configuration).getResources();
p = document.createElement("p");
p.text(res.getString(R.string.title_receipt_text));
for (String text : Helper.getStrings(context, R.string.title_receipt_text)) {
Element p = document.createElement("p");
p.text(text);
document.body().appendChild(p);
}
} else if ("participation".equals(action))
@ -3168,21 +3154,8 @@ public class FragmentCompose extends FragmentBase {
// Check for missing attachments
if (attached == 0) {
List<String> keywords = new ArrayList<>();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
String[] k = context.getString(R.string.title_attachment_keywords).split(",");
keywords.addAll(Arrays.asList(k));
} else {
Configuration config = context.getResources().getConfiguration();
LocaleList ll = context.getResources().getConfiguration().getLocales();
for (int i = 0; i < ll.size(); i++) {
Configuration lconf = new Configuration(config);
lconf.setLocale(ll.get(i));
Context lcontext = context.createConfigurationContext(lconf);
String[] k = lcontext.getString(R.string.title_attachment_keywords).split(",");
keywords.addAll(Arrays.asList(k));
}
}
for (String text : Helper.getStrings(context, R.string.title_attachment_keywords))
keywords.addAll(Arrays.asList(text.split(",")));
Document d = JsoupEx.parse(body);
d.select("div[fairemail=signature]").remove();

View File

@ -29,6 +29,8 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
@ -36,6 +38,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.LocaleList;
import android.os.Parcel;
import android.os.PowerManager;
import android.os.StatFs;
@ -637,6 +640,29 @@ public class Helper {
}
}
static String[] getStrings(Context context, int resid, Object... formatArgs) {
List<String> result = new ArrayList<>();
Configuration configuration = new Configuration(context.getResources().getConfiguration());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
result.add(context.getString(resid, formatArgs));
if (!Locale.getDefault().getLanguage().equals("en")) {
configuration.setLocale(new Locale("en"));
Resources res = context.createConfigurationContext(configuration).getResources();
result.add(res.getString(resid, formatArgs));
}
} else {
LocaleList ll = context.getResources().getConfiguration().getLocales();
for (int i = 0; i < ll.size(); i++) {
configuration.setLocale(ll.get(i));
Resources res = context.createConfigurationContext(configuration).getResources();
result.add(res.getString(resid, formatArgs));
}
}
return result.toArray(new String[0]);
}
// Files
static String sanitizeFilename(String name) {