diff --git a/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiController.kt b/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiController.kt index e0d7bdd888..bef43d8b14 100644 --- a/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiController.kt +++ b/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiController.kt @@ -23,7 +23,6 @@ import im.vector.riotx.EmojiCompatFontProvider import im.vector.riotx.features.autocomplete.AutocompleteClickListener import im.vector.riotx.features.reactions.ReactionClickListener import im.vector.riotx.features.reactions.data.EmojiItem -import im.vector.riotx.features.reactions.emojiSearchResultItem import javax.inject.Inject class AutocompleteEmojiController @Inject constructor( @@ -49,16 +48,16 @@ class AutocompleteEmojiController @Inject constructor( return } data.forEach { emojiItem -> - emojiSearchResultItem { + autocompleteEmojiItem { id(emojiItem.name) emojiItem(emojiItem) emojiTypeFace(emojiTypeface) - //currentQuery(data.query) - onClickListener(object : ReactionClickListener { - override fun onReactionSelected(reaction: String) { - listener?.onItemClick(reaction) - } - } + onClickListener( + object : ReactionClickListener { + override fun onReactionSelected(reaction: String) { + listener?.onItemClick(reaction) + } + } ) } } diff --git a/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiItem.kt b/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiItem.kt index e5c53315ab..36759f9271 100644 --- a/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/autocomplete/emoji/AutocompleteEmojiItem.kt @@ -16,37 +16,43 @@ package im.vector.riotx.features.autocomplete.emoji -import android.view.View +import android.graphics.Typeface import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.epoxy.VectorEpoxyModel +import im.vector.riotx.core.extensions.setTextOrHide +import im.vector.riotx.features.reactions.ReactionClickListener +import im.vector.riotx.features.reactions.data.EmojiItem -//@EpoxyModelClass(layout = R.layout.item_autocomplete_emoji) -//abstract class AutocompleteEmojiItem : VectorEpoxyModel() { -// -// @EpoxyAttribute -// var name: CharSequence? = null -// @EpoxyAttribute -// var parameters: CharSequence? = null -// @EpoxyAttribute -// var description: CharSequence? = null -// @EpoxyAttribute -// var clickListener: View.OnClickListener? = null -// -// override fun bind(holder: Holder) { -// holder.view.setOnClickListener(clickListener) -// -// holder.nameView.text = name -// holder.parametersView.text = parameters -// holder.descriptionView.text = description -// } -// -// class Holder : VectorEpoxyHolder() { -// val nameView by bind(R.id.commandName) -// val parametersView by bind(R.id.commandParameter) -// val descriptionView by bind(R.id.commandDescription) -// } -//} +@EpoxyModelClass(layout = R.layout.item_autocomplete_emoji) +abstract class AutocompleteEmojiItem : VectorEpoxyModel() { + + @EpoxyAttribute + lateinit var emojiItem: EmojiItem + + @EpoxyAttribute + var emojiTypeFace: Typeface? = null + + @EpoxyAttribute + var onClickListener: ReactionClickListener? = null + + override fun bind(holder: Holder) { + holder.emojiText.text = emojiItem.emoji + holder.emojiText.typeface = emojiTypeFace ?: Typeface.DEFAULT + holder.emojiNameText.text = emojiItem.name + holder.emojiKeywordText.setTextOrHide(emojiItem.keywords.joinToString()) + + holder.view.setOnClickListener { + onClickListener?.onReactionSelected(emojiItem.emoji) + } + } + + class Holder : VectorEpoxyHolder() { + val emojiText by bind(R.id.itemAutocompleteEmoji) + val emojiNameText by bind(R.id.itemAutocompleteEmojiName) + val emojiKeywordText by bind(R.id.itemAutocompleteEmojiSubname) + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/AutoCompleter.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/AutoCompleter.kt index 9fe2249450..78ddf80a84 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/AutoCompleter.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/AutoCompleter.kt @@ -172,10 +172,20 @@ class AutoCompleter @Inject constructor( .with(backgroundDrawable) .with(object : AutocompleteCallback { override fun onPopupItemClicked(editable: Editable, item: String): Boolean { - editable.clear() - editable - .append(item) - .append(" ") + // Detect last ":" and remove it + var startIndex = editable.lastIndexOf(":") + if (startIndex == -1) { + startIndex = 0 + } + + // Detect next word separator + var endIndex = editable.indexOf(" ", startIndex) + if (endIndex == -1) { + endIndex = editable.length + } + + // Replace the word by its completion + editable.replace(startIndex, endIndex, item) return true } diff --git a/vector/src/main/res/layout/item_autocomplete_emoji.xml b/vector/src/main/res/layout/item_autocomplete_emoji.xml new file mode 100644 index 0000000000..650a405f34 --- /dev/null +++ b/vector/src/main/res/layout/item_autocomplete_emoji.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + \ No newline at end of file