Update emoji_picker_datasource.json to Unicode 13.1 and dynamically filter reactions by renderability
This commit is contained in:
parent
e8d4fab305
commit
e8015bfbd4
@ -41,6 +41,7 @@ Improvements 🙌:
|
||||
- Sending is now queuing by room and not uniquely to the session
|
||||
- Improve Snackbar duration (#2929)
|
||||
- Improve sending message state (#2937)
|
||||
- Update reactions to Unicode 13.1 (#1481)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Try to fix crash about UrlPreview (#2640)
|
||||
|
@ -42,17 +42,15 @@ class EmojiDataSourceTest : InstrumentedTest {
|
||||
@Test
|
||||
fun checkNumberOfResult() {
|
||||
val emojiDataSource = EmojiDataSource(context().resources)
|
||||
|
||||
assertEquals("Wrong number of emojis", 1545, emojiDataSource.rawData.emojis.size)
|
||||
assertEquals("Wrong number of categories", 8, emojiDataSource.rawData.categories.size)
|
||||
assertEquals("Wrong number of aliases", 57, emojiDataSource.rawData.aliases.size)
|
||||
assertTrue("Wrong number of emojis", emojiDataSource.rawData.emojis.size >= 500)
|
||||
assertTrue("Wrong number of categories", emojiDataSource.rawData.categories.size >= 8)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun searchTestEmptySearch() {
|
||||
val emojiDataSource = EmojiDataSource(context().resources)
|
||||
|
||||
assertEquals("Empty search should return 1545 results", 1545, emojiDataSource.filterWith("").size)
|
||||
assertTrue("Empty search should return at least 500 results", emojiDataSource.filterWith("").size >= 500)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,6 +16,8 @@
|
||||
package im.vector.app.features.reactions.data
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Paint
|
||||
import androidx.core.graphics.PaintCompat
|
||||
import com.squareup.moshi.Moshi
|
||||
import im.vector.app.R
|
||||
import javax.inject.Inject
|
||||
@ -25,6 +27,7 @@ import javax.inject.Singleton
|
||||
class EmojiDataSource @Inject constructor(
|
||||
resources: Resources
|
||||
) {
|
||||
private val paint = Paint()
|
||||
val rawData = resources.openRawResource(R.raw.emoji_picker_datasource)
|
||||
.use { input ->
|
||||
Moshi.Builder()
|
||||
@ -34,18 +37,32 @@ class EmojiDataSource @Inject constructor(
|
||||
}
|
||||
?.let { parsedRawData ->
|
||||
// Add key as a keyword, it will solve the issue that ":tada" is not available in completion
|
||||
// Only add emojis to emojis/categories that can be rendered by the system
|
||||
parsedRawData.copy(
|
||||
emojis = mutableMapOf<String, EmojiItem>().apply {
|
||||
parsedRawData.emojis.keys.forEach { key ->
|
||||
val origin = parsedRawData.emojis[key] ?: return@forEach
|
||||
|
||||
// Do not add keys containing '_'
|
||||
if (origin.keywords.contains(key) || key.contains("_")) {
|
||||
put(key, origin)
|
||||
} else {
|
||||
put(key, origin.copy(keywords = origin.keywords + key))
|
||||
if (isEmojiRenderable(origin.emoji)) {
|
||||
if (origin.keywords.contains(key) || key.contains("_")) {
|
||||
put(key, origin)
|
||||
} else {
|
||||
put(key, origin.copy(keywords = origin.keywords + key))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
categories = mutableListOf<EmojiCategory>().apply {
|
||||
parsedRawData.categories.forEach { entry ->
|
||||
add(EmojiCategory(entry.id, entry.name, mutableListOf<String>().apply {
|
||||
entry.emojis.forEach { e ->
|
||||
if (isEmojiRenderable(parsedRawData.emojis[e]!!.emoji)) {
|
||||
add(e)
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -53,6 +70,10 @@ class EmojiDataSource @Inject constructor(
|
||||
|
||||
private val quickReactions = mutableListOf<EmojiItem>()
|
||||
|
||||
private fun isEmojiRenderable(emoji: String): Boolean {
|
||||
return PaintCompat.hasGlyph(paint, emoji)
|
||||
}
|
||||
|
||||
fun filterWith(query: String): List<EmojiItem> {
|
||||
val words = query.split("\\s".toRegex())
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user