mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-03 15:26:27 +00:00
Added subject field for group chat room creation
This commit is contained in:
parent
ee46722a3d
commit
1c7b97d8db
4 changed files with 157 additions and 13 deletions
|
|
@ -26,7 +26,7 @@ import android.view.ViewGroup
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.view.doOnPreDraw
|
||||
import androidx.navigation.navGraphViewModels
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import org.linphone.R
|
||||
import org.linphone.core.Address
|
||||
|
|
@ -49,9 +49,7 @@ class StartConversationFragment : GenericAddressPickerFragment() {
|
|||
|
||||
private lateinit var binding: StartChatFragmentBinding
|
||||
|
||||
private val viewModel: StartConversationViewModel by navGraphViewModels(
|
||||
R.id.main_nav_graph
|
||||
)
|
||||
private lateinit var viewModel: StartConversationViewModel
|
||||
|
||||
private lateinit var adapter: ContactsAndSuggestionsListAdapter
|
||||
|
||||
|
|
@ -69,6 +67,8 @@ class StartConversationFragment : GenericAddressPickerFragment() {
|
|||
postponeEnterTransition()
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
viewModel = ViewModelProvider(this)[StartConversationViewModel::class.java]
|
||||
binding.viewModel = viewModel
|
||||
|
||||
binding.setBackClickListener {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.linphone.ui.main.chat.viewmodel
|
|||
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import kotlin.collections.ArrayList
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
|
@ -54,6 +55,10 @@ class StartConversationViewModel @UiThread constructor() : AddressSelectionViewM
|
|||
|
||||
val hideGroupChatButton = MutableLiveData<Boolean>()
|
||||
|
||||
val subject = MutableLiveData<String>()
|
||||
|
||||
val groupChatRoomCreateButtonEnabled = MediatorLiveData<Boolean>()
|
||||
|
||||
val operationInProgress = MutableLiveData<Boolean>()
|
||||
|
||||
val chatRoomCreationErrorEvent: MutableLiveData<Event<String>> by lazy {
|
||||
|
|
@ -68,10 +73,10 @@ class StartConversationViewModel @UiThread constructor() : AddressSelectionViewM
|
|||
@WorkerThread
|
||||
override fun onStateChanged(chatRoom: ChatRoom, newState: ChatRoom.State?) {
|
||||
val state = chatRoom.state
|
||||
Log.i("$TAG Chat room state changed: [$state]")
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.i("$TAG Chat room [$id] (${chatRoom.subject}) state changed: [$state]")
|
||||
|
||||
if (state == ChatRoom.State.Created) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.i("$TAG Chat room [$id] successfully created")
|
||||
chatRoom.removeListener(this)
|
||||
operationInProgress.postValue(false)
|
||||
|
|
@ -84,7 +89,6 @@ class StartConversationViewModel @UiThread constructor() : AddressSelectionViewM
|
|||
)
|
||||
)
|
||||
} else if (state == ChatRoom.State.CreationFailed) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.e("$TAG Chat room [$id] creation has failed!")
|
||||
chatRoom.removeListener(this)
|
||||
operationInProgress.postValue(false)
|
||||
|
|
@ -121,6 +125,18 @@ class StartConversationViewModel @UiThread constructor() : AddressSelectionViewM
|
|||
}
|
||||
|
||||
init {
|
||||
groupChatRoomCreateButtonEnabled.postValue(false)
|
||||
groupChatRoomCreateButtonEnabled.addSource(selection) {
|
||||
groupChatRoomCreateButtonEnabled.postValue(
|
||||
subject.value.orEmpty().isNotEmpty() && selection.value.orEmpty().isNotEmpty()
|
||||
)
|
||||
}
|
||||
groupChatRoomCreateButtonEnabled.addSource(subject) {
|
||||
groupChatRoomCreateButtonEnabled.postValue(
|
||||
subject.value.orEmpty().isNotEmpty() && selection.value.orEmpty().isNotEmpty()
|
||||
)
|
||||
}
|
||||
|
||||
updateGroupChatButtonVisibility()
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
|
|
@ -150,6 +166,79 @@ class StartConversationViewModel @UiThread constructor() : AddressSelectionViewM
|
|||
searchFilter.value = ""
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun createGroupChatRoom() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
val account = core.defaultAccount
|
||||
if (account == null) {
|
||||
Log.e(
|
||||
"$TAG No default account found, can't create group conversation!"
|
||||
)
|
||||
return@postOnCoreThread
|
||||
}
|
||||
|
||||
operationInProgress.postValue(true)
|
||||
|
||||
val groupChatRoomSubject = subject.value.orEmpty()
|
||||
val params: ChatRoomParams = coreContext.core.createDefaultChatRoomParams()
|
||||
params.isGroupEnabled = true
|
||||
params.subject = groupChatRoomSubject
|
||||
params.backend = ChatRoom.Backend.FlexisipChat
|
||||
params.isEncryptionEnabled = true
|
||||
|
||||
val participants = arrayListOf<Address>()
|
||||
for (participant in selection.value.orEmpty()) {
|
||||
participants.add(participant.address)
|
||||
}
|
||||
val localAddress = account.params.identityAddress
|
||||
|
||||
val participantsArray = arrayOf<Address>()
|
||||
val chatRoom = core.createChatRoom(
|
||||
params,
|
||||
localAddress,
|
||||
participants.toArray(participantsArray)
|
||||
)
|
||||
if (chatRoom != null) {
|
||||
if (params.backend == ChatRoom.Backend.FlexisipChat) {
|
||||
if (chatRoom.state == ChatRoom.State.Created) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.i("$TAG Group chat room [$id] ($groupChatRoomSubject) has been created")
|
||||
operationInProgress.postValue(false)
|
||||
chatRoomCreatedEvent.postValue(
|
||||
Event(
|
||||
Pair(
|
||||
chatRoom.localAddress.asStringUriOnly(),
|
||||
chatRoom.peerAddress.asStringUriOnly()
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Log.i(
|
||||
"$TAG Chat room [$groupChatRoomSubject] isn't in Created state yet, wait for it"
|
||||
)
|
||||
chatRoom.addListener(chatRoomListener)
|
||||
}
|
||||
} else {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.i("$TAG Chat room successfully created [$id] ($groupChatRoomSubject)")
|
||||
operationInProgress.postValue(false)
|
||||
chatRoomCreatedEvent.postValue(
|
||||
Event(
|
||||
Pair(
|
||||
chatRoom.localAddress.asStringUriOnly(),
|
||||
chatRoom.peerAddress.asStringUriOnly()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Log.e("$TAG Failed to create group chat room [$groupChatRoomSubject]!")
|
||||
operationInProgress.postValue(false)
|
||||
chatRoomCreationErrorEvent.postValue(Event("Error!")) // TODO FIXME: use translated string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun createOneToOneChatRoomWith(remote: Address) {
|
||||
val core = coreContext.core
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="@color/white">
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/multiple_selection_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:constraint_referenced_ids="group_name_title, group_name, required_label, create_group, multiple_selection, multiple_selection_count"
|
||||
android:visibility="@{viewModel.multipleSelectionMode ? View.VISIBLE : View.GONE, default=gone}" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -49,13 +56,14 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/create_group"
|
||||
android:onClick="@{() -> viewModel.createGroupChatRoom()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:padding="15dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/check"
|
||||
android:visibility="@{viewModel.multipleSelectionMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:tint="@color/orange_main_500"
|
||||
android:enabled="@{viewModel.groupChatRoomCreateButtonEnabled}"
|
||||
app:tint="@color/primary_color_selector"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
|
|
@ -69,25 +77,70 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/header_style"
|
||||
android:id="@+id/group_name_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/new_conversation_group_name_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/background" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_300"
|
||||
android:id="@+id/required_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/required"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/gray_main2_600"
|
||||
app:layout_constraintEnd_toEndOf="@id/group_name"
|
||||
app:layout_constraintTop_toTopOf="@id/background" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/group_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:text="@={viewModel.subject, default=`Dummy subject`}"
|
||||
android:hint="@string/new_conversation_group_name_title"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/gray_main2_600"
|
||||
android:maxLines="1"
|
||||
android:background="@drawable/edit_text_background"
|
||||
android:inputType="text|textCapWords"
|
||||
app:layout_constraintWidth_max="@dimen/text_input_max_width"
|
||||
app:layout_constraintTop_toBottomOf="@id/group_name_title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_300"
|
||||
android:id="@+id/multiple_selection_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@{viewModel.selectionCount, default=`0 selected`}"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/black"
|
||||
android:visibility="@{viewModel.multipleSelectionMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/background" />
|
||||
app:layout_constraintTop_toBottomOf="@id/group_name" />
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/multiple_selection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="@{viewModel.multipleSelectionMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/multiple_selection_count">
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
<string name="or">or</string>
|
||||
<string name="next">next</string>
|
||||
<string name="start">Start</string>
|
||||
<string name="required">Required</string>
|
||||
|
||||
<plurals name="selection_count_label">
|
||||
<item quantity="one">%s selected</item>
|
||||
|
|
@ -342,6 +343,7 @@
|
|||
<string name="new_conversation_search_bar_filter_hint">Search contact</string>
|
||||
<string name="new_conversation_create_group">Create a group conversation</string>
|
||||
<string name="new_conversation_no_contact">No contact for the moment…</string>
|
||||
<string name="new_conversation_group_name_title">Name of the group</string>
|
||||
<string name="conversation_text_field_hint">Say something…</string>
|
||||
<plurals name="conversation_composing_label">
|
||||
<item quantity="one">%s is composing…</item>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue