Commit cfcc4f62 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add different view type to custom emojis, since they need to be displayed on a ImageView

parent 37b86ee9
...@@ -126,7 +126,7 @@ class MainPresenter @Inject constructor( ...@@ -126,7 +126,7 @@ class MainPresenter @Inject constructor(
launchUI(strategy) { launchUI(strategy) {
val customEmojiList = mutableListOf<Emoji>() val customEmojiList = mutableListOf<Emoji>()
try { try {
for (customEmoji in client.getCustomEmojis()) { for (customEmoji in retryIO("getCustomEmojis()") { client.getCustomEmojis() }) {
customEmojiList.add(Emoji( customEmojiList.add(Emoji(
shortname = ":${customEmoji.name}:", shortname = ":${customEmoji.name}:",
category = EmojiCategory.CUSTOM.name, category = EmojiCategory.CUSTOM.name,
...@@ -138,7 +138,6 @@ class MainPresenter @Inject constructor( ...@@ -138,7 +138,6 @@ class MainPresenter @Inject constructor(
siblings = mutableListOf(), siblings = mutableListOf(),
unicode = "" unicode = ""
)) ))
} }
EmojiRepository.load(view as Context, customEmojis = customEmojiList) EmojiRepository.load(view as Context, customEmojis = customEmojiList)
......
...@@ -34,6 +34,8 @@ dependencies { ...@@ -34,6 +34,8 @@ dependencies {
implementation libraries.constraintlayout implementation libraries.constraintlayout
implementation libraries.recyclerview implementation libraries.recyclerview
implementation libraries.material implementation libraries.material
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
} }
kotlin { kotlin {
......
...@@ -19,3 +19,12 @@ ...@@ -19,3 +19,12 @@
# If you keep the line number information, uncomment this to # If you keep the line number information, uncomment this to
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule
...@@ -14,7 +14,10 @@ import chat.rocket.android.emoji.EmojiParser ...@@ -14,7 +14,10 @@ import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiRepository import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.Fitzpatrick import chat.rocket.android.emoji.Fitzpatrick
import chat.rocket.android.emoji.R import chat.rocket.android.emoji.R
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import kotlinx.android.synthetic.main.emoji_category_layout.view.* import kotlinx.android.synthetic.main.emoji_category_layout.view.*
import kotlinx.android.synthetic.main.emoji_image_row_item.view.*
import kotlinx.android.synthetic.main.emoji_row_item.view.* import kotlinx.android.synthetic.main.emoji_row_item.view.*
import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI import kotlinx.coroutines.experimental.android.UI
...@@ -88,6 +91,8 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -88,6 +91,8 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
private val listener: EmojiKeyboardListener private val listener: EmojiKeyboardListener
) : RecyclerView.Adapter<EmojiRowViewHolder>() { ) : RecyclerView.Adapter<EmojiRowViewHolder>() {
private val TYPE_CUSTOM = 1
private val TYPE_NORMAL = 2
private val emojis = mutableListOf<Emoji>() private val emojis = mutableListOf<Emoji>()
fun addEmojis(emojis: List<Emoji>) { fun addEmojis(emojis: List<Emoji>) {
...@@ -96,6 +101,10 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -96,6 +101,10 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
notifyDataSetChanged() notifyDataSetChanged()
} }
override fun getItemViewType(position: Int): Int {
return if (emojis[position].url != null) TYPE_CUSTOM else TYPE_NORMAL
}
suspend fun addEmojisFromSequence(emojiSequence: Sequence<Emoji>) { suspend fun addEmojisFromSequence(emojiSequence: Sequence<Emoji>) {
withContext(CommonPool) { withContext(CommonPool) {
emojiSequence.forEachIndexed { index, emoji -> emojiSequence.forEachIndexed { index, emoji ->
...@@ -120,7 +129,11 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -120,7 +129,11 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EmojiRowViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EmojiRowViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.emoji_row_item, parent, false) val view = if (viewType == TYPE_CUSTOM) {
LayoutInflater.from(parent.context).inflate(R.layout.emoji_image_row_item, parent, false)
} else {
LayoutInflater.from(parent.context).inflate(R.layout.emoji_row_item, parent, false)
}
return EmojiRowViewHolder(view, listener) return EmojiRowViewHolder(view, listener)
} }
...@@ -134,16 +147,23 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -134,16 +147,23 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
fun bind(emoji: Emoji) { fun bind(emoji: Emoji) {
with(itemView) { with(itemView) {
val parsedUnicode = unicodeCache[emoji.unicode] if (emoji.unicode.isNotEmpty()) {
emoji_view.setSpannableFactory(spannableFactory) val parsedUnicode = unicodeCache[emoji.unicode]
emoji_view.text = if (parsedUnicode == null) { emoji_view.setSpannableFactory(spannableFactory)
EmojiParser.parse(emoji.unicode, spannableFactory).let { emoji_view.text = if (parsedUnicode == null) {
unicodeCache[emoji.unicode] = it EmojiParser.parse(emoji.unicode, spannableFactory).let {
it unicodeCache[emoji.unicode] = it
it
}
} else {
parsedUnicode
} }
} else { } else {
parsedUnicode Glide.with(context)
.load(emoji.url)
.into(emoji_image_view)
} }
itemView.setOnClickListener { itemView.setOnClickListener {
listener.onEmojiAdded(emoji) listener.onEmojiAdded(emoji)
} }
...@@ -155,4 +175,4 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) : ...@@ -155,4 +175,4 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
private val unicodeCache = mutableMapOf<CharSequence, CharSequence>() private val unicodeCache = mutableMapOf<CharSequence, CharSequence>()
} }
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/emoji_image_view"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
tools:src="@tools:sample/avatars" />
</FrameLayout>
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:foreground="?selectableItemBackground" android:foreground="?selectableItemBackground"
android:gravity="center"
android:textColor="#000000" android:textColor="#000000"
android:textSize="26sp" android:textSize="26sp"
tools:text="😀" /> tools:text="😀" />
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment