Fixed crash when animations are disabled + crash when creating 1-1 encrypted chat room

This commit is contained in:
Sylvain Berfini 2021-01-21 15:52:33 +01:00
parent 1d0cbbcc69
commit 2dd034cfbd
2 changed files with 15 additions and 8 deletions

View file

@ -91,7 +91,9 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactViewModelI
get() = chatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt())
val peerSipUri: String
get() = if (oneToOneChatRoom && !basicChatRoom) chatRoom.participants.first().address.asStringUriOnly()
get() = if (oneToOneChatRoom && !basicChatRoom)
chatRoom.participants.firstOrNull()?.address?.asStringUriOnly()
?: chatRoom.peerAddress.asStringUriOnly()
else chatRoom.peerAddress.asStringUriOnly()
val oneParticipantOneDevice: Boolean

View file

@ -26,6 +26,7 @@ import androidx.core.view.doOnPreDraw
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import org.linphone.LinphoneApplication
import org.linphone.R
import org.linphone.activities.main.viewmodels.DialogViewModel
import org.linphone.activities.main.viewmodels.ListTopBarViewModel
@ -91,13 +92,17 @@ abstract class MasterFragment<T : ViewDataBinding, U : SelectionListAdapter<*, *
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// Do not use postponeEnterTransition when fragment is recreated from the back stack,
// otherwise the previous fragment will be visible until the animation starts
val resume = findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Boolean>("resume")?.value ?: false
if (!resume) {
findNavController().currentBackStackEntry?.savedStateHandle?.set("resume", true)
// To ensure animation will be smooth,
// wait until the adapter is loaded to display the fragment
postponeEnterTransition()
view.doOnPreDraw { startPostponedEnterTransition() }
if (LinphoneApplication.corePreferences.enableAnimations) {
val resume =
findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Boolean>("resume")?.value
?: false
if (!resume) {
findNavController().currentBackStackEntry?.savedStateHandle?.set("resume", true)
// To ensure animation will be smooth,
// wait until the adapter is loaded to display the fragment
postponeEnterTransition()
view.doOnPreDraw { startPostponedEnterTransition() }
}
}
super.onViewCreated(view, savedInstanceState)