Move list of Quick Emoji to Emoji Data Source

This commit is contained in:
Benoit Marty 2020-01-02 10:42:01 +01:00
parent 9ecceafb96
commit 448552d287
4 changed files with 25 additions and 16 deletions

View file

@ -43,6 +43,7 @@ import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformatio
import im.vector.riotx.features.html.EventHtmlRenderer import im.vector.riotx.features.html.EventHtmlRenderer
import im.vector.riotx.features.html.VectorHtmlCompressor import im.vector.riotx.features.html.VectorHtmlCompressor
import im.vector.riotx.features.settings.VectorPreferences import im.vector.riotx.features.settings.VectorPreferences
import im.vector.riotx.features.reactions.data.EmojiDataSource
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -101,9 +102,6 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
} }
companion object : MvRxViewModelFactory<MessageActionsViewModel, MessageActionState> { companion object : MvRxViewModelFactory<MessageActionsViewModel, MessageActionState> {
val quickEmojis = listOf("👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀")
@JvmStatic @JvmStatic
override fun create(viewModelContext: ViewModelContext, state: MessageActionState): MessageActionsViewModel? { override fun create(viewModelContext: ViewModelContext, state: MessageActionState): MessageActionsViewModel? {
val fragment: MessageActionsBottomSheet = (viewModelContext as FragmentViewModelContext).fragment() val fragment: MessageActionsBottomSheet = (viewModelContext as FragmentViewModelContext).fragment()
@ -161,7 +159,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
RxRoom(room) RxRoom(room)
.liveAnnotationSummary(eventId) .liveAnnotationSummary(eventId)
.map { annotations -> .map { annotations ->
quickEmojis.map { emoji -> EmojiDataSource.quickEmojis.map { emoji ->
ToggleState(emoji, annotations.getOrNull()?.reactionsSummary?.firstOrNull { it.key == emoji }?.addedByMe ?: false) ToggleState(emoji, annotations.getOrNull()?.reactionsSummary?.firstOrNull { it.key == emoji }?.addedByMe ?: false)
} }
} }

View file

@ -34,6 +34,8 @@ class EmojiDataSource @Inject constructor(
} }
?: EmojiData(emptyList(), emptyMap(), emptyMap()) ?: EmojiData(emptyList(), emptyMap(), emptyMap())
private val quickReactions = mutableListOf<EmojiItem>()
fun filterWith(query: String): List<EmojiItem> { fun filterWith(query: String): List<EmojiItem> {
val words = query.split("\\s".toRegex()) val words = query.split("\\s".toRegex())
@ -56,7 +58,8 @@ class EmojiDataSource @Inject constructor(
} }
fun getQuickReactions(): List<EmojiItem> { fun getQuickReactions(): List<EmojiItem> {
return listOf( if (quickReactions.isEmpty()) {
listOf(
"+1", // 👍 "+1", // 👍
"-1", // 👎 "-1", // 👎
"grinning", // 😄 "grinning", // 😄
@ -65,6 +68,14 @@ class EmojiDataSource @Inject constructor(
"heart", // ❤️ "heart", // ❤️
"rocket", // 🚀 "rocket", // 🚀
"eyes" // 👀 "eyes" // 👀
).mapNotNull { rawData.emojis[it] } )
.mapNotNullTo(quickReactions) { rawData.emojis[it] }
}
return quickReactions
}
companion object {
val quickEmojis = listOf("👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀")
} }
} }

View file

@ -18,6 +18,6 @@
<string name="devices_current_device">Current device</string> <string name="devices_current_device">Current device</string>
<string name="devices_other_devices">Other devices</string> <string name="devices_other_devices">Other devices</string>
<string name="autocomplete_limited_results">Limited results, please type more letters…</string> <string name="autocomplete_limited_results">Showing only the first results, type more letters…</string>
</resources> </resources>