Preventing crash due to keyboard visibility listener + improved suggestions list

This commit is contained in:
Sylvain Berfini 2023-08-21 17:30:00 +02:00
parent bfe56579aa
commit ce2a9b0bde
2 changed files with 41 additions and 8 deletions

View file

@ -99,13 +99,32 @@ class SuggestionsListViewModel : ViewModel() {
val list = arrayListOf<ContactAvatarModel>()
for (result in results) {
// We don't want Friends here as they would also be in contacts list
if (result.friend == null) {
val fakeFriend = createFriendFromSearchResult(result)
val model = ContactAvatarModel(fakeFriend)
model.noAlphabet.postValue(true)
val address = result.address
Log.i("$TAG ${address?.asStringUriOnly()}")
if (address != null) {
val friend = coreContext.core.findFriend(address)
Log.i("$TAG ${friend?.name}")
// We don't want Friends here as they would also be in contacts list
if (friend == null) {
// If user-input generated result (always last) already exists, don't show it again
if (result.sourceFlags == MagicSearch.Source.Request.toInt()) {
val found = list.find {
it.friend.address?.weakEqual(address) == true
}
if (found != null) {
Log.i(
"$TAG Result generated from user input is a duplicate of an existing solution, preventing double"
)
continue
}
}
list.add(model)
val fakeFriend = createFriendFromSearchResult(result)
val model = ContactAvatarModel(fakeFriend)
model.noAlphabet.postValue(true)
list.add(model)
}
}
}

View file

@ -46,6 +46,7 @@ import org.linphone.BR
import org.linphone.R
import org.linphone.contacts.ContactData
import org.linphone.core.ConsolidatedPresence
import org.linphone.core.tools.Log
import org.linphone.ui.main.MainActivity
import org.linphone.ui.main.contacts.model.ContactAvatarModel
@ -103,7 +104,13 @@ fun View.setKeyboardInsetListener(lambda: (visible: Boolean) -> Unit) {
WindowInsetsCompat.Type.ime()
) == true
lambda(isKeyboardVisible)
try {
lambda(isKeyboardVisible)
} catch (ise: IllegalStateException) {
Log.e(
"[Databinding Utils] Failed to called lambda after keyboard visibility changed: $ise"
)
}
// See https://issuetracker.google.com/issues/281942480
ViewCompat.setOnApplyWindowInsetsListener(
@ -113,7 +120,14 @@ fun View.setKeyboardInsetListener(lambda: (visible: Boolean) -> Unit) {
?.isVisible(WindowInsetsCompat.Type.ime()) == true
if (keyboardVisibilityChanged != isKeyboardVisible) {
isKeyboardVisible = keyboardVisibilityChanged
lambda(isKeyboardVisible)
try {
lambda(isKeyboardVisible)
} catch (ise: IllegalStateException) {
Log.e(
"[Databinding Utils] Failed to called lambda after keyboard visibility changed: $ise"
)
}
}
ViewCompat.onApplyWindowInsets(view, insets)
}