From 2857378c875b8bb92442c3b3302a9f8bad7197d3 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 6 Nov 2023 09:35:11 +0100 Subject: [PATCH] Added conference info in chat bubble layout --- .../ui/main/chat/model/ChatMessageModel.kt | 78 ++++++- ...e_squircle_gray_100_top_r10_background.xml | 5 + .../shape_squircle_white_r10_background.xml | 5 + .../main/res/layout/chat_bubble_content.xml | 13 +- .../chat_bubble_meeting_invite_content.xml | 201 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/shape_squircle_gray_100_top_r10_background.xml create mode 100644 app/src/main/res/drawable/shape_squircle_white_r10_background.xml create mode 100644 app/src/main/res/layout/chat_bubble_meeting_invite_content.xml diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/ChatMessageModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/ChatMessageModel.kt index 7619f43e2..f451d6f00 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/ChatMessageModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/ChatMessageModel.kt @@ -27,13 +27,16 @@ import androidx.annotation.WorkerThread import androidx.lifecycle.MutableLiveData import java.util.regex.Pattern import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.R import org.linphone.core.Address import org.linphone.core.ChatMessage import org.linphone.core.ChatMessageListenerStub import org.linphone.core.ChatMessageReaction import org.linphone.core.Content +import org.linphone.core.Factory import org.linphone.core.tools.Log import org.linphone.ui.main.contacts.model.ContactAvatarModel +import org.linphone.utils.AppUtils import org.linphone.utils.Event import org.linphone.utils.LinphoneUtils import org.linphone.utils.PatternClickableSpan @@ -78,6 +81,26 @@ class ChatMessageModel @WorkerThread constructor( val firstImage = MutableLiveData() + // Below are for conferences info + val meetingFound = MutableLiveData() + + val meetingDay = MutableLiveData() + + val meetingDayNumber = MutableLiveData() + + val meetingSubject = MutableLiveData() + + val meetingDate = MutableLiveData() + + val meetingTime = MutableLiveData() + + val meetingDescription = MutableLiveData() + + val meetingParticipants = MutableLiveData() + + private lateinit var meetingConferenceUri: Address + // End of conference info related fields + val dismissLongPressMenuEvent: MutableLiveData> by lazy { MutableLiveData>() } @@ -114,7 +137,10 @@ class ChatMessageModel @WorkerThread constructor( val contents = chatMessage.contents for (content in contents) { - if (content.isText) { + if (content.isIcalendar) { + parseConferenceInvite(content) + displayableContentFound = true + } else if (content.isText) { computeTextContent(content) displayableContentFound = true } else { @@ -177,6 +203,16 @@ class ChatMessageModel @WorkerThread constructor( } } + @UiThread + fun joinConference() { + coreContext.postOnCoreThread { + if (::meetingConferenceUri.isInitialized) { + Log.i("$TAG Calling conference URI [${meetingConferenceUri.asStringUriOnly()}]") + coreContext.startCall(meetingConferenceUri) + } + } + } + @WorkerThread private fun updateReactionsList() { var reactionsList = "" @@ -279,4 +315,44 @@ class ChatMessageModel @WorkerThread constructor( .build(spannableBuilder) ) } + + @WorkerThread + private fun parseConferenceInvite(content: Content) { + val conferenceInfo = Factory.instance().createConferenceInfoFromIcalendarContent(content) + val conferenceAddress = conferenceInfo?.uri + val conferenceUri = conferenceAddress?.asStringUriOnly() + if (conferenceInfo != null && conferenceAddress != null) { + Log.i( + "$TAG Found conference info with URI [$conferenceUri] and subject [${conferenceInfo.subject}]" + ) + meetingConferenceUri = conferenceAddress + + meetingSubject.postValue(conferenceInfo.subject) + meetingDescription.postValue(conferenceInfo.description) + + val timestamp = conferenceInfo.dateTime + val duration = conferenceInfo.duration + val date = TimestampUtils.toString( + timestamp, + onlyDate = true, + shortDate = false, + hideYear = false + ) + val startTime = TimestampUtils.timeToString(timestamp) + val end = timestamp + (duration * 60) + val endTime = TimestampUtils.timeToString(end) + meetingDate.postValue(date) + meetingTime.postValue("$startTime - $endTime") + + meetingDay.postValue(TimestampUtils.dayOfWeek(timestamp)) + meetingDayNumber.postValue(TimestampUtils.dayOfMonth(timestamp)) + + // TODO: fixme + meetingParticipants.postValue( + AppUtils.getFormattedString(R.string.conference_participants_list_title, "24") + ) + + meetingFound.postValue(true) + } + } } diff --git a/app/src/main/res/drawable/shape_squircle_gray_100_top_r10_background.xml b/app/src/main/res/drawable/shape_squircle_gray_100_top_r10_background.xml new file mode 100644 index 000000000..9a31c9bf0 --- /dev/null +++ b/app/src/main/res/drawable/shape_squircle_gray_100_top_r10_background.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_squircle_white_r10_background.xml b/app/src/main/res/drawable/shape_squircle_white_r10_background.xml new file mode 100644 index 000000000..139f19f5d --- /dev/null +++ b/app/src/main/res/drawable/shape_squircle_white_r10_background.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/chat_bubble_content.xml b/app/src/main/res/layout/chat_bubble_content.xml index ca4e4ce02..5edef789f 100644 --- a/app/src/main/res/layout/chat_bubble_content.xml +++ b/app/src/main/res/layout/chat_bubble_content.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:bind="http://schemas.android.com/tools"> @@ -56,6 +57,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/single_image"/> + + \ No newline at end of file diff --git a/app/src/main/res/layout/chat_bubble_meeting_invite_content.xml b/app/src/main/res/layout/chat_bubble_meeting_invite_content.xml new file mode 100644 index 000000000..b0efe05a2 --- /dev/null +++ b/app/src/main/res/layout/chat_bubble_meeting_invite_content.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 793d2ead7..72c34d034 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -399,6 +399,7 @@ Organizer Delete meeting Meeting has been deleted + Description Join