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(
launchUI(strategy) {
val customEmojiList = mutableListOf<Emoji>()
try {
for (customEmoji in client.getCustomEmojis()) {
for (customEmoji in retryIO("getCustomEmojis()") { client.getCustomEmojis() }) {
customEmojiList.add(Emoji(
shortname = ":${customEmoji.name}:",
category = EmojiCategory.CUSTOM.name,
......@@ -138,7 +138,6 @@ class MainPresenter @Inject constructor(
siblings = mutableListOf(),
unicode = ""
))
}
EmojiRepository.load(view as Context, customEmojis = customEmojiList)
......
......@@ -34,6 +34,8 @@ dependencies {
implementation libraries.constraintlayout
implementation libraries.recyclerview
implementation libraries.material
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
kotlin {
......
......@@ -19,3 +19,12 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-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
import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.Fitzpatrick
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_image_row_item.view.*
import kotlinx.android.synthetic.main.emoji_row_item.view.*
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI
......@@ -88,6 +91,8 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
private val listener: EmojiKeyboardListener
) : RecyclerView.Adapter<EmojiRowViewHolder>() {
private val TYPE_CUSTOM = 1
private val TYPE_NORMAL = 2
private val emojis = mutableListOf<Emoji>()
fun addEmojis(emojis: List<Emoji>) {
......@@ -96,6 +101,10 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
notifyDataSetChanged()
}
override fun getItemViewType(position: Int): Int {
return if (emojis[position].url != null) TYPE_CUSTOM else TYPE_NORMAL
}
suspend fun addEmojisFromSequence(emojiSequence: Sequence<Emoji>) {
withContext(CommonPool) {
emojiSequence.forEachIndexed { index, emoji ->
......@@ -120,7 +129,11 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
}
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)
}
......@@ -134,16 +147,23 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
fun bind(emoji: Emoji) {
with(itemView) {
val parsedUnicode = unicodeCache[emoji.unicode]
emoji_view.setSpannableFactory(spannableFactory)
emoji_view.text = if (parsedUnicode == null) {
EmojiParser.parse(emoji.unicode, spannableFactory).let {
unicodeCache[emoji.unicode] = it
it
if (emoji.unicode.isNotEmpty()) {
val parsedUnicode = unicodeCache[emoji.unicode]
emoji_view.setSpannableFactory(spannableFactory)
emoji_view.text = if (parsedUnicode == null) {
EmojiParser.parse(emoji.unicode, spannableFactory).let {
unicodeCache[emoji.unicode] = it
it
}
} else {
parsedUnicode
}
} else {
parsedUnicode
Glide.with(context)
.load(emoji.url)
.into(emoji_image_view)
}
itemView.setOnClickListener {
listener.onEmojiAdded(emoji)
}
......@@ -155,4 +175,4 @@ internal class EmojiPagerAdapter(private val listener: EmojiKeyboardListener) :
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 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:foreground="?selectableItemBackground"
android:gravity="center"
android:textColor="#000000"
android:textSize="26sp"
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