Quoting quotes, limited by nesting depth.
This commit is contained in:
parent
74d60d0131
commit
e850900b40
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue