diff --git a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt index f3e0e6cfd..1149dcc18 100644 --- a/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/meetings/viewmodel/ScheduleMeetingViewModel.kt @@ -248,8 +248,9 @@ class ScheduleMeetingViewModel @UiThread constructor() : ViewModel() { val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress( address ) - val model = SelectedAddressModel(address, avatarModel) { + val model = SelectedAddressModel(address, avatarModel) { model -> // onRemoveFromSelection + removeModelFromSelection(model) } list.add(model) Log.i("$TAG Loaded participant [${address.asStringUriOnly()}]") @@ -331,11 +332,20 @@ class ScheduleMeetingViewModel @UiThread constructor() : ViewModel() { if (address == null) { Log.e("$TAG Failed to parse [$participant] as address!") } else { + val found = list.find { it.address.weakEqual(address) } + if (found != null) { + Log.i( + "$TAG Participant [${found.address.asStringUriOnly()}] already in list, skipping" + ) + continue + } + val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress( address ) - val model = SelectedAddressModel(address, avatarModel) { + val model = SelectedAddressModel(address, avatarModel) { model -> // onRemoveFromSelection + removeModelFromSelection(model) } list.add(model) Log.i("$TAG Added participant [${address.asStringUriOnly()}]") @@ -353,6 +363,12 @@ class ScheduleMeetingViewModel @UiThread constructor() : ViewModel() { @UiThread fun schedule() { + if (subject.value.orEmpty().isEmpty() || participants.value.orEmpty().isEmpty()) { + Log.e("$TAG Either no subject was set or no participant was selected, can't schedule meeting.") + // TODO: show red toast + return + } + coreContext.postOnCoreThread { core -> Log.i( "$TAG Scheduling ${if (isBroadcastSelected.value == true) "broadcast" else "meeting"}" @@ -455,6 +471,15 @@ class ScheduleMeetingViewModel @UiThread constructor() : ViewModel() { } } + @UiThread + private fun removeModelFromSelection(model: SelectedAddressModel) { + val newList = arrayListOf() + newList.addAll(participants.value.orEmpty()) + newList.remove(model) + Log.i("$TAG Removed participant [${model.address.asStringUriOnly()}]") + participants.postValue(newList) + } + @AnyThread private fun computeDateLabels() { val start = TimestampUtils.toString( diff --git a/app/src/main/res/layout/meeting_schedule_fragment.xml b/app/src/main/res/layout/meeting_schedule_fragment.xml index f68d3c989..6ca8b38dc 100644 --- a/app/src/main/res/layout/meeting_schedule_fragment.xml +++ b/app/src/main/res/layout/meeting_schedule_fragment.xml @@ -474,7 +474,6 @@ + app:layout_constraintStart_toStartOf="parent" /> + + diff --git a/app/src/main/res/layout/meeting_schedule_participant_list_cell.xml b/app/src/main/res/layout/meeting_schedule_participant_list_cell.xml index 6264f5ce4..81019f0be 100644 --- a/app/src/main/res/layout/meeting_schedule_participant_list_cell.xml +++ b/app/src/main/res/layout/meeting_schedule_participant_list_cell.xml @@ -48,11 +48,27 @@ android:text="@{model.avatarModel.name, default=`John Doe`}" android:textSize="14sp" android:layout_marginStart="10dp" + android:maxLines="1" + android:ellipsize="end" app:layout_constraintStart_toEndOf="@id/avatar" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@id/remove" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> + + \ No newline at end of file