mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Improved emoji library loading wait
This commit is contained in:
parent
c90961408f
commit
9b61700b79
3 changed files with 60 additions and 8 deletions
|
|
@ -21,13 +21,17 @@ package org.linphone.ui.main.contacts.viewmodel
|
|||
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.emoji2.text.EmojiCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import java.io.File
|
||||
import java.text.Collator
|
||||
import java.util.ArrayList
|
||||
import java.util.Locale
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.contacts.ContactsManager.ContactsListener
|
||||
|
|
@ -101,6 +105,24 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
}
|
||||
|
||||
applyFilter(currentFilter)
|
||||
|
||||
val emojiCompat = coreContext.emojiCompat
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Wait for emoji compat library to have been loaded
|
||||
if (emojiCompat.loadState != EmojiCompat.LOAD_STATE_SUCCEEDED) {
|
||||
Log.i("$TAG Waiting for emoji compat library to have been loaded")
|
||||
while (emojiCompat.loadState == EmojiCompat.LOAD_STATE_DEFAULT || emojiCompat.loadState == EmojiCompat.LOAD_STATE_LOADING) {
|
||||
delay(50)
|
||||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
Log.i("$TAG Emoji compat library loaded, update contacts list")
|
||||
processMagicSearchResults(magicSearch.lastSearch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
@ -207,6 +229,7 @@ class ContactsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
|
|||
|
||||
@WorkerThread
|
||||
private fun processMagicSearchResults(results: Array<SearchResult>) {
|
||||
// Do not call destroy() on previous list items as they are cached and will be re-used
|
||||
Log.i("$TAG Processing [${results.size}] results")
|
||||
|
||||
val list = arrayListOf<ContactAvatarModel>()
|
||||
|
|
|
|||
|
|
@ -153,23 +153,28 @@ open class AbstractTopBarViewModel @UiThread constructor() : ViewModel() {
|
|||
init {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.addListener(coreListener)
|
||||
configure()
|
||||
}
|
||||
|
||||
searchBarVisible.value = false
|
||||
|
||||
val emojiCompat = coreContext.emojiCompat
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Wait for emoji compat library to have been loaded
|
||||
Log.i("$TAG Waiting for emoji compat library to have been loaded")
|
||||
while (emojiCompat.loadState == EmojiCompat.LOAD_STATE_DEFAULT || emojiCompat.loadState == EmojiCompat.LOAD_STATE_LOADING) {
|
||||
delay(50)
|
||||
}
|
||||
coreContext.postOnCoreThread {
|
||||
configure()
|
||||
if (emojiCompat.loadState != EmojiCompat.LOAD_STATE_SUCCEEDED) {
|
||||
Log.i("$TAG Waiting for emoji compat library to have been loaded")
|
||||
while (emojiCompat.loadState == EmojiCompat.LOAD_STATE_DEFAULT || emojiCompat.loadState == EmojiCompat.LOAD_STATE_LOADING) {
|
||||
delay(50)
|
||||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
Log.i("$TAG Emoji compat library loaded, update account")
|
||||
configure()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
searchBarVisible.value = false
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -22,8 +22,14 @@ package org.linphone.ui.main.viewmodel
|
|||
import android.view.View
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.emoji2.text.EmojiCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Account
|
||||
import org.linphone.core.Core
|
||||
|
|
@ -97,6 +103,24 @@ class DrawerMenuViewModel @UiThread constructor() : ViewModel() {
|
|||
core.addListener(coreListener)
|
||||
|
||||
computeAccountsList()
|
||||
|
||||
val emojiCompat = coreContext.emojiCompat
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Wait for emoji compat library to have been loaded
|
||||
if (emojiCompat.loadState != EmojiCompat.LOAD_STATE_SUCCEEDED) {
|
||||
Log.i("$TAG Waiting for emoji compat library to have been loaded")
|
||||
while (emojiCompat.loadState == EmojiCompat.LOAD_STATE_DEFAULT || emojiCompat.loadState == EmojiCompat.LOAD_STATE_LOADING) {
|
||||
delay(50)
|
||||
}
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
Log.i("$TAG Emoji compat library loaded, update accounts list")
|
||||
computeAccountsList()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue