Don't use arguments to pass list of Addresses between fragments, might crash in a writeToParcel
This commit is contained in:
parent
712852cdce
commit
2131458ac1
6 changed files with 19 additions and 17 deletions
|
@ -348,11 +348,11 @@ internal fun DetailChatRoomFragment.navigateToEphemeralInfo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChatRoomCreationFragment.navigateToGroupInfo(args: Bundle?) {
|
internal fun ChatRoomCreationFragment.navigateToGroupInfo() {
|
||||||
if (findNavController().currentDestination?.id == R.id.chatRoomCreationFragment) {
|
if (findNavController().currentDestination?.id == R.id.chatRoomCreationFragment) {
|
||||||
findNavController().navigate(
|
findNavController().navigate(
|
||||||
R.id.action_chatRoomCreationFragment_to_groupInfoFragment,
|
R.id.action_chatRoomCreationFragment_to_groupInfoFragment,
|
||||||
args,
|
null,
|
||||||
getRightToLeftAnimationNavOptions()
|
getRightToLeftAnimationNavOptions()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.linphone.activities.main.fragments.SecureFragment
|
||||||
import org.linphone.activities.main.navigateToChatRoom
|
import org.linphone.activities.main.navigateToChatRoom
|
||||||
import org.linphone.activities.main.navigateToGroupInfo
|
import org.linphone.activities.main.navigateToGroupInfo
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||||
import org.linphone.core.Address
|
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.databinding.ChatRoomCreationFragmentBinding
|
import org.linphone.databinding.ChatRoomCreationFragmentBinding
|
||||||
import org.linphone.utils.PermissionHelper
|
import org.linphone.utils.PermissionHelper
|
||||||
|
@ -128,14 +127,13 @@ class ChatRoomCreationFragment : SecureFragment<ChatRoomCreationFragmentBinding>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
addParticipantsFromBundle()
|
addParticipantsFromSharedViewModel()
|
||||||
|
|
||||||
// Next button is only used to go to group chat info fragment
|
// Next button is only used to go to group chat info fragment
|
||||||
binding.setNextClickListener {
|
binding.setNextClickListener {
|
||||||
sharedViewModel.createEncryptedChatRoom = viewModel.isEncrypted.value == true
|
sharedViewModel.createEncryptedChatRoom = viewModel.isEncrypted.value == true
|
||||||
val args = Bundle()
|
sharedViewModel.chatRoomParticipants.value = viewModel.selectedAddresses.value
|
||||||
args.putSerializable("participants", viewModel.selectedAddresses.value)
|
navigateToGroupInfo()
|
||||||
navigateToGroupInfo(args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.onErrorEvent.observe(viewLifecycleOwner, {
|
viewModel.onErrorEvent.observe(viewLifecycleOwner, {
|
||||||
|
@ -150,9 +148,8 @@ class ChatRoomCreationFragment : SecureFragment<ChatRoomCreationFragmentBinding>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
private fun addParticipantsFromSharedViewModel() {
|
||||||
private fun addParticipantsFromBundle() {
|
val participants = sharedViewModel.chatRoomParticipants.value
|
||||||
val participants = arguments?.getSerializable("participants") as? ArrayList<Address>
|
|
||||||
if (participants != null && participants.size > 0) {
|
if (participants != null && participants.size > 0) {
|
||||||
viewModel.selectedAddresses.value = participants
|
viewModel.selectedAddresses.value = participants
|
||||||
}
|
}
|
||||||
|
|
|
@ -398,6 +398,7 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
|
|
||||||
private fun showGroupInfo(chatRoom: ChatRoom) {
|
private fun showGroupInfo(chatRoom: ChatRoom) {
|
||||||
sharedViewModel.selectedGroupChatRoom.value = chatRoom
|
sharedViewModel.selectedGroupChatRoom.value = chatRoom
|
||||||
|
sharedViewModel.chatRoomParticipants.value = arrayListOf()
|
||||||
navigateToGroupInfo()
|
navigateToGroupInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
addParticipantsFromBundle()
|
addParticipantsFromSharedViewModel()
|
||||||
|
|
||||||
binding.setBackClickListener {
|
binding.setBackClickListener {
|
||||||
findNavController().popBackStack()
|
findNavController().popBackStack()
|
||||||
|
@ -128,13 +128,14 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
|
||||||
binding.setParticipantsClickListener {
|
binding.setParticipantsClickListener {
|
||||||
sharedViewModel.createEncryptedChatRoom = viewModel.isEncrypted.value == true
|
sharedViewModel.createEncryptedChatRoom = viewModel.isEncrypted.value == true
|
||||||
|
|
||||||
val args = Bundle()
|
|
||||||
args.putBoolean("createGroup", true)
|
|
||||||
val list = arrayListOf<Address>()
|
val list = arrayListOf<Address>()
|
||||||
for (participant in viewModel.participants.value.orEmpty()) {
|
for (participant in viewModel.participants.value.orEmpty()) {
|
||||||
list.add(participant.address)
|
list.add(participant.address)
|
||||||
}
|
}
|
||||||
args.putSerializable("participants", list)
|
sharedViewModel.chatRoomParticipants.value = list
|
||||||
|
|
||||||
|
val args = Bundle()
|
||||||
|
args.putBoolean("createGroup", true)
|
||||||
navigateToChatRoomCreation(args)
|
navigateToChatRoomCreation(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,9 +162,8 @@ class GroupInfoFragment : SecureFragment<ChatRoomGroupInfoFragmentBinding>() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
private fun addParticipantsFromSharedViewModel() {
|
||||||
private fun addParticipantsFromBundle() {
|
val participants = sharedViewModel.chatRoomParticipants.value
|
||||||
val participants = arguments?.getSerializable("participants") as? ArrayList<Address>
|
|
||||||
if (participants != null && participants.size > 0) {
|
if (participants != null && participants.size > 0) {
|
||||||
val list = arrayListOf<GroupChatRoomMember>()
|
val list = arrayListOf<GroupChatRoomMember>()
|
||||||
|
|
||||||
|
|
|
@ -157,11 +157,13 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.setNewOneToOneChatRoomClickListener {
|
binding.setNewOneToOneChatRoomClickListener {
|
||||||
|
sharedViewModel.chatRoomParticipants.value = arrayListOf()
|
||||||
navigateToChatRoomCreation(false)
|
navigateToChatRoomCreation(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.setNewGroupChatRoomClickListener {
|
binding.setNewGroupChatRoomClickListener {
|
||||||
sharedViewModel.selectedGroupChatRoom.value = null
|
sharedViewModel.selectedGroupChatRoom.value = null
|
||||||
|
sharedViewModel.chatRoomParticipants.value = arrayListOf()
|
||||||
navigateToChatRoomCreation(true)
|
navigateToChatRoomCreation(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ class SharedMainViewModel : ViewModel() {
|
||||||
|
|
||||||
var createEncryptedChatRoom: Boolean = false
|
var createEncryptedChatRoom: Boolean = false
|
||||||
|
|
||||||
|
val chatRoomParticipants = MutableLiveData<ArrayList<Address>>()
|
||||||
|
|
||||||
/* Contacts */
|
/* Contacts */
|
||||||
|
|
||||||
val selectedContact = MutableLiveData<Contact>()
|
val selectedContact = MutableLiveData<Contact>()
|
||||||
|
|
Loading…
Reference in a new issue