Fixed crash if sharedViewModel has not been initialized when saving fragment instance state

This commit is contained in:
Sylvain Berfini 2021-11-29 11:43:40 +01:00
parent 60cc5a31c4
commit 72ae8f2e67

View file

@ -109,11 +109,15 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
val chatRoom = sharedViewModel.selectedChatRoom.value if (::sharedViewModel.isInitialized) {
if (chatRoom != null) { val chatRoom = sharedViewModel.selectedChatRoom.value
outState.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly()) if (chatRoom != null) {
outState.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly()) outState.putString("LocalSipUri", chatRoom.localAddress.asStringUriOnly())
Log.i("[Chat Room] Saving current chat room local & remote addresses in save instance state") outState.putString("RemoteSipUri", chatRoom.peerAddress.asStringUriOnly())
Log.i("[Chat Room] Saving current chat room local & remote addresses in save instance state")
}
} else {
Log.w("[Chat Room] Can't save instance state, sharedViewModel hasn't been initialized yet")
} }
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
} }