Ellipsize notification preview

Refs #148
pull/149/head
M66B 6 years ago
parent e8e4d69da8
commit 1ed0fe7fce

@ -60,7 +60,8 @@ 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 {
private static final int PREVIEW_SIZE = 250; static final int PREVIEW_SIZE = 250;
private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr"); private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr");
private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li"); private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");

@ -60,6 +60,7 @@ import com.sun.mail.util.MailConnectException;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.jsoup.Jsoup;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -688,7 +689,12 @@ public class ServiceSynchronize extends LifecycleService {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (!TextUtils.isEmpty(message.subject)) if (!TextUtils.isEmpty(message.subject))
sb.append(message.subject).append("<br>"); sb.append(message.subject).append("<br>");
sb.append(HtmlHelper.getPreview(body)); String text = Jsoup.parse(body).text();
if (text.length() > HtmlHelper.PREVIEW_SIZE) {
sb.append(text.substring(0, HtmlHelper.PREVIEW_SIZE));
sb.append(" …");
} else
sb.append(text);
mbuilder.setStyle(new Notification.BigTextStyle().bigText(HtmlHelper.fromHtml(sb.toString()))); mbuilder.setStyle(new Notification.BigTextStyle().bigText(HtmlHelper.fromHtml(sb.toString())));
} catch (IOException ex) { } catch (IOException ex) {
Log.e(ex); Log.e(ex);

Loading…
Cancel
Save