mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Adding participants to existing group
This commit is contained in:
parent
d9d7508292
commit
a27cf28544
6 changed files with 90 additions and 1 deletions
|
|
@ -123,6 +123,13 @@ class ConversationInfoFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
sharedViewModel.listOfSelectedSipUrisEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { list ->
|
||||
Log.i("$TAG Found [${list.size}] new participants to add to the group, let's do it")
|
||||
viewModel.addParticipants(list)
|
||||
}
|
||||
}
|
||||
|
||||
binding.setBackClickListener {
|
||||
goBack()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import androidx.annotation.WorkerThread
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.ChatRoomListenerStub
|
||||
import org.linphone.core.EventLog
|
||||
|
|
@ -256,6 +257,37 @@ class ConversationInfoViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun addParticipants(toAdd: ArrayList<String>) {
|
||||
coreContext.postOnCoreThread {
|
||||
if (::chatRoom.isInitialized) {
|
||||
if (!LinphoneUtils.isChatRoomAGroup(chatRoom)) {
|
||||
Log.e("$TAG Can't add participants to a chat room that's not a group!")
|
||||
return@postOnCoreThread
|
||||
}
|
||||
|
||||
val list = arrayListOf<Address>()
|
||||
for (participant in toAdd) {
|
||||
val address = Factory.instance().createAddress(participant)
|
||||
if (address == null) {
|
||||
Log.e("$TAG Failed to parse [$participant] as address!")
|
||||
} else {
|
||||
list.add(address)
|
||||
}
|
||||
}
|
||||
|
||||
val participantsToAdd = arrayOfNulls<Address>(list.size)
|
||||
list.toArray(participantsToAdd)
|
||||
Log.i("$TAG Adding [${participantsToAdd.size}] new participants to chat room")
|
||||
val ok = chatRoom.addParticipants(participantsToAdd)
|
||||
if (!ok) {
|
||||
Log.w("$TAG Failed to add some/all participants to the group!")
|
||||
// TODO: show toast
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun configureChatRoom() {
|
||||
isMuted.postValue(chatRoom.muted)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.linphone.core.Friend
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.GenericAddParticipantsFragmentBinding
|
||||
import org.linphone.ui.main.viewmodel.AddParticipantsViewModel
|
||||
import org.linphone.utils.Event
|
||||
|
||||
@UiThread
|
||||
class AddParticipantsFragment : GenericAddressPickerFragment() {
|
||||
|
|
@ -93,5 +94,12 @@ class AddParticipantsFragment : GenericAddressPickerFragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.selectedSipUrisEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { list ->
|
||||
sharedViewModel.listOfSelectedSipUrisEvent.value = Event(list)
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,35 @@
|
|||
package org.linphone.ui.main.viewmodel
|
||||
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class AddParticipantsViewModel @UiThread constructor() : AddressSelectionViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Add Participants ViewModel]"
|
||||
}
|
||||
|
||||
val selectedSipUrisEvent = MutableLiveData<Event<ArrayList<String>>>()
|
||||
|
||||
init {
|
||||
Log.i("$TAG Forcing multiple selection mode")
|
||||
switchToMultipleSelectionMode()
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun addParticipants() {
|
||||
val selected = selection.value.orEmpty()
|
||||
Log.i("$TAG [${selected.size}] participants selected")
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
val list = arrayListOf<String>()
|
||||
for (model in selected) {
|
||||
list.add(model.address.asStringUriOnly())
|
||||
}
|
||||
|
||||
selectedSipUrisEvent.postValue(Event(list))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,4 +122,10 @@ class SharedMainViewModel @UiThread constructor() : ViewModel() {
|
|||
val forceRefreshMeetingsListEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
/* Other */
|
||||
|
||||
val listOfSelectedSipUrisEvent: MutableLiveData<Event<ArrayList<String>>> by lazy {
|
||||
MutableLiveData<Event<ArrayList<String>>>()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,10 +43,24 @@
|
|||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:text="@string/conversation_add_participants_title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/add_participants"
|
||||
app:layout_constraintStart_toEndOf="@id/back"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/add_participants"
|
||||
android:onClick="@{() -> viewModel.addParticipants()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:padding="15dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/check"
|
||||
android:enabled="@{viewModel.selection.size() > 0}"
|
||||
app:tint="@color/primary_color_selector"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
|
||||
<View
|
||||
android:id="@+id/background"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue