diff --git a/vector/src/main/java/im/vector/riotx/core/utils/Emoji.kt b/vector/src/main/java/im/vector/riotx/core/utils/Emoji.kt index a5babcc885..9b5552a73b 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/Emoji.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/Emoji.kt @@ -19,7 +19,7 @@ package im.vector.riotx.core.utils import android.content.Context import com.squareup.moshi.Moshi import im.vector.riotx.R -import im.vector.riotx.features.reactions.EmojiDataSource +import im.vector.riotx.features.reactions.data.EmojiData import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import timber.log.Timber @@ -56,7 +56,7 @@ fun initKnownEmojiHashSet(context: Context, done: (() -> Unit)? = null) { GlobalScope.launch { context.resources.openRawResource(R.raw.emoji_picker_datasource).use { input -> val moshi = Moshi.Builder().build() - val jsonAdapter = moshi.adapter(EmojiDataSource.EmojiData::class.java) + val jsonAdapter = moshi.adapter(EmojiData::class.java) val inputAsString = input.bufferedReader().use { it.readText() } val source = jsonAdapter.fromJson(inputAsString) knownEmojiSet = HashSet().also { diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserViewModel.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserViewModel.kt index 1979b02bfd..014250d860 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiChooserViewModel.kt @@ -19,6 +19,7 @@ import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import im.vector.riotx.core.utils.LiveEvent +import im.vector.riotx.features.reactions.data.EmojiDataSource import javax.inject.Inject class EmojiChooserViewModel @Inject constructor() : ViewModel() { diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiRecyclerAdapter.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiRecyclerAdapter.kt index b5270bad29..c7df7fbe7b 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiRecyclerAdapter.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiRecyclerAdapter.kt @@ -30,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView import androidx.transition.AutoTransition import androidx.transition.TransitionManager import im.vector.riotx.R +import im.vector.riotx.features.reactions.data.EmojiDataSource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultItem.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultItem.kt index 746fdddbf3..b3e70bcdf6 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultItem.kt @@ -23,12 +23,13 @@ import com.airbnb.epoxy.EpoxyModelWithHolder import im.vector.riotx.R import im.vector.riotx.core.epoxy.VectorEpoxyHolder import im.vector.riotx.core.extensions.setTextOrHide +import im.vector.riotx.features.reactions.data.EmojiItem @EpoxyModelClass(layout = R.layout.item_emoji_result) abstract class EmojiSearchResultItem : EpoxyModelWithHolder() { @EpoxyAttribute - lateinit var emojiItem: EmojiDataSource.EmojiItem + lateinit var emojiItem: EmojiItem @EpoxyAttribute var currentQuery: String? = null diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultViewModel.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultViewModel.kt index 8225fa7bd6..96746e583e 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultViewModel.kt @@ -19,10 +19,12 @@ import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.ViewModelContext import im.vector.riotx.core.platform.VectorViewModel +import im.vector.riotx.features.reactions.data.EmojiDataSource +import im.vector.riotx.features.reactions.data.EmojiItem data class EmojiSearchResultViewState( val query: String = "", - val results: List = emptyList() + val results: List = emptyList() ) : MvRxState class EmojiSearchResultViewModel(val dataSource: EmojiDataSource, initialState: EmojiSearchResultViewState) diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiCategory.kt b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiCategory.kt new file mode 100644 index 0000000000..9aa7428047 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiCategory.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.reactions.data + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class EmojiCategory( + val id: String, + val name: String, + val emojis: List +) diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiData.kt b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiData.kt new file mode 100644 index 0000000000..9db9a01ce8 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiData.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.reactions.data + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class EmojiData( + val categories: List, + val emojis: Map, + val aliases: Map +) diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiDataSource.kt b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt similarity index 51% rename from vector/src/main/java/im/vector/riotx/features/reactions/EmojiDataSource.kt rename to vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt index 2853975938..794fdbfe12 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiDataSource.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiDataSource.kt @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotx.features.reactions +package im.vector.riotx.features.reactions.data import android.content.Context -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass import com.squareup.moshi.Moshi import im.vector.riotx.R @@ -31,32 +29,6 @@ class EmojiDataSource(val context: Context) { val jsonAdapter = moshi.adapter(EmojiData::class.java) val inputAsString = input.bufferedReader().use { it.readText() } this.rawData = jsonAdapter.fromJson(inputAsString) - // this.rawData = mb.fr(InputStreamReader(it), EmojiData::class.java) - } - } - @JsonClass(generateAdapter = true) - data class EmojiData(val categories: List, - val emojis: Map, - val aliases: Map) - - @JsonClass(generateAdapter = true) - data class EmojiCategory(val id: String, val name: String, val emojis: List) - - @JsonClass(generateAdapter = true) - data class EmojiItem( - @Json(name = "a") val name: String, - @Json(name = "b") val unicode: String, - @Json(name = "j") val keywords: List?, - val k: List?) { - - 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!! } } @@ -72,20 +44,4 @@ class EmojiDataSource(val context: Context) { return text.toString() } } - -// 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', } 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 new file mode 100644 index 0000000000..95deb32279 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/reactions/data/EmojiItem.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.reactions.data + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class EmojiItem( + @Json(name = "a") val name: String, + @Json(name = "b") val unicode: String, + @Json(name = "j") val keywords: List?, + val k: List?) { + + 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) + } + return _emojiText!! + } +} + +// 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',