Refactoring

pull/162/head
M66B 6 years ago
parent d28f8bedc2
commit 4afb121fbe

@ -3007,19 +3007,15 @@ class Core {
if (message.content && notify_preview) if (message.content && notify_preview)
try { try {
String body = Helper.readText(message.getFile(context)); String body = Helper.readText(message.getFile(context));
StringBuilder sbm = new StringBuilder(); StringBuilder sbm = new StringBuilder();
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
sbm.append(message.subject).append("<br>"); sbm.append(message.subject).append("<br>");
String text = Jsoup.parse(body).text();
if (!TextUtils.isEmpty(text)) { String preview = HtmlHelper.getPreview(body);
sbm.append("<em>"); if (!TextUtils.isEmpty(preview))
if (text.length() > HtmlHelper.PREVIEW_SIZE) { sbm.append("<em>").append(preview).append("</em>");
sbm.append(text.substring(0, HtmlHelper.PREVIEW_SIZE));
sbm.append("…");
} else
sbm.append(text);
sbm.append("</em>");
}
mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString()))); mbuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(HtmlHelper.fromHtml(sbm.toString())));
} catch (IOException ex) { } catch (IOException ex) {
Log.e(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; import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
public class HtmlHelper { 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 float MIN_LUMINANCE = 0.5f;
private static final int MAX_AUTO_LINK = 250; private static final int MAX_AUTO_LINK = 250;
@ -812,8 +812,16 @@ public class HtmlHelper {
} }
static String getPreview(String body) { static String getPreview(String body) {
String text = (body == null ? null : Jsoup.parse(body).text()); if (body == null)
return (text == null ? null : text.substring(0, Math.min(text.length(), PREVIEW_SIZE))); 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) { static String getText(String html) {

Loading…
Cancel
Save