Implement nested quotes through iteration.
This commit is contained in:
parent
65a72827bc
commit
74d60d0131
|
@ -201,4 +201,7 @@ public final class Config {
|
||||||
public final static float LOCATION_FIX_SPACE_DELTA = 10; // m
|
public final static float LOCATION_FIX_SPACE_DELTA = 10; // m
|
||||||
public final static int LOCATION_FIX_SIGNIFICANT_TIME_DELTA = 1000 * 60 * 2; // ms
|
public final static int LOCATION_FIX_SIGNIFICANT_TIME_DELTA = 1000 * 60 * 2; // ms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// How deep nested quotes should become. '2' means one quote nested in another.
|
||||||
|
public static final int QUOTE_MAX_DEPTH = 3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ import eu.siacs.conversations.ui.text.DividerSpan;
|
||||||
import eu.siacs.conversations.ui.text.QuoteSpan;
|
import eu.siacs.conversations.ui.text.QuoteSpan;
|
||||||
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
||||||
import eu.siacs.conversations.ui.util.MyLinkify;
|
import eu.siacs.conversations.ui.util.MyLinkify;
|
||||||
|
import eu.siacs.conversations.ui.util.QuoteHelper;
|
||||||
import eu.siacs.conversations.ui.util.ViewUtil;
|
import eu.siacs.conversations.ui.util.ViewUtil;
|
||||||
import eu.siacs.conversations.ui.widget.ClickableMovementMethod;
|
import eu.siacs.conversations.ui.widget.ClickableMovementMethod;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
|
@ -359,48 +360,55 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
*/
|
*/
|
||||||
private boolean handleTextQuotes(SpannableStringBuilder body, boolean darkBackground) {
|
private boolean handleTextQuotes(SpannableStringBuilder body, boolean darkBackground) {
|
||||||
boolean startsWithQuote = false;
|
boolean startsWithQuote = false;
|
||||||
char previous = '\n';
|
int quoteDepth = 1;
|
||||||
int lineStart = -1;
|
while (QuoteHelper.bodyContainsQuoteStart(body) && quoteDepth <= Config.QUOTE_MAX_DEPTH) {
|
||||||
int lineTextStart = -1;
|
char previous = '\n';
|
||||||
int quoteStart = -1;
|
int lineStart = -1;
|
||||||
for (int i = 0; i <= body.length(); i++) {
|
int lineTextStart = -1;
|
||||||
char current = body.length() > i ? body.charAt(i) : '\n';
|
int quoteStart = -1;
|
||||||
if (lineStart == -1) {
|
for (int i = 0; i <= body.length(); i++) {
|
||||||
if (previous == '\n') {
|
char current = body.length() > i ? body.charAt(i) : '\n';
|
||||||
if ((current == '>' && UIHelper.isPositionFollowedByQuoteableCharacter(body, i))
|
if (lineStart == -1) {
|
||||||
|| current == '\u00bb' && !UIHelper.isPositionFollowedByQuote(body, i)) {
|
if (previous == '\n') {
|
||||||
// Line start with quote
|
if (
|
||||||
lineStart = i;
|
(QuoteHelper.isPositionQuoteStart(body, i)
|
||||||
if (quoteStart == -1) quoteStart = i;
|
|| (current == '\u00bb' && !UIHelper.isPositionFollowedByQuote(body, i)
|
||||||
if (i == 0) startsWithQuote = true;
|
))) {
|
||||||
} else if (quoteStart >= 0) {
|
// Line start with quote
|
||||||
// Line start without quote, apply spans there
|
lineStart = i;
|
||||||
applyQuoteSpan(body, quoteStart, i - 1, darkBackground);
|
if (quoteStart == -1) quoteStart = i;
|
||||||
quoteStart = -1;
|
if (i == 0) startsWithQuote = true;
|
||||||
|
} else if (quoteStart >= 0) {
|
||||||
|
// Line start without quote, apply spans there
|
||||||
|
applyQuoteSpan(body, quoteStart, i - 1, darkBackground);
|
||||||
|
quoteStart = -1;
|
||||||
|
quoteDepth++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Remove extra spaces between > and first character in the line
|
||||||
|
// > character will be removed too
|
||||||
|
if (current != ' ' && lineTextStart == -1) {
|
||||||
|
lineTextStart = i;
|
||||||
|
}
|
||||||
|
if (current == '\n') {
|
||||||
|
body.delete(lineStart, lineTextStart);
|
||||||
|
i -= lineTextStart - lineStart;
|
||||||
|
if (i == lineStart) {
|
||||||
|
// Avoid empty lines because span over empty line can be hidden
|
||||||
|
body.insert(i++, " ");
|
||||||
|
}
|
||||||
|
lineStart = -1;
|
||||||
|
lineTextStart = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
previous = current;
|
||||||
// Remove extra spaces between > and first character in the line
|
}
|
||||||
// > character will be removed too
|
if (quoteStart >= 0) {
|
||||||
if (current != ' ' && lineTextStart == -1) {
|
// Apply spans to finishing open quote
|
||||||
lineTextStart = i;
|
applyQuoteSpan(body, quoteStart, body.length(), darkBackground);
|
||||||
}
|
quoteDepth++;
|
||||||
if (current == '\n') {
|
|
||||||
body.delete(lineStart, lineTextStart);
|
|
||||||
i -= lineTextStart - lineStart;
|
|
||||||
if (i == lineStart) {
|
|
||||||
// Avoid empty lines because span over empty line can be hidden
|
|
||||||
body.insert(i++, " ");
|
|
||||||
}
|
|
||||||
lineStart = -1;
|
|
||||||
lineTextStart = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
previous = current;
|
|
||||||
}
|
|
||||||
if (quoteStart >= 0) {
|
|
||||||
// Apply spans to finishing open quote
|
|
||||||
applyQuoteSpan(body, quoteStart, body.length(), darkBackground);
|
|
||||||
}
|
}
|
||||||
return startsWithQuote;
|
return startsWithQuote;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue