diff --git a/app/src/main/java/org/linphone/ui/contacts/ContactsFragment.kt b/app/src/main/java/org/linphone/ui/contacts/ContactsFragment.kt index b9c091ab8..78bf8d5d5 100644 --- a/app/src/main/java/org/linphone/ui/contacts/ContactsFragment.kt +++ b/app/src/main/java/org/linphone/ui/contacts/ContactsFragment.kt @@ -95,6 +95,15 @@ class ContactsFragment : Fragment() { binding.contactsList.setHasFixedSize(true) binding.contactsList.adapter = adapter + adapter.contactLongClickedEvent.observe(viewLifecycleOwner) { + it.consume { model -> + val modalBottomSheet = ContactsListMenuDialogFragment(model.friend) { + adapter.resetSelection() + } + modalBottomSheet.show(parentFragmentManager, ContactsListMenuDialogFragment.TAG) + } + } + val layoutManager = LinearLayoutManager(requireContext()) binding.contactsList.layoutManager = layoutManager diff --git a/app/src/main/java/org/linphone/ui/contacts/ContactsListMenuDialogFragment.kt b/app/src/main/java/org/linphone/ui/contacts/ContactsListMenuDialogFragment.kt new file mode 100644 index 000000000..f586d37ea --- /dev/null +++ b/app/src/main/java/org/linphone/ui/contacts/ContactsListMenuDialogFragment.kt @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010-2023 Belledonne Communications SARL. + * + * This file is part of linphone-android + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.linphone.ui.contacts + +import android.content.DialogInterface +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import org.linphone.core.Friend +import org.linphone.databinding.ContactsListLongPressMenuBinding + +class ContactsListMenuDialogFragment( + private val friend: Friend, + private val onDismiss: (() -> Unit)? = null +) : BottomSheetDialogFragment() { + companion object { + const val TAG = "ContactsListMenuDialogFragment" + } + + override fun onCancel(dialog: DialogInterface) { + onDismiss?.invoke() + super.onCancel(dialog) + } + + override fun onDismiss(dialog: DialogInterface) { + onDismiss?.invoke() + super.onDismiss(dialog) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val view = ContactsListLongPressMenuBinding.inflate(layoutInflater) + + return view.root + } +} diff --git a/app/src/main/java/org/linphone/ui/contacts/adapter/ConversationsListAdapter.kt b/app/src/main/java/org/linphone/ui/contacts/adapter/ConversationsListAdapter.kt index a07007f17..df3705eb0 100644 --- a/app/src/main/java/org/linphone/ui/contacts/adapter/ConversationsListAdapter.kt +++ b/app/src/main/java/org/linphone/ui/contacts/adapter/ConversationsListAdapter.kt @@ -4,18 +4,28 @@ import android.view.LayoutInflater import android.view.ViewGroup 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.contacts.model.ContactModel +import org.linphone.utils.Event class ContactsListAdapter( private val viewLifecycleOwner: LifecycleOwner ) : ListAdapter(ContactDiffCallback()) { var selectedAdapterPosition = -1 + val contactClickedEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + + val contactLongClickedEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { val binding: ContactListCellBinding = DataBindingUtil.inflate( LayoutInflater.from(parent.context), @@ -63,6 +73,17 @@ class ContactsListAdapter( binding.root.isSelected = bindingAdapterPosition == selectedAdapterPosition + binding.setOnClickListener { + contactClickedEvent.value = Event(contactModel) + } + + binding.setOnLongClickListener { + selectedAdapterPosition = bindingAdapterPosition + binding.root.isSelected = true + contactLongClickedEvent.value = Event(contactModel) + true + } + executePendingBindings() } } diff --git a/app/src/main/res/drawable/delete.xml b/app/src/main/res/drawable/delete.xml new file mode 100644 index 000000000..31421c8f7 --- /dev/null +++ b/app/src/main/res/drawable/delete.xml @@ -0,0 +1,13 @@ + + + diff --git a/app/src/main/res/drawable/favorite.xml b/app/src/main/res/drawable/favorite.xml new file mode 100644 index 000000000..44db34b4b --- /dev/null +++ b/app/src/main/res/drawable/favorite.xml @@ -0,0 +1,13 @@ + + + diff --git a/app/src/main/res/drawable/invite.xml b/app/src/main/res/drawable/invite.xml new file mode 100644 index 000000000..41ae581d3 --- /dev/null +++ b/app/src/main/res/drawable/invite.xml @@ -0,0 +1,13 @@ + + + diff --git a/app/src/main/res/drawable/share.xml b/app/src/main/res/drawable/share.xml new file mode 100644 index 000000000..06fb2604d --- /dev/null +++ b/app/src/main/res/drawable/share.xml @@ -0,0 +1,13 @@ + + + diff --git a/app/src/main/res/layout/contact_list_cell.xml b/app/src/main/res/layout/contact_list_cell.xml index 371764c72..04ac5280f 100644 --- a/app/src/main/res/layout/contact_list_cell.xml +++ b/app/src/main/res/layout/contact_list_cell.xml @@ -15,9 +15,17 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file