mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 19:58:57 +03:00
Split EmojiDataSource - cleanup
This commit is contained in:
parent
1ad8f47dc1
commit
2972177541
5 changed files with 31 additions and 25 deletions
|
@ -44,9 +44,13 @@ class EmojiSearchResultViewModel(val dataSource: EmojiDataSource, initialState:
|
|||
?.map { it.second }
|
||||
?.filter {
|
||||
it.name.contains(action.queryString, true)
|
||||
|| action.queryString.split("\\s".toRegex()).fold(true, { prev, q ->
|
||||
prev && (it.keywords?.any { it.contains(q, true) } ?: false)
|
||||
})
|
||||
|| action.queryString
|
||||
.split("\\s".toRegex())
|
||||
.fold(true, { prev, q ->
|
||||
prev
|
||||
&& (it.keywords?.any { it.contains(q, true) }
|
||||
?: false)
|
||||
})
|
||||
} ?: emptyList()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
package im.vector.riotx.features.reactions.data
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class EmojiCategory(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val emojis: List<String>
|
||||
@Json(name = "id") val id: String,
|
||||
@Json(name = "name") val name: String,
|
||||
@Json(name = "emojis") val emojis: List<String>
|
||||
)
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
package im.vector.riotx.features.reactions.data
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class EmojiData(
|
||||
val categories: List<EmojiCategory>,
|
||||
val emojis: Map<String, EmojiItem>,
|
||||
val aliases: Map<String, String>
|
||||
@Json(name = "categories") val categories: List<EmojiCategory>,
|
||||
@Json(name = "emojis") val emojis: Map<String, EmojiItem>,
|
||||
@Json(name = "aliases") val aliases: Map<String, String>
|
||||
)
|
||||
|
|
|
@ -31,17 +31,4 @@ class EmojiDataSource(val context: Context) {
|
|||
this.rawData = jsonAdapter.fromJson(inputAsString)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromUnicode(unicode: String): String {
|
||||
val str = unicode.replace("\\", "")
|
||||
val arr = str.split("u".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val text = StringBuffer()
|
||||
for (i in 1 until arr.size) {
|
||||
val hexVal = Integer.parseInt(arr[i], 16)
|
||||
text.append(Character.toChars(hexVal))
|
||||
}
|
||||
return text.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,31 @@ import com.squareup.moshi.JsonClass
|
|||
data class EmojiItem(
|
||||
@Json(name = "a") val name: String,
|
||||
@Json(name = "b") val unicode: String,
|
||||
@Json(name = "j") val keywords: List<String>?,
|
||||
val k: List<String>?) {
|
||||
@Json(name = "j") val keywords: List<String>?
|
||||
) {
|
||||
|
||||
var _emojiText: String? = null
|
||||
|
||||
fun emojiString(): String {
|
||||
if (_emojiText == null) {
|
||||
val utf8Text = unicode.split("-").joinToString("") { "\\u$it" } // "\u0048\u0065\u006C\u006C\u006F World"
|
||||
_emojiText = EmojiDataSource.fromUnicode(utf8Text)
|
||||
_emojiText = fromUnicode(utf8Text)
|
||||
}
|
||||
return _emojiText!!
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun fromUnicode(unicode: String): String {
|
||||
val str = unicode.replace("\\", "")
|
||||
val arr = str.split("u".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
return buildString {
|
||||
for (i in 1 until arr.size) {
|
||||
val hexVal = Integer.parseInt(arr[i], 16)
|
||||
append(Character.toChars(hexVal))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// name: 'a',
|
||||
|
|
Loading…
Add table
Reference in a new issue