From e850900b40e5bafc6ece4303bb6f712b87132758 Mon Sep 17 00:00:00 2001 From: Millesimus Date: Fri, 20 Aug 2021 22:40:06 +0200 Subject: [PATCH] Quoting quotes, limited by nesting depth. --- .../java/eu/siacs/conversations/Config.java | 4 ++- .../conversations/ui/util/QuoteHelper.java | 30 +++++++++---------- .../conversations/ui/widget/EditMessage.java | 2 +- .../conversations/utils/MessageUtils.java | 3 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 3159d931f..a8494d68c 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -202,6 +202,8 @@ public final class Config { 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. + // How deep nested quotes should be displayed. '2' means one quote nested in another. public static final int QUOTE_MAX_DEPTH = 3; + // How deep nested quotes should be created on quoting a message. + public static final int QUOTING_MAX_DEPTH = QUOTE_MAX_DEPTH - 1; } diff --git a/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java b/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java index cfd2a2e63..cc539f1ef 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/QuoteHelper.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui.util; +import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.UIHelper; public class QuoteHelper { @@ -32,20 +33,19 @@ public class QuoteHelper { } return false; } - /*public static int getQuoteColors(XmppActivity activity, boolean darkBackground, int quoteDepth){ - int[] colorsLight = R.style.ConversationsTheme_Dark; - int[] colorsDark = Config.QUOTE_COLOR_ARRAY_DARK; - Collections.rotate(Collections.singletonList(colorsLight), quoteDepth); - Collections.rotate(Collections.singletonList(colorsDark), quoteDepth); - - Arrays.stream(colorsLight).toArray(); - - int quoteColors = darkBackground ? ContextCompat.getColor(activity, colorsLight[quoteDepth-1]) - : ContextCompat.getColor(activity, colorsDark[quoteDepth-1]); - - Collections.rotate - - return quoteColors; - };*/ + public static boolean isNestedTooDeeply (CharSequence line){ + if (isPositionQuoteCharacter(line, 0)) { + int nestingDepth = 1; + for (int i = 1; i < line.length(); i++) { + if (isPositionQuoteCharacter(line, i)) { + nestingDepth++; + } + if (nestingDepth > (Config.QUOTING_MAX_DEPTH)) { + return true; + } + } + } + return false; + } } diff --git a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java index eadd562a7..a4c6e67fd 100644 --- a/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +++ b/src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java @@ -142,7 +142,7 @@ public class EditMessage extends EmojiWrapperEditText { } public void insertAsQuote(String text) { - text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", ""); + text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)>", "$1>>").replaceAll("(^|\n)([^>])", "$1> $2").replaceAll("\n$", ""); Editable editable = getEditableText(); int position = getSelectionEnd(); if (position == -1) position = editable.length(); diff --git a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java index 3cb6338db..c9c029c65 100644 --- a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java @@ -39,6 +39,7 @@ import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.http.AesGcmURL; import eu.siacs.conversations.http.URL; +import eu.siacs.conversations.ui.util.QuoteHelper; public class MessageUtils { @@ -69,7 +70,7 @@ public class MessageUtils { continue; } final char c = line.charAt(0); - if (c == '>' && UIHelper.isPositionFollowedByQuoteableCharacter(line, 0) + if (QuoteHelper.isNestedTooDeeply(line) || (c == '\u00bb' && !UIHelper.isPositionFollowedByQuote(line, 0))) { continue; }