Add already selected participants to list when adding new participants

This commit is contained in:
Sylvain Berfini 2024-04-26 10:21:13 +02:00
parent e9f0bed2d2
commit f532214e1a
8 changed files with 89 additions and 6 deletions

View file

@ -218,8 +218,15 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
binding.setAddParticipantsClickListener {
if (findNavController().currentDestination?.id == R.id.conversationInfoFragment) {
Log.i("$TAG Going into participant picker fragment")
val selection = arrayListOf<String>()
for (participant in viewModel.participants.value.orEmpty()) {
selection.add(participant.address.asStringUriOnly())
}
Log.i("$TAG [${selection.size}] participants are already selected, keeping them")
val action =
ConversationInfoFragmentDirections.actionConversationInfoFragmentToAddParticipantsFragment()
ConversationInfoFragmentDirections.actionConversationInfoFragmentToAddParticipantsFragment(
selection.toTypedArray()
)
findNavController().navigate(action)
}
}

View file

@ -27,6 +27,7 @@ import androidx.annotation.UiThread
import androidx.core.view.doOnPreDraw
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import org.linphone.core.Address
import org.linphone.core.Friend
import org.linphone.core.tools.Log
@ -44,6 +45,8 @@ class AddParticipantsFragment : GenericAddressPickerFragment() {
override lateinit var viewModel: AddParticipantsViewModel
private val args: AddParticipantsFragmentArgs by navArgs()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -77,6 +80,11 @@ class AddParticipantsFragment : GenericAddressPickerFragment() {
setupRecyclerView(binding.contactsList)
val participants = args.selectedParticipants
if (!participants.isNullOrEmpty()) {
viewModel.addSelectedParticipants(participants)
}
viewModel.contactsAndSuggestionsList.observe(
viewLifecycleOwner
) {

View file

@ -160,8 +160,15 @@ class EditMeetingFragment : SlidingPaneChildFragment() {
binding.setPickParticipantsClickListener {
if (findNavController().currentDestination?.id == R.id.editMeetingFragment) {
Log.i("$TAG Going into participant picker fragment")
val selection = arrayListOf<String>()
for (participant in viewModel.participants.value.orEmpty()) {
selection.add(participant.address.asStringUriOnly())
}
Log.i("$TAG [${selection.size}] participants are already selected, keeping them")
val action =
EditMeetingFragmentDirections.actionEditMeetingFragmentToAddParticipantsFragment()
EditMeetingFragmentDirections.actionEditMeetingFragmentToAddParticipantsFragment(
selection.toTypedArray()
)
findNavController().navigate(action)
}
}

View file

@ -161,8 +161,15 @@ class ScheduleMeetingFragment : GenericFragment() {
binding.setPickParticipantsClickListener {
if (findNavController().currentDestination?.id == R.id.scheduleMeetingFragment) {
Log.i("$TAG Going into participant picker fragment")
val selection = arrayListOf<String>()
for (participant in viewModel.participants.value.orEmpty()) {
selection.add(participant.address.asStringUriOnly())
}
Log.i("$TAG [${selection.size}] participants are already selected, keeping them")
val action =
ScheduleMeetingFragmentDirections.actionScheduleMeetingFragmentToAddParticipantsFragment()
ScheduleMeetingFragmentDirections.actionScheduleMeetingFragmentToAddParticipantsFragment(
selection.toTypedArray()
)
findNavController().navigate(action)
}
}

View file

@ -22,7 +22,10 @@ package org.linphone.ui.main.viewmodel
import androidx.annotation.UiThread
import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.ui.main.model.SelectedAddressModel
import org.linphone.utils.AppUtils
import org.linphone.utils.Event
class AddParticipantsViewModel @UiThread constructor() : AddressSelectionViewModel() {
@ -37,6 +40,39 @@ class AddParticipantsViewModel @UiThread constructor() : AddressSelectionViewMod
switchToMultipleSelectionMode()
}
@UiThread
fun addSelectedParticipants(participants: Array<String>) {
coreContext.postOnCoreThread { core ->
Log.i("$TAG Adding [${participants.size}] pre-selected participants")
val list = arrayListOf<SelectedAddressModel>()
for (uri in participants) {
val address = core.interpretUrl(uri, false)
if (address == null) {
Log.e("$TAG Failed to parse participant URI [$uri] as address!")
continue
}
val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress(
address
)
val model = SelectedAddressModel(address, avatarModel) {
removeAddressModelFromSelection(it)
}
list.add(model)
}
selectionCount.postValue(
AppUtils.getStringWithPlural(
R.plurals.selection_count_label,
list.size,
list.size.toString()
)
)
selection.postValue(list)
}
}
@UiThread
fun addParticipants() {
val selected = selection.value.orEmpty()

View file

@ -99,7 +99,13 @@
android:id="@+id/addParticipantsFragment"
android:name="org.linphone.ui.main.fragment.AddParticipantsFragment"
android:label="AddParticipantsFragment"
tools:layout="@layout/generic_add_participants_fragment" />
tools:layout="@layout/generic_add_participants_fragment">
<argument
android:name="selectedParticipants"
app:argType="string[]"
app:nullable="true"
android:defaultValue="@null" />
</fragment>
<fragment
android:id="@+id/conversationEphemeralLifetimeFragment"

View file

@ -349,7 +349,13 @@
android:id="@+id/addParticipantsFragment"
android:name="org.linphone.ui.main.fragment.AddParticipantsFragment"
android:label="AddParticipantsFragment"
tools:layout="@layout/generic_add_participants_fragment"/>
tools:layout="@layout/generic_add_participants_fragment">
<argument
android:name="selectedParticipants"
app:argType="string[]"
app:nullable="true"
android:defaultValue="@null" />
</fragment>
<action android:id="@+id/action_global_conversationsListFragment"
app:destination="@id/conversationsListFragment"

View file

@ -60,6 +60,12 @@
android:id="@+id/addParticipantsFragment"
android:name="org.linphone.ui.main.fragment.AddParticipantsFragment"
android:label="AddParticipantsFragment"
tools:layout="@layout/generic_add_participants_fragment"/>
tools:layout="@layout/generic_add_participants_fragment">
<argument
android:name="selectedParticipants"
app:argType="string[]"
app:nullable="true"
android:defaultValue="@null" />
</fragment>
</navigation>