mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
d28f8bedc2
commit
4afb121fbe
|
@ -3007,19 +3007,15 @@ class Core {
|
|||
if (message.content && notify_preview)
|
||||
try {
|
||||
String body = Helper.readText(message.getFile(context));
|
||||
|
||||
StringBuilder sbm = new StringBuilder();
|
||||
if (!TextUtils.isEmpty(message.subject))
|
||||
sbm.append(message.subject).append("<br>");
|
||||
String text = Jsoup.parse(body).text();
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
sbm.append("<em>");
|
||||
if (text.length() > HtmlHelper.PREVIEW_SIZE) {
|
||||
sbm.append(text.substring(0, HtmlHelper.PREVIEW_SIZE));
|
||||
sbm.append("…");
|
||||
} else
|
||||
sbm.append(text);
|
||||
sbm.append("</em>");
|
||||
}
|
||||
|
||||
String preview = HtmlHelper.getPreview(body);
|
||||
if (!TextUtils.isEmpty(preview))
|
||||
sbm.append("<em>").append(preview).append("</em>");
|
||||
|
||||
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString())));
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
|
|
|
@ -83,7 +83,7 @@ import static androidx.core.text.HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_
|
|||
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
|
||||
|
||||
public class HtmlHelper {
|
||||
static final int PREVIEW_SIZE = 250; // characters
|
||||
private static final int PREVIEW_SIZE = 250; // characters
|
||||
|
||||
private static final float MIN_LUMINANCE = 0.5f;
|
||||
private static final int MAX_AUTO_LINK = 250;
|
||||
|
@ -812,8 +812,16 @@ public class HtmlHelper {
|
|||
}
|
||||
|
||||
static String getPreview(String body) {
|
||||
String text = (body == null ? null : Jsoup.parse(body).text());
|
||||
return (text == null ? null : text.substring(0, Math.min(text.length(), PREVIEW_SIZE)));
|
||||
if (body == null)
|
||||
return null;
|
||||
|
||||
String text = Jsoup.parse(body).text();
|
||||
|
||||
String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE));
|
||||
if (preview.length() < text.length())
|
||||
preview += "…";
|
||||
|
||||
return preview;
|
||||
}
|
||||
|
||||
static String getText(String html) {
|
||||
|
|
Loading…
Reference in New Issue