Skip to content

Commit

Permalink
using EmojiCompat callback to process emoji through latest compatibil…
Browse files Browse the repository at this point in the history
…ity Font
  • Loading branch information
mzorz committed Nov 8, 2019
1 parent e6df0f3 commit 21430d8
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.emoji.text.EmojiCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.automattic.photoeditor.PhotoEditor
Expand Down Expand Up @@ -75,7 +76,26 @@ class EmojiPickerFragment : BottomSheetDialogFragment() {
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.txtEmojiRef.text = emojiList[position]
// holder.txtEmojiRef.text = emojiList[position]
// use EmojiCompat to process the string and make sure we have an emoji that can be rendered
EmojiCompat.get().registerInitCallback(object : EmojiCompat.InitCallback() {
override fun onInitialized() {
EmojiCompat.get().unregisterInitCallback(this)

val regularTextView = holder.txtEmojiRef
if (regularTextView != null) {
val compat = EmojiCompat.get()
regularTextView.text = compat.process(emojiList[position])
}
}

override fun onFailed(throwable: Throwable?) {
EmojiCompat.get().unregisterInitCallback(this)

// just fallback to setting the text
holder.txtEmojiRef.text = emojiList[position]
}
})
}

override fun getItemCount(): Int {
Expand Down

0 comments on commit 21430d8

Please sign in to comment.