From 80306f20dfcd2d135d796751a8e6026aa31b0a43 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 9 Dec 2019 22:57:23 +0100 Subject: [PATCH] Split EmojiDataSource - avoid !! --- .../features/reactions/data/EmojiItem.kt | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiItem.kt b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiItem.kt index fc0959dfbb..9b4600b5c1 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiItem.kt @@ -19,6 +19,23 @@ package im.vector.riotx.features.reactions.data import com.squareup.moshi.Json import com.squareup.moshi.JsonClass +/** + * name: 'a', + * unified: 'b', + * non_qualified: 'c', + * has_img_apple: 'd', + * has_img_google: 'e', + * has_img_twitter: 'f', + * has_img_emojione: 'g', + * has_img_facebook: 'h', + * has_img_messenger: 'i', + * keywords: 'j', + * sheet: 'k', + * emoticons: 'l', + * text: 'm', + * short_names: 'n', + * added_in: 'o' + */ @JsonClass(generateAdapter = true) data class EmojiItem( @Json(name = "a") val name: String, @@ -26,14 +43,14 @@ data class EmojiItem( @Json(name = "j") val keywords: List? ) { - var _emojiText: String? = null + private var emojiText: String? = null fun emojiString(): String { - if (_emojiText == null) { - val utf8Text = unicode.split("-").joinToString("") { "\\u$it" } // "\u0048\u0065\u006C\u006C\u006F World" - _emojiText = fromUnicode(utf8Text) - } - return _emojiText!! + emojiText?.let { return it } + + val utf8Text = unicode.split("-").joinToString("") { "\\u$it" } // "\u0048\u0065\u006C\u006C\u006F World" + return fromUnicode(utf8Text) + .also { emojiText = it } } companion object { @@ -50,18 +67,3 @@ data class EmojiItem( } } -// name: 'a', -// unified: 'b', -// non_qualified: 'c', -// has_img_apple: 'd', -// has_img_google: 'e', -// has_img_twitter: 'f', -// has_img_emojione: 'g', -// has_img_facebook: 'h', -// has_img_messenger: 'i', -// keywords: 'j', -// sheet: 'k', -// emoticons: 'l', -// text: 'm', -// short_names: 'n', -// added_in: 'o',