From cb593ebb147c73f53f815223559003547156267d Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Fri, 7 Apr 2023 11:27:37 +0200 Subject: [PATCH] Move standard emojis to top of autocompletion Now that we can limit emojis per category while allowing to expand them, makes sense to show standard emojis on top, above custom emotes, especially when users have lots of emotes. Change-Id: I822cc091bf595795fa08fef32f0737073a43163a --- .../emoji/AutocompleteEmojiController.kt | 9 +++++++-- .../emoji/AutocompleteEmojiPresenter.kt | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiController.kt b/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiController.kt index 7f78a4816e..1cb120f4cf 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiController.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiController.kt @@ -110,8 +110,12 @@ class AutocompleteEmojiController @Inject constructor( } companion object { + // Count of standard emoji matches - WARN: do not set to 8 or less, or epoxy/recycler will sometimes crash with some class casts, + // e.g. when repeatedly typing `:turt`, then deleting back to `:`?!? + // What makes 8 magic? Probably that no-search proposals also returns 8 results? But wtf? + const val STANDARD_EMOJI_MAX = 9 // Count of emojis for the current room's image pack - const val CUSTOM_THIS_ROOM_MAX = 10 + const val CUSTOM_THIS_ROOM_MAX = 8 // Count of emojis per other image pack const val CUSTOM_OTHER_ROOM_MAX = 5 // Count of emojis for global account data @@ -122,7 +126,8 @@ class AutocompleteEmojiController @Inject constructor( const val MAX = 50 // Total max after expanding a section const val MAX_EXPAND = 10000 - // Internal ID + // Internal IDs const val ACCOUNT_DATA_EMOTE_ID = "de.spiritcroc.riotx.ACCOUNT_DATA_EMOTES" + const val STANDARD_EMOJI_ID = "de.spiritcroc.riotx.STANDARD_EMOJI" } } diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiPresenter.kt index 95d61a08cd..5d893788e2 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/emoji/AutocompleteEmojiPresenter.kt @@ -105,12 +105,19 @@ class AutocompleteEmojiPresenter @AssistedInject constructor( lastQuery = query coroutineScope.launch { // Plain emojis + val fullStandardEmojis: List val data = if (query.isNullOrBlank()) { // Return common emojis - emojiDataSource.getQuickReactions() + fullStandardEmojis = emojiDataSource.getQuickReactions() + fullStandardEmojis } else { - emojiDataSource.filterWith(query.toString()) - }.toAutocompleteItems() + fullStandardEmojis = emojiDataSource.filterWith(query.toString()) + fullStandardEmojis.maybeLimit(AutocompleteEmojiController.STANDARD_EMOJI_MAX, AutocompleteEmojiController.STANDARD_EMOJI_ID, null) + }.toAutocompleteItems().toMutableList() + + if (fullStandardEmojis.size > data.size) { + data += listOf(AutocompleteEmojiDataItem.Expand(AutocompleteEmojiController.STANDARD_EMOJI_ID, null, fullStandardEmojis.size - data.size)) + } // Custom emotes: This room's emotes val currentRoomEmotes = room.getAllEmojiItems(query) @@ -203,12 +210,7 @@ class AutocompleteEmojiPresenter @AssistedInject constructor( } } - val dataHeader = if (data.isNotEmpty() && emoteData.isNotEmpty()) { - listOf(AutocompleteEmojiDataItem.Header("de.spiritcroc.riotx.STANDARD_EMOJI_HEADER", context.getString(R.string.standard_emojis))) - } else { - emptyList() - } - controller.setData(emoteData + dataHeader + data) + controller.setData(data + emoteData) } }