Add spoiler format style.

This commit is contained in:
Cody Henthorne
2023-03-22 16:42:30 -04:00
parent 5d6889786c
commit 43cd647036
20 changed files with 662 additions and 57 deletions

View File

@@ -107,6 +107,7 @@ public final class FeatureFlags {
private static final String TEXT_FORMATTING = "android.textFormatting";
private static final String ANY_ADDRESS_PORTS_KILL_SWITCH = "android.calling.fieldTrial.anyAddressPortsKillSwitch";
private static final String CALLS_TAB = "android.calls.tab";
private static final String TEXT_FORMATTING_SPOILER_SEND = "android.textFormatting.spoilerSend";
/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
@@ -164,7 +165,8 @@ public final class FeatureFlags {
PAYPAL_RECURRING_DONATIONS,
TEXT_FORMATTING,
ANY_ADDRESS_PORTS_KILL_SWITCH,
CALLS_TAB
CALLS_TAB,
TEXT_FORMATTING_SPOILER_SEND
);
@VisibleForTesting
@@ -227,7 +229,8 @@ public final class FeatureFlags {
CREDIT_CARD_PAYMENTS,
PAYMENTS_REQUEST_ACTIVATE_FLOW,
CDS_HARD_LIMIT,
TEXT_FORMATTING
TEXT_FORMATTING,
TEXT_FORMATTING_SPOILER_SEND
);
/**
@@ -579,6 +582,13 @@ public final class FeatureFlags {
return getBoolean(TEXT_FORMATTING, false);
}
/**
* Whether or not we should show spoiler text formatting option.
*/
public static boolean textFormattingSpoilerSend() {
return getBoolean(TEXT_FORMATTING_SPOILER_SEND, false);
}
/**
* Enable/disable RingRTC field trial for "AnyAddressPortsKillSwitch"
*/

View File

@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.util;
import android.text.Annotation;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -12,6 +13,7 @@ import com.annimon.stream.Stream;
import org.signal.core.util.StringUtil;
import org.signal.libsignal.protocol.util.Pair;
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation;
import java.security.InvalidParameterException;
import java.util.Collections;
@@ -71,7 +73,10 @@ public class SearchUtil {
CharacterStyle[] styles = styleFactory.createStyles();
for (Pair<Integer, Integer> range : ranges) {
for (CharacterStyle style : styles) {
spanned.setSpan(style, range.first(), range.second(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
List<Annotation> annotations = SpoilerAnnotation.getSpoilerAnnotations(spanned, range.first(), range.second());
if (annotations.isEmpty()) {
spanned.setSpan(style, range.first(), range.second(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}