mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-18 11:58:09 +00:00
Added user-input as suggestion when starting a new call
This commit is contained in:
parent
78edc79fc2
commit
bde1258c87
6 changed files with 88 additions and 18 deletions
|
|
@ -0,0 +1,66 @@
|
|||
package org.linphone.ui.main.calls.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.linphone.R
|
||||
import org.linphone.databinding.ContactListCellBinding
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class SuggestionsListAdapter(
|
||||
private val viewLifecycleOwner: LifecycleOwner
|
||||
) : ListAdapter<ContactAvatarModel, RecyclerView.ViewHolder>(SuggestionDiffCallback()) {
|
||||
val contactClickedEvent: MutableLiveData<Event<ContactAvatarModel>> by lazy {
|
||||
MutableLiveData<Event<ContactAvatarModel>>()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val binding: ContactListCellBinding = DataBindingUtil.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
R.layout.contact_list_cell,
|
||||
parent,
|
||||
false
|
||||
)
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
(holder as ViewHolder).bind(getItem(position))
|
||||
}
|
||||
|
||||
inner class ViewHolder(
|
||||
val binding: ContactListCellBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
@UiThread
|
||||
fun bind(contactModel: ContactAvatarModel) {
|
||||
with(binding) {
|
||||
model = contactModel
|
||||
|
||||
lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.setOnClickListener {
|
||||
contactClickedEvent.value = Event(contactModel)
|
||||
}
|
||||
|
||||
executePendingBindings()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SuggestionDiffCallback : DiffUtil.ItemCallback<ContactAvatarModel>() {
|
||||
override fun areItemsTheSame(oldItem: ContactAvatarModel, newItem: ContactAvatarModel): Boolean {
|
||||
return oldItem.friend == newItem.friend
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: ContactAvatarModel, newItem: ContactAvatarModel): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.R
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.databinding.CallStartFragmentBinding
|
||||
import org.linphone.ui.main.calls.adapter.SuggestionsListAdapter
|
||||
import org.linphone.ui.main.calls.viewmodel.StartCallViewModel
|
||||
import org.linphone.ui.main.calls.viewmodel.SuggestionsListViewModel
|
||||
import org.linphone.ui.main.contacts.adapter.ContactsListAdapter
|
||||
|
|
@ -59,7 +60,7 @@ class StartCallFragment : GenericFragment() {
|
|||
)
|
||||
|
||||
private lateinit var contactsAdapter: ContactsListAdapter
|
||||
private lateinit var suggestionsAdapter: ContactsListAdapter
|
||||
private lateinit var suggestionsAdapter: SuggestionsListAdapter
|
||||
|
||||
private val listener = object : ContactNumberOrAddressClickListener {
|
||||
@UiThread
|
||||
|
|
@ -101,7 +102,7 @@ class StartCallFragment : GenericFragment() {
|
|||
goBack()
|
||||
}
|
||||
|
||||
contactsAdapter = ContactsListAdapter(viewLifecycleOwner, false)
|
||||
contactsAdapter = ContactsListAdapter(viewLifecycleOwner, disableLongClick = true)
|
||||
binding.contactsList.setHasFixedSize(true)
|
||||
binding.contactsList.adapter = contactsAdapter
|
||||
|
||||
|
|
@ -113,7 +114,7 @@ class StartCallFragment : GenericFragment() {
|
|||
|
||||
binding.contactsList.layoutManager = LinearLayoutManager(requireContext())
|
||||
|
||||
suggestionsAdapter = ContactsListAdapter(viewLifecycleOwner, false)
|
||||
suggestionsAdapter = SuggestionsListAdapter(viewLifecycleOwner)
|
||||
binding.suggestionsList.setHasFixedSize(true)
|
||||
binding.suggestionsList.adapter = suggestionsAdapter
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class SuggestionsListViewModel : ViewModel() {
|
|||
applyFilter(
|
||||
currentFilter,
|
||||
if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else "",
|
||||
MagicSearch.Source.CallLogs.toInt() or MagicSearch.Source.ChatRooms.toInt(),
|
||||
MagicSearch.Source.CallLogs.toInt() or MagicSearch.Source.ChatRooms.toInt() or MagicSearch.Source.Request.toInt(),
|
||||
MagicSearch.Aggregation.Friend
|
||||
)
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class SuggestionsListViewModel : ViewModel() {
|
|||
applyFilter(
|
||||
filter,
|
||||
if (limitSearchToLinphoneAccounts) corePreferences.defaultDomain else "",
|
||||
MagicSearch.Source.CallLogs.toInt() or MagicSearch.Source.ChatRooms.toInt(),
|
||||
MagicSearch.Source.CallLogs.toInt() or MagicSearch.Source.ChatRooms.toInt() or MagicSearch.Source.Request.toInt(),
|
||||
MagicSearch.Aggregation.Friend
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ import org.linphone.utils.Event
|
|||
|
||||
class ContactsListAdapter(
|
||||
private val viewLifecycleOwner: LifecycleOwner,
|
||||
private val favourites: Boolean
|
||||
private val favourites: Boolean = false,
|
||||
private val disableLongClick: Boolean = false
|
||||
) : ListAdapter<ContactAvatarModel, RecyclerView.ViewHolder>(ContactDiffCallback()) {
|
||||
var selectedAdapterPosition = -1
|
||||
|
||||
|
|
@ -78,11 +79,13 @@ class ContactsListAdapter(
|
|||
contactClickedEvent.value = Event(contactModel)
|
||||
}
|
||||
|
||||
binding.setOnLongClickListener {
|
||||
selectedAdapterPosition = bindingAdapterPosition
|
||||
binding.root.isSelected = true
|
||||
contactLongClickedEvent.value = Event(contactModel)
|
||||
true
|
||||
if (!disableLongClick) {
|
||||
binding.setOnLongClickListener {
|
||||
selectedAdapterPosition = bindingAdapterPosition
|
||||
binding.root.isSelected = true
|
||||
contactLongClickedEvent.value = Event(contactModel)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
executePendingBindings()
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class ContactsListFragment : GenericFragment() {
|
|||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
binding.viewModel = listViewModel
|
||||
|
||||
adapter = ContactsListAdapter(viewLifecycleOwner, false)
|
||||
adapter = ContactsListAdapter(viewLifecycleOwner)
|
||||
binding.contactsList.setHasFixedSize(true)
|
||||
binding.contactsList.adapter = adapter
|
||||
configureAdapter(adapter)
|
||||
|
|
@ -82,7 +82,7 @@ class ContactsListFragment : GenericFragment() {
|
|||
val layoutManager = LinearLayoutManager(requireContext())
|
||||
binding.contactsList.layoutManager = layoutManager
|
||||
|
||||
favouritesAdapter = ContactsListAdapter(viewLifecycleOwner, true)
|
||||
favouritesAdapter = ContactsListAdapter(viewLifecycleOwner, favourites = true)
|
||||
binding.favouritesContactsList.setHasFixedSize(true)
|
||||
binding.favouritesContactsList.adapter = favouritesAdapter
|
||||
configureAdapter(favouritesAdapter)
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@
|
|||
android:padding="5dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="All contacts"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Contacts"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
@ -123,7 +123,7 @@
|
|||
android:id="@+id/contacts_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/all_contacts_label"
|
||||
|
|
@ -137,7 +137,7 @@
|
|||
android:padding="5dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="Suggestions"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
@ -149,7 +149,7 @@
|
|||
android:id="@+id/suggestions_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintHeight_max="220dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue