diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index 0ea00bc8..fba94259 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -117,7 +117,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI loadResources() makeNotificationBarTransparent() setContentView(R.layout.activity_account) - + // Obtain information to fill out the profile. viewModel.setAccountInfo(intent.getStringExtra(KEY_ACCOUNT_ID)!!) @@ -364,9 +364,9 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI val usernameFormatted = getString(R.string.status_username_format, account.username) accountUsernameTextView.text = usernameFormatted - accountDisplayNameTextView.text = emojifyString(account.name, account.emojis, accountDisplayNameTextView) + accountDisplayNameTextView.text = account.name.emojify(account.emojis, accountDisplayNameTextView, true) - val emojifiedNote = emojifyText(account.note, account.emojis, accountNoteTextView) + val emojifiedNote = account.note.emojify(account.emojis, accountNoteTextView) LinkHelper.setClickableText(accountNoteTextView, emojifiedNote, null, this) // accountFieldAdapter.fields = account.fields ?: emptyList() @@ -438,7 +438,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI private fun updateToolbar() { loadedAccount?.let { account -> - val emojifiedName = emojifyString(account.name, account.emojis, accountToolbar, true) + val emojifiedName = account.name.emojify(account.emojis, accountToolbar) try { supportActionBar?.title = EmojiCompat.get().process(emojifiedName) @@ -546,7 +546,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI showingReblogs = relation.showingReblogs accountFollowsYouTextView.visible(relation.followedBy) - + // because subscribing is Pleroma extension, enable it __only__ when we have non-null subscribing field if(!viewModel.isSelf && followState == FollowState.FOLLOWING && relation.subscribing != null) { accountSubscribeButton.show() @@ -579,7 +579,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountFollowButton.setText(R.string.action_unfollow) } } - updateSubscribeButton() + updateSubscribeButton() } private fun updateMuteButton() { @@ -589,19 +589,19 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountMuteButton.hide() } } - + private fun updateSubscribeButton() { if(followState != FollowState.FOLLOWING) { accountSubscribeButton.hide() } - + if(subscribing) { accountSubscribeButton.setIconResource(R.drawable.ic_notifications_active_24dp) } else { accountSubscribeButton.setIconResource(R.drawable.ic_notifications_24dp) } } - + private fun updateButtons() { invalidateOptionsMenu() diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountsInListFragment.kt b/app/src/main/java/com/keylesspalace/tusky/AccountsInListFragment.kt index e00d6d93..71aeb1bb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountsInListFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountsInListFragment.kt @@ -209,7 +209,7 @@ class AccountsInListFragment : DialogFragment(), Injectable { } fun bind(account: Account) { - displayNameTextView.text = emojifyString(account.name, account.emojis, displayNameTextView) + displayNameTextView.text = account.name.emojify(account.emojis, displayNameTextView) usernameTextView.text = account.username loadAvatar(account.avatar, avatar, radius, animateAvatar) } @@ -252,7 +252,7 @@ class AccountsInListFragment : DialogFragment(), Injectable { override val containerView = itemView fun bind(account: Account, inAList: Boolean) { - displayNameTextView.text = emojifyString(account.name, account.emojis, displayNameTextView) + displayNameTextView.text = account.name.emojify(account.emojis, displayNameTextView) usernameTextView.text = account.username loadAvatar(account.avatar, avatar, radius, animateAvatar) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt index 0c649cc7..fc1dc6a7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt @@ -592,7 +592,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje private fun updateProfiles() { val profiles: MutableList = accountManager.getAllAccountsOrderedByActive().map { acc -> - val emojifiedName = EmojiCompat.get().process(emojifyString(acc.displayName, acc.emojis, header)) + val emojifiedName = EmojiCompat.get().process(acc.displayName.emojify(acc.emojis, header)) ProfileDrawerItem().apply { isSelected = acc.isActive diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldAdapter.kt index 4f08570b..e80129c6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountFieldAdapter.kt @@ -55,10 +55,10 @@ class AccountFieldAdapter(private val linkListener: LinkListener) : RecyclerView viewHolder.valueTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_check_circle, 0) } else { val field = proofOrField.asRight() - val emojifiedName = emojifyString(field.name, emojis, viewHolder.nameTextView) + val emojifiedName = field.name.emojify(emojis, viewHolder.nameTextView) viewHolder.nameTextView.text = emojifiedName - val emojifiedValue = emojifyText(field.value, emojis, viewHolder.valueTextView) + val emojifiedValue = field.value.emojify(emojis, viewHolder.valueTextView) LinkHelper.setClickableText(viewHolder.valueTextView, emojifiedValue, null, linkListener) if(field.verifiedAt != null) { diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountSelectionAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountSelectionAdapter.kt index 7e4bad6e..dae0db4b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountSelectionAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountSelectionAdapter.kt @@ -42,7 +42,7 @@ class AccountSelectionAdapter(context: Context) : ArrayAdapter(co val displayName = view.display_name val avatar = view.avatar username.text = account.fullName - displayName.text = emojifyString(account.displayName, account.emojis, displayName) + displayName.text = account.displayName.emojify(account.emojis, displayName) val avatarRadius = avatar.context.resources.getDimensionPixelSize(R.dimen.avatar_radius_42dp) val animateAvatar = PreferenceManager.getDefaultSharedPreferences(avatar.context) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java index 97ad4a13..7b07d5bd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java @@ -12,7 +12,7 @@ import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.interfaces.AccountActionListener; import com.keylesspalace.tusky.interfaces.LinkListener; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.ImageLoadingHelper; public class AccountViewHolder extends RecyclerView.ViewHolder { @@ -40,7 +40,7 @@ public class AccountViewHolder extends RecyclerView.ViewHolder { String format = username.getContext().getString(R.string.status_username_format); String formattedUsername = String.format(format, account.getUsername()); username.setText(formattedUsername); - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(account.getName(), account.getEmojis(), displayName); + CharSequence emojifiedName = CustomEmojiHelper.emojify(account.getName(), account.getEmojis(), displayName); displayName.setText(emojifiedName); int avatarRadius = avatar.getContext().getResources() .getDimensionPixelSize(R.dimen.avatar_radius_48dp); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/BlocksAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/BlocksAdapter.java index 0ba44651..3cc686ff 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/BlocksAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/BlocksAdapter.java @@ -29,7 +29,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.interfaces.AccountActionListener; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.ImageLoadingHelper; public class BlocksAdapter extends AccountAdapter { @@ -86,7 +86,7 @@ public class BlocksAdapter extends AccountAdapter { void setupWithAccount(Account account) { id = account.getId(); - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(account.getName(), account.getEmojis(), displayName); + CharSequence emojifiedName = CustomEmojiHelper.emojify(account.getName(), account.getEmojis(), displayName); displayName.setText(emojifiedName); String format = username.getContext().getString(R.string.status_username_format); String formattedUsername = String.format(format, account.getUsername()); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/ComposeAutoCompleteAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/ComposeAutoCompleteAdapter.java index b366acaf..ebc292ab 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/ComposeAutoCompleteAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/ComposeAutoCompleteAdapter.java @@ -31,7 +31,7 @@ import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.Emoji; import com.keylesspalace.tusky.entity.HashTag; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.ImageLoadingHelper; import java.util.ArrayList; @@ -146,7 +146,7 @@ public class ComposeAutoCompleteAdapter extends BaseAdapter account.getUsername() ); accountViewHolder.username.setText(formattedUsername); - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(account.getName(), + CharSequence emojifiedName = CustomEmojiHelper.emojify(account.getName(), account.getEmojis(), accountViewHolder.displayName); accountViewHolder.displayName.setText(emojifiedName); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/FollowRequestViewHolder.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/FollowRequestViewHolder.kt index b973c57b..2c4d2088 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/FollowRequestViewHolder.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/FollowRequestViewHolder.kt @@ -18,7 +18,7 @@ internal class FollowRequestViewHolder(itemView: View, private val showHeader: B fun setupWithAccount(account: Account, formatter: BidiFormatter?) { id = account.id val wrappedName = formatter?.unicodeWrap(account.name) ?: account.name - val emojifiedName: CharSequence = emojifyString(wrappedName, account.emojis, itemView, true) + val emojifiedName: CharSequence = wrappedName.emojify(account.emojis, itemView, true) itemView.displayNameTextView.text = emojifiedName if (showHeader) { itemView.notificationTextView?.text = itemView.context.getString(R.string.notification_follow_request_format, emojifiedName) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/MutedStatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/MutedStatusViewHolder.java index 07ec7f44..66138b24 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/MutedStatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/MutedStatusViewHolder.java @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Emoji; import com.keylesspalace.tusky.interfaces.StatusActionListener; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.util.TimestampUtils; import com.keylesspalace.tusky.viewdata.StatusViewData; @@ -48,7 +48,7 @@ public class MutedStatusViewHolder extends RecyclerView.ViewHolder { } protected void setDisplayName(String name, List customEmojis) { - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(name, customEmojis, displayName, true); + CharSequence emojifiedName = CustomEmojiHelper.emojify(name, customEmojis, displayName, true); displayName.setText(emojifiedName); } diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java index 1d921618..db3a0ae5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java @@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.interfaces.AccountActionListener; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.ImageLoadingHelper; public class MutesAdapter extends AccountAdapter { @@ -71,7 +71,7 @@ public class MutesAdapter extends AccountAdapter { void setupWithAccount(Account account) { id = account.getId(); - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(account.getName(), account.getEmojis(), displayName); + CharSequence emojifiedName = CustomEmojiHelper.emojify(account.getName(), account.getEmojis(), displayName); displayName.setText(emojifiedName); String format = username.getContext().getString(R.string.status_username_format); String formattedUsername = String.format(format, account.getUsername()); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java index 560ea9f6..fe244e21 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java @@ -46,7 +46,7 @@ import com.keylesspalace.tusky.interfaces.AccountActionListener; import com.keylesspalace.tusky.interfaces.LinkListener; import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.util.CardViewMode; -import com.keylesspalace.tusky.util.CustomEmojiHelperKt; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.ImageLoadingHelper; import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.SmartLengthInputFilter; @@ -347,13 +347,13 @@ public class NotificationsAdapter extends RecyclerView.Adapter { String format = context.getString(R.string.notification_follow_format); String wrappedDisplayName = bidiFormatter.unicodeWrap(account.getName()); String wholeMessage = String.format(format, wrappedDisplayName); - CharSequence emojifiedMessage = CustomEmojiHelperKt.emojifyString(wholeMessage, account.getEmojis(), message, true); + CharSequence emojifiedMessage = CustomEmojiHelper.emojify(wholeMessage, account.getEmojis(), message, true); message.setText(emojifiedMessage); String username = context.getString(R.string.status_username_format, account.getUsername()); usernameView.setText(username); - CharSequence emojifiedDisplayName = CustomEmojiHelperKt.emojifyString(wrappedDisplayName, account.getEmojis(), usernameView, true); + CharSequence emojifiedDisplayName = CustomEmojiHelper.emojify(wrappedDisplayName, account.getEmojis(), usernameView, true); displayNameView.setText(emojifiedDisplayName); @@ -429,7 +429,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter { } private void setDisplayName(String name, List emojis) { - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(name, emojis, displayName, true); + CharSequence emojifiedName = CustomEmojiHelper.emojify(name, emojis, displayName, true); displayName.setText(emojifiedName); } @@ -526,7 +526,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter { final SpannableStringBuilder str = new SpannableStringBuilder(wholeMessage); str.setSpan(new StyleSpan(Typeface.BOLD), 0, displayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - CharSequence emojifiedText = CustomEmojiHelperKt.emojifyText(str, notificationViewData.getAccount().getEmojis(), message); + CharSequence emojifiedText = CustomEmojiHelper.emojify(str, notificationViewData.getAccount().getEmojis(), message); message.setText(emojifiedText); if (statusViewData != null) { @@ -621,11 +621,11 @@ public class NotificationsAdapter extends RecyclerView.Adapter { statusContent.setFilters(NO_INPUT_FILTER); } - Spanned emojifiedText = CustomEmojiHelperKt.emojifyText(content, emojis, statusContent); + CharSequence emojifiedText = CustomEmojiHelper.emojify(content, emojis, statusContent); LinkHelper.setClickableText(statusContent, emojifiedText, statusViewData.getMentions(), listener); - Spanned emojifiedContentWarning = - CustomEmojiHelperKt.emojifyString(statusViewData.getSpoilerText(), statusViewData.getStatusEmojis(), contentWarningDescriptionTextView); + CharSequence emojifiedContentWarning = + CustomEmojiHelper.emojify(statusViewData.getSpoilerText(), statusViewData.getStatusEmojis(), contentWarningDescriptionTextView); contentWarningDescriptionTextView.setText(emojifiedContentWarning); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt index 1c004766..2dbf6440 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt @@ -70,7 +70,8 @@ class PollAdapter: RecyclerView.Adapter() { when(mode) { RESULT -> { val percent = calculatePercent(option.votesCount, voteCount) - val emojifiedPollOptionText = emojifyText(buildDescription(option.title, percent, holder.resultTextView.context), emojis, holder.resultTextView) + val emojifiedPollOptionText = buildDescription(option.title, percent, holder.resultTextView.context) + .emojify(emojis, holder.resultTextView) holder.resultTextView.text = EmojiCompat.get().process(emojifiedPollOptionText) val level = percent * 100 @@ -79,7 +80,7 @@ class PollAdapter: RecyclerView.Adapter() { } SINGLE -> { - val emojifiedPollOptionText = emojifyString(option.title, emojis, holder.radioButton) + val emojifiedPollOptionText = option.title.emojify(emojis, holder.radioButton) holder.radioButton.text = EmojiCompat.get().process(emojifiedPollOptionText) holder.radioButton.isChecked = option.selected holder.radioButton.setOnClickListener { @@ -90,7 +91,7 @@ class PollAdapter: RecyclerView.Adapter() { } } MULTIPLE -> { - val emojifiedPollOptionText = emojifyString(option.title, emojis, holder.checkBox) + val emojifiedPollOptionText = option.title.emojify(emojis, holder.checkBox) holder.checkBox.text = EmojiCompat.get().process(emojifiedPollOptionText) holder.checkBox.isChecked = option.selected holder.checkBox.setOnCheckedChangeListener { _, isChecked -> diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 70113a88..a68244cb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -195,7 +195,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { protected abstract int getMediaPreviewHeight(Context context); protected void setDisplayName(String name, List customEmojis) { - CharSequence emojifiedName = CustomEmojiHelperKt.emojifyString(name, customEmojis, displayName, true); + CharSequence emojifiedName = CustomEmojiHelper.emojify(name, customEmojis, displayName, true); displayName.setText(emojifiedName); } @@ -219,7 +219,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { final StatusActionListener listener) { boolean sensitive = !TextUtils.isEmpty(spoilerText); if (sensitive) { - CharSequence emojiSpoiler = CustomEmojiHelperKt.emojifyString(spoilerText, emojis, contentWarningDescription); + CharSequence emojiSpoiler = CustomEmojiHelper.emojify(spoilerText, emojis, contentWarningDescription); contentWarningDescription.setText(emojiSpoiler); contentWarningDescription.setVisibility(View.VISIBLE); contentWarningButton.setVisibility(View.VISIBLE); @@ -258,7 +258,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) { if (expanded) { - Spanned emojifiedText = CustomEmojiHelperKt.emojifyText(content, emojis, this.content); + CharSequence emojifiedText = CustomEmojiHelper.emojify(content, emojis, this.content); LinkHelper.setClickableText(this.content, emojifiedText, mentions, listener); for (int i = 0; i < mediaLabels.length; ++i) { updateMediaLabel(i, sensitive, expanded); diff --git a/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt b/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt index 5f291b4c..93b3a7d2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/report/adapter/StatusViewHolder.kt @@ -89,7 +89,7 @@ class StatusViewHolder( itemView.statusContentWarningButton.hide() itemView.statusContentWarningDescription.hide() } else { - val emojiSpoiler = emojifyString(status.spoilerText, status.emojis, itemView.statusContentWarningDescription) + val emojiSpoiler = status.spoilerText.emojify(status.emojis, itemView.statusContentWarningDescription) itemView.statusContentWarningDescription.text = emojiSpoiler itemView.statusContentWarningDescription.show() itemView.statusContentWarningButton.show() @@ -122,7 +122,7 @@ class StatusViewHolder( emojis: List, listener: LinkListener) { if (expanded) { - val emojifiedText = emojifyText(content, emojis, itemView.statusContent) + val emojifiedText = content.emojify(emojis, itemView.statusContent) LinkHelper.setClickableText(itemView.statusContent, emojifiedText, mentions, listener) } else { LinkHelper.setClickableMentions(itemView.statusContent, mentions, listener) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt b/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt index 29870080..9835b6b9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt @@ -1,5 +1,5 @@ -/* Copyright 2017 Andrew Dawson - * +/* Copyright 2020 Tusky Contributors + * * This file is a part of Tusky. * * This program is free software; you can redistribute it and/or modify it under the terms of the @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License along with Tusky; if not, * see . */ +@file:JvmName("CustomEmojiHelper") package com.keylesspalace.tusky.util import android.graphics.Bitmap @@ -21,8 +22,6 @@ import android.graphics.Paint import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.text.SpannableStringBuilder -import android.text.Spanned -import android.text.SpannedString import android.text.style.ReplacementSpan import android.view.View @@ -43,50 +42,41 @@ import androidx.preference.PreferenceManager * @param view a reference to the a view the emojis will be shown in (should be the TextView, but parents of the TextView are also acceptable) * @return the text with the shortcodes replaced by EmojiSpans */ -fun emojifyText(text: Spanned, emojis: List?, view: View, forceSmallEmoji: Boolean) : Spanned { +fun CharSequence.emojify(emojis: List?, view: View, forceSmallEmoji: Boolean) : CharSequence { + if(emojis.isNullOrEmpty()) + return this + + val builder = SpannableStringBuilder.valueOf(this) val pm = PreferenceManager.getDefaultSharedPreferences(view.context) val smallEmojis = forceSmallEmoji || !pm.getBoolean("bigEmojis", true) // val animatedEmojis = pm.getBoolean("animateEmojis", false) - if (emojis != null && emojis.isNotEmpty()) { - val builder = SpannableStringBuilder(text) - for (emoji in emojis) { - val pattern = StringBuilder(":").append(emoji.shortcode).append(":") - val matcher = Pattern.compile(pattern.toString(), Pattern.LITERAL) - .matcher(text) - while(matcher.find()) { - val span = if(smallEmojis) { - SmallEmojiSpan(WeakReference(view)) - } else { - EmojiSpan(WeakReference(view)) - } - builder.setSpan(span, matcher.start(), matcher.end(), 0); - Glide.with(view) - .asBitmap() - .load(emoji.url) - .into(span.getTarget()) + emojis.forEach { (shortcode, url) -> + val matcher = Pattern.compile(":$shortcode:", Pattern.LITERAL) + .matcher(this) + + while(matcher.find()) { + val span = if(smallEmojis) { + SmallEmojiSpan(WeakReference(view)) + } else { + EmojiSpan(WeakReference(view)) } + + builder.setSpan(span, matcher.start(), matcher.end(), 0); + Glide.with(view) + .asBitmap() + .load(url) + .into(span.getTarget()) } - - return builder } - - return text -} - -fun emojifyText(text: Spanned, emojis: List?, view: View) : Spanned { - return emojifyText(text, emojis, view, false) -} - -fun emojifyString(string: String, emojis: List?, view: View, forceSmallEmoji: Boolean) : Spanned { - return emojifyText(SpannedString(string), emojis, view, forceSmallEmoji) + return builder } -fun emojifyString(string: String, emojis: List?, view: View) : Spanned { - return emojifyString(string, emojis, view, false) +fun CharSequence.emojify(emojis: List?, view: View) : CharSequence { + return this.emojify(emojis, view, false) } -public open class EmojiSpan(val viewWeakReference: WeakReference) : ReplacementSpan() { +open class EmojiSpan(val viewWeakReference: WeakReference) : ReplacementSpan() { var imageDrawable: Drawable? = null override fun getSize(paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?) : Int { @@ -104,27 +94,25 @@ public open class EmojiSpan(val viewWeakReference: WeakReference) : Replac } override fun draw(canvas: Canvas, text: CharSequence, start: Int, end: Int, x: Float, top: Int, y: Int, bottom: Int, paint: Paint) { - if (imageDrawable == null) - return - - canvas.save() - - val emojiSize = getSize(paint, text, start, end, null) - imageDrawable!!.setBounds(0, 0, emojiSize, emojiSize) - - var transY = bottom - imageDrawable!!.bounds.bottom - transY -= paint.fontMetricsInt.descent / 2; - - canvas.translate(x, transY.toFloat()) - imageDrawable!!.draw(canvas) - canvas.restore() + imageDrawable?.let { drawable -> + canvas.save() + + val emojiSize = getSize(paint, text, start, end, null) + drawable.setBounds(0, 0, emojiSize, emojiSize) + + var transY = bottom - drawable.bounds.bottom + transY -= paint.fontMetricsInt.descent / 2; + + canvas.translate(x, transY.toFloat()) + drawable.draw(canvas) + canvas.restore() + } } fun getTarget(): Target { return object : CustomTarget() { override fun onResourceReady(resource: Bitmap, transition: Transition?) { - val view = viewWeakReference.get() - if (view != null) { + viewWeakReference.get()?.let { view -> imageDrawable = BitmapDrawable(view.context.resources, resource) view.invalidate() } @@ -135,7 +123,7 @@ public open class EmojiSpan(val viewWeakReference: WeakReference) : Replac } } -public class SmallEmojiSpan(viewWeakReference: WeakReference) +class SmallEmojiSpan(viewWeakReference: WeakReference) : EmojiSpan(viewWeakReference) { override fun getSize(paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?): Int { if (fm != null) { @@ -150,4 +138,4 @@ public class SmallEmojiSpan(viewWeakReference: WeakReference) return paint.textSize.toInt() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java index f6d5c88c..7a438d9f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java @@ -72,10 +72,10 @@ public class LinkHelper { * @param mentions any '@' mentions which are known to be in the content * @param listener to notify about particular spans that are clicked */ - public static void setClickableText(TextView view, Spanned content, + public static void setClickableText(TextView view, CharSequence content, @Nullable Status.Mention[] mentions, final LinkListener listener) { - SpannableStringBuilder builder = new SpannableStringBuilder(content); - URLSpan[] urlSpans = content.getSpans(0, content.length(), URLSpan.class); + SpannableStringBuilder builder = SpannableStringBuilder.valueOf(content); + URLSpan[] urlSpans = builder.getSpans(0, content.length(), URLSpan.class); for (URLSpan span : urlSpans) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); diff --git a/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt b/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt index 7e3611ee..cb2f0f3a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt @@ -298,7 +298,7 @@ class StatusViewHelper(private val itemView: View) { val percent = calculatePercent(options[i].votesCount, poll.votesCount) val pollOptionText = buildDescription(options[i].title, percent, pollResults[i].context) - pollResults[i].text = emojifyText(pollOptionText, emojis, pollResults[i]) + pollResults[i].text = pollOptionText.emojify(emojis, pollResults[i]) pollResults[i].visibility = View.VISIBLE val level = percent * 100