Switch to LinkifyCompat.

We've seen some inconsistencies across OEMs with Linkify. Hopefully
LinkifyCompat will resolve them.
fork-5.53.8
Greyson Parrelli 2021-06-26 00:27:06 -04:00
rodzic 5bf23dcfb3
commit fce362960f
4 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -54,6 +54,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.text.util.LinkifyCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import com.annimon.stream.Collectors; import com.annimon.stream.Collectors;
@ -1067,7 +1068,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
boolean shouldLinkifyAllLinks) boolean shouldLinkifyAllLinks)
{ {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS; int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? linkPattern : 0); boolean hasLinks = LinkifyCompat.addLinks(messageBody, shouldLinkifyAllLinks ? linkPattern : 0);
if (hasLinks) { if (hasLinks) {
Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class)) Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class))

Wyświetl plik

@ -13,6 +13,7 @@ import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.text.util.LinkifyCompat;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -38,7 +39,7 @@ public final class GroupDescriptionUtil {
if (linkify) { if (linkify) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS; int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = Linkify.addLinks(descriptionSpannable, linkPattern); boolean hasLinks = LinkifyCompat.addLinks(descriptionSpannable, linkPattern);
if (hasLinks) { if (hasLinks) {
Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class)) Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class))

Wyświetl plik

@ -10,6 +10,7 @@ import android.text.util.Linkify;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.text.util.LinkifyCompat;
import com.annimon.stream.Collectors; import com.annimon.stream.Collectors;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -53,7 +54,7 @@ public final class LinkPreviewUtil {
*/ */
public static @NonNull Links findValidPreviewUrls(@NonNull String text) { public static @NonNull Links findValidPreviewUrls(@NonNull String text) {
SpannableString spannable = new SpannableString(text); SpannableString spannable = new SpannableString(text);
boolean found = Linkify.addLinks(spannable, Linkify.WEB_URLS); boolean found = LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS);
if (!found) { if (!found) {
return Links.EMPTY; return Links.EMPTY;

Wyświetl plik

@ -16,6 +16,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.text.util.LinkifyCompat;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -170,7 +171,7 @@ public class LongMessageActivity extends PassphraseRequiredActivity {
private SpannableString linkifyMessageBody(SpannableString messageBody) { private SpannableString linkifyMessageBody(SpannableString messageBody) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS; int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = Linkify.addLinks(messageBody, linkPattern); boolean hasLinks = LinkifyCompat.addLinks(messageBody, linkPattern);
if (hasLinks) { if (hasLinks) {
Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class)) Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class))