do not save draft if message is completly empty and fixed appending shared text

This commit is contained in:
Daniel Gultsch 2018-05-19 14:30:42 +02:00
parent be579332be
commit 2230d5a42c
3 changed files with 22 additions and 3 deletions

View file

@ -647,11 +647,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return null;
}
public boolean setNextMessage(String message) {
public boolean setNextMessage(final String input) {
final String message = input == null || input.trim().isEmpty() ? null : input;
boolean changed = !getNextMessage().equals(message);
this.setAttribute(ATTRIBUTE_NEXT_MESSAGE, message);
if (changed) {
this.setAttribute(ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP, TextUtils.isEmpty(message) ? 0 : System.currentTimeMillis());
this.setAttribute(ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP, message == null ? 0 : System.currentTimeMillis());
}
return changed;
}

View file

@ -2391,7 +2391,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return;
}
String previous = this.binding.textinput.getText().toString();
if (previous.length() != 0 && !previous.endsWith(" ")) {
if (UIHelper.isLastLineQuote(previous)) {
text = '\n' + text;
} else if (previous.length() != 0 && !Character.isWhitespace(previous.charAt(previous.length() - 1))) {
text = " " + text;
}
this.binding.textinput.append(text);

View file

@ -334,6 +334,22 @@ public class UIHelper {
}
}
public static boolean isLastLineQuote(String body) {
if (body.endsWith("\n")) {
return false;
}
String[] lines = body.split("\n");
if (lines.length == 0) {
return false;
}
String line = lines[lines.length - 1];
if (line.isEmpty()) {
return false;
}
char first = line.charAt(0);
return first == '>' && isPositionFollowedByQuoteableCharacter(line,0) || first == '\u00bb';
}
public static CharSequence shorten(CharSequence input) {
return input.length() > 256 ? StylingHelper.subSequence(input, 0, 256) : input;
}