From 3f34a3aff0902b37b4e94b5d8c1c38b8285532ab Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 25 Dec 2016 18:44:07 +0100 Subject: skip empty lines in message preview. prevents indexoutofbounds exception and don't show quoted text in message preview --- .../java/de/pixart/messenger/utils/UIHelper.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index 0bb87e6c7..dce1b031c 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -202,7 +202,31 @@ public class UIHelper { return new Pair<>(context.getString(R.string.x_file_offered_for_download, getFileDescriptionString(context, message)), true); } else { - return new Pair<>(body.trim(), false); + String[] lines = body.split("\n"); + StringBuilder builder = new StringBuilder(); + for(String l : lines) { + if (l.length() > 0) { + char first = l.charAt(0); + if (first != '>' && first != '\u00bb') { + String line = l.trim(); + if (line.isEmpty()) { + continue; + } + char last = line.charAt(line.length()-1); + if (builder.length() != 0) { + builder.append(' '); + } + builder.append(line); + if (last != '.' && last != '!' && last != '?' && last != ',') { + break; + } + } + } + } + if (builder.length() == 0) { + builder.append(body.trim()); + } + return new Pair<>(builder.length() > 256 ? builder.substring(0,256) : builder.toString(), false); } } } -- cgit v1.2.3