mirror of https://github.com/M66B/FairEmail.git
Limit formatted message size based on memory class
This commit is contained in:
parent
c8929f5e49
commit
e312905327
|
@ -22,6 +22,7 @@ package eu.faircode.email;
|
|||
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL;
|
||||
import static org.w3c.css.sac.Condition.SAC_CLASS_CONDITION;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
|
@ -362,6 +363,15 @@ public class HtmlHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static int getMaxFormatTextSize(Context context) {
|
||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
int mc = am.getMemoryClass();
|
||||
if (mc >= 256)
|
||||
return MAX_FORMAT_TEXT_SIZE;
|
||||
else
|
||||
return mc * MAX_FORMAT_TEXT_SIZE / 256;
|
||||
}
|
||||
|
||||
private static Document sanitize(Context context, Document parsed, boolean view, boolean show_images) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String theme = prefs.getString("theme", "blue_orange_system");
|
||||
|
@ -425,7 +435,7 @@ public class HtmlHelper {
|
|||
normalizeNamespaces(parsed, display_hidden);
|
||||
|
||||
// Limit length
|
||||
if (view && truncate(parsed, MAX_FORMAT_TEXT_SIZE)) {
|
||||
if (view && truncate(parsed, getMaxFormatTextSize(context))) {
|
||||
parsed.body()
|
||||
.appendElement("p")
|
||||
.appendElement("em")
|
||||
|
@ -2200,7 +2210,7 @@ public class HtmlHelper {
|
|||
static String getText(Context context, String html) {
|
||||
Document d = sanitizeCompose(context, html, false);
|
||||
|
||||
truncate(d, MAX_FORMAT_TEXT_SIZE);
|
||||
truncate(d, getMaxFormatTextSize(context));
|
||||
|
||||
SpannableStringBuilder ssb = fromDocument(context, d, null, null);
|
||||
|
||||
|
|
Loading…
Reference in New Issue