Added long press bottom sheet menu to meetings list cell

This commit is contained in:
Sylvain Berfini 2023-11-17 14:46:31 +01:00
parent 3ce702fc0d
commit 6b95cc6a5c
10 changed files with 200 additions and 53 deletions

View file

@ -23,6 +23,8 @@ class MeetingsListAdapter :
MeetingDiffCallback()
),
HeaderAdapter {
var selectedAdapterPosition = -1
val meetingClickedEvent: MutableLiveData<Event<MeetingModel>> by lazy {
MutableLiveData<Event<MeetingModel>>()
}
@ -53,6 +55,7 @@ class MeetingsListAdapter :
parent,
false
)
val viewHolder = ViewHolder(binding)
binding.apply {
lifecycleOwner = parent.findViewTreeLifecycleOwner()
@ -61,18 +64,24 @@ class MeetingsListAdapter :
}
setOnLongClickListener {
selectedAdapterPosition = viewHolder.bindingAdapterPosition
root.isSelected = true
meetingLongClickedEvent.value = Event(model!!)
true
}
}
return ViewHolder(binding)
return viewHolder
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as ViewHolder).bind(getItem(position))
}
fun resetSelection() {
notifyItemChanged(selectedAdapterPosition)
selectedAdapterPosition = -1
}
inner class ViewHolder(
val binding: MeetingListCellBinding
) : RecyclerView.ViewHolder(binding.root) {
@ -80,6 +89,9 @@ class MeetingsListAdapter :
fun bind(meetingModel: MeetingModel) {
with(binding) {
model = meetingModel
binding.root.isSelected = bindingAdapterPosition == selectedAdapterPosition
executePendingBindings()
}
}

View file

@ -140,6 +140,22 @@ class MeetingsListFragment : AbstractTopBarFragment() {
}
}
adapter.meetingLongClickedEvent.observe(viewLifecycleOwner) {
it.consume { model ->
val modalBottomSheet = MeetingsMenuDialogFragment(
{ // onDismiss
adapter.resetSelection()
},
{ // onDelete
Log.i("$TAG Deleting meeting [${model.id}]")
model.delete()
listViewModel.applyFilter()
}
)
modalBottomSheet.show(parentFragmentManager, MeetingsMenuDialogFragment.TAG)
}
}
sharedViewModel.forceRefreshMeetingsListEvent.observe(viewLifecycleOwner) {
it.consume {
Log.i("$TAG We were asked to refresh the meetings list, doing it now")

View file

@ -0,0 +1,64 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.linphone.ui.main.meetings.fragment
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.linphone.databinding.MeetingsListLongPressMenuBinding
@UiThread
class MeetingsMenuDialogFragment(
private val onDismiss: (() -> Unit)? = null,
private val onDeleteMeeting: (() -> Unit)? = null
) : BottomSheetDialogFragment() {
companion object {
const val TAG = "MeetingsMenuDialogFragment"
}
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 = MeetingsListLongPressMenuBinding.inflate(layoutInflater)
view.setDeleteClickListener {
onDeleteMeeting?.invoke()
dismiss()
}
return view.root
}
}

View file

@ -19,13 +19,20 @@
*/
package org.linphone.ui.main.meetings.model
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.ConferenceInfo
import org.linphone.core.Participant
import org.linphone.core.tools.Log
import org.linphone.utils.TimestampUtils
class MeetingModel @WorkerThread constructor(conferenceInfo: ConferenceInfo) {
class MeetingModel @WorkerThread constructor(private val conferenceInfo: ConferenceInfo) {
companion object {
private const val TAG = "[Meeting Model]"
}
val id = conferenceInfo.uri?.asStringUriOnly() ?: ""
val timestamp = conferenceInfo.dateTime
@ -65,4 +72,12 @@ class MeetingModel @WorkerThread constructor(conferenceInfo: ConferenceInfo) {
isBroadcast.postValue(!allSpeaker)
}
@UiThread
fun delete() {
coreContext.postOnCoreThread { core ->
Log.w("$TAG Deleting conference info [${conferenceInfo.uri?.asStringUriOnly()}]")
core.deleteConferenceInformation(conferenceInfo)
}
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/shape_squircle_gray_main2_100_r10_background" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_squircle_gray_main2_100_r10_background" />
<item
android:drawable="@drawable/shape_squircle_white_r10_background" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/gray_main2_100"/>
</shape>

View file

@ -16,9 +16,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="@{() -> model.clicked()}"
android:background="@drawable/primary_cell_background"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
android:layout_marginEnd="16dp"
android:background="@drawable/primary_cell_background">
<com.google.android.material.imageview.ShapeableImageView
style="@style/avatar_imageview"

View file

@ -82,7 +82,7 @@
app:layout_constraintBottom_toBottomOf="@id/today_background"
app:layout_constraintTop_toBottomOf="@id/header_day"/>
<androidx.cardview.widget.CardView
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cardview"
android:onClick="@{onClickListener}"
android:onLongClick="@{onLongClickListener}"
@ -92,59 +92,52 @@
android:layout_marginEnd="5dp"
android:layout_marginTop="@{model.firstMeetingOfTheDay ? @dimen/meeting_margin : @dimen/zero, default=@dimen/zero}"
android:layout_marginBottom="8dp"
app:cardBackgroundColor="@color/list_cell_background_color"
app:cardElevation="5dp"
app:cardCornerRadius="10dp"
android:background="@drawable/primary_cell_r10_background"
android:elevation="5dp"
app:layout_constraintStart_toEndOf="@id/header_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/today_separator"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_700"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.subject, default=`Meeting with John`}"
android:textSize="13sp"
android:textColor="@color/gray_main2_600"
android:maxLines="1"
android:ellipsize="end"
android:drawableStart="@{model.isBroadcast ? @drawable/slideshow : @drawable/users_three, default=@drawable/users_three}"
android:drawablePadding="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_700"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.subject, default=`Meeting with John`}"
android:textSize="13sp"
android:textColor="@color/gray_main2_600"
android:maxLines="1"
android:ellipsize="end"
android:drawableStart="@{model.isBroadcast ? @drawable/slideshow : @drawable/users_three, default=@drawable/users_three}"
android:drawablePadding="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="3dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.time, default=`10:00 - 12:00`}"
android:textSize="14sp"
android:textColor="@color/gray_main2_500"
android:maxLines="1"
android:ellipsize="end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="3dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.time, default=`10:00 - 12:00`}"
android:textSize="14sp"
android:textColor="@color/gray_main2_500"
android:maxLines="1"
android:ellipsize="end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View" />
<variable
name="deleteClickListener"
type="View.OnClickListener" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray_main2_200">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/delete"
android:onClick="@{deleteClickListener}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/menu_delete_selected_item"
style="@style/context_menu_danger_action_label_style"
android:background="@drawable/menu_item_background"
android:layout_marginBottom="1dp"
android:drawableStart="@drawable/trash_simple"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -17,9 +17,9 @@
android:onClick="@{onClickListener}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/primary_cell_background"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
android:layout_marginEnd="16dp"
android:background="@drawable/primary_cell_background">
<com.google.android.material.imageview.ShapeableImageView
style="@style/avatar_imageview"