Use SpannableString instead of SpannableStringBuilder when it's possible

main
Alibek Omarov 4 years ago
parent f18f7aab5c
commit ed16f1b2bc
  1. 13
      app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt
  2. 3
      app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java
  3. 7
      app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt
  4. 3
      app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java

@ -68,20 +68,19 @@ private fun TextView.setClickableTextWithoutUnderlines(@StringRes textId: Int) {
Linkify.addLinks(text, Linkify.WEB_URLS)
val builder = SpannableStringBuilder(text)
val urlSpans = text.getSpans(0, text.length, URLSpan::class.java)
for (span in urlSpans) {
val start = builder.getSpanStart(span)
val end = builder.getSpanEnd(span)
val flags = builder.getSpanFlags(span)
val start = text.getSpanStart(span)
val end = text.getSpanEnd(span)
val flags = text.getSpanFlags(span)
val customSpan = object : CustomURLSpan(span.url) {}
builder.removeSpan(span)
builder.setSpan(customSpan, start, end, flags)
text.removeSpan(span)
text.setSpan(customSpan, start, end, flags)
}
setText(builder)
setText(text)
linksClickable = true
movementMethod = LinkMovementMethod.getInstance()

@ -21,6 +21,7 @@ import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.InputFilter;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@ -523,7 +524,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
}
}
message.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
final SpannableStringBuilder str = new SpannableStringBuilder(wholeMessage);
final SpannableString str = new SpannableString(wholeMessage);
str.setSpan(new StyleSpan(Typeface.BOLD), 0, displayName.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
CharSequence emojifiedText = CustomEmojiHelper.emojify(str, notificationViewData.getAccount().getEmojis(), message, true);

@ -21,9 +21,12 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ReplacementSpan
import android.view.View
import androidx.core.text.toSpannable
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
@ -46,7 +49,7 @@ fun CharSequence.emojify(emojis: List<Emoji>?, view: View, forceSmallEmoji: Bool
if(emojis.isNullOrEmpty())
return this
val builder = SpannableStringBuilder.valueOf(this)
val builder = SpannableString.valueOf(this)
val pm = PreferenceManager.getDefaultSharedPreferences(view.context)
val smallEmojis = forceSmallEmoji || !pm.getBoolean("bigEmojis", true)
// val animatedEmojis = pm.getBoolean("animateEmojis", false)
@ -62,7 +65,7 @@ fun CharSequence.emojify(emojis: List<Emoji>?, view: View, forceSmallEmoji: Bool
EmojiSpan(WeakReference<View>(view))
}
builder.setSpan(span, matcher.start(), matcher.end(), 0);
builder.setSpan(span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Glide.with(view)
.asBitmap()
.load(url)

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
@ -187,7 +188,7 @@ public class LinkHelper {
public static CharSequence createClickableText(String text, String link) {
URLSpan span = new CustomURLSpan(link);
SpannableStringBuilder clickableText = new SpannableStringBuilder(text);
SpannableString clickableText = new SpannableString(text);
clickableText.setSpan(span, 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return clickableText;
}

Loading…
Cancel
Save