Added confirmation dialog before clearing conversation history

This commit is contained in:
Sylvain Berfini 2024-06-04 11:01:50 +02:00
parent a3489f4064
commit cfe7a8ed38
7 changed files with 160 additions and 5 deletions

View file

@ -42,6 +42,7 @@ import org.linphone.ui.main.chat.model.ParticipantModel
import org.linphone.ui.main.chat.viewmodel.ConversationInfoViewModel
import org.linphone.ui.main.fragment.GroupSetOrEditSubjectDialogModel
import org.linphone.ui.main.fragment.SlidingPaneChildFragment
import org.linphone.ui.main.history.model.ConfirmationDialogModel
import org.linphone.utils.DialogUtils
import org.linphone.utils.Event
@ -150,7 +151,7 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
Log.i("$TAG History has been deleted, leaving conversation info...")
sharedViewModel.forceRefreshConversationEvents.value = Event(true)
goBack()
val message = getString(R.string.toast_conversation_history_deleted)
val message = getString(R.string.conversation_info_history_deleted_toast)
(requireActivity() as GenericActivity).showGreenToast(
message,
R.drawable.chat_teardrop_text
@ -293,6 +294,10 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
findNavController().navigate(action)
}
}
binding.setDeleteHistoryClickListener {
showDeleteHistoryConfirmationDialog()
}
}
private fun showParticipantAdminPopupMenu(view: View, participantModel: ParticipantModel) {
@ -373,4 +378,27 @@ class ConversationInfoFragment : SlidingPaneChildFragment() {
popupWindow.elevation = 20f
popupWindow.showAsDropDown(view, 0, 0, Gravity.BOTTOM)
}
private fun showDeleteHistoryConfirmationDialog() {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getDeleteConversationHistoryConfirmationDialog(
requireActivity(),
model
)
model.dismissEvent.observe(viewLifecycleOwner) {
it.consume {
dialog.dismiss()
}
}
model.confirmEvent.observe(viewLifecycleOwner) {
it.consume {
viewModel.deleteHistory()
dialog.dismiss()
}
}
dialog.show()
}
}

View file

@ -267,7 +267,6 @@ class ConversationInfoViewModel @UiThread constructor() : AbstractConversationVi
@UiThread
fun deleteHistory() {
coreContext.postOnCoreThread {
// TODO: confirmation dialog ?
if (isChatRoomInitialized()) {
Log.i(
"$TAG Cleaning conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] history"

View file

@ -50,6 +50,7 @@ import org.linphone.databinding.DialogPickNumberOrAddressBinding
import org.linphone.databinding.DialogRemoveAccountBinding
import org.linphone.databinding.DialogRemoveAllCallLogsBinding
import org.linphone.databinding.DialogRemoveCallLogsBinding
import org.linphone.databinding.DialogRemoveConversationHistoryBinding
import org.linphone.databinding.DialogSetOrEditGroupSubjectBindingImpl
import org.linphone.databinding.DialogUpdateAccountPasswordBinding
import org.linphone.databinding.DialogUpdateAvailableBinding
@ -293,6 +294,22 @@ class DialogUtils {
return getDialog(context, binding)
}
@UiThread
fun getDeleteConversationHistoryConfirmationDialog(
context: Context,
viewModel: ConfirmationDialogModel
): Dialog {
val binding: DialogRemoveConversationHistoryBinding = DataBindingUtil.inflate(
LayoutInflater.from(context),
R.layout.dialog_remove_conversation_history,
null,
false
)
binding.viewModel = viewModel
return getDialog(context, binding)
}
@UiThread
fun getOpenOrExportFileDialog(
context: Context,

View file

@ -24,6 +24,9 @@
<variable
name="configureEphemeralMessagesClickListener"
type="View.OnClickListener" />
<variable
name="deleteHistoryClickListener"
type="View.OnClickListener" />
<variable
name="viewModel"
type="org.linphone.ui.main.chat.viewmodel.ConversationInfoViewModel" />
@ -443,7 +446,7 @@
android:layout_marginBottom="@dimen/screen_bottom_margin"
android:background="@drawable/action_background"
android:drawableStart="@drawable/trash_simple"
android:onClick="@{() -> viewModel.deleteHistory()}"
android:onClick="@{deleteHistoryClickListener}"
android:text="@string/conversation_info_delete_history_action"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/actions_background"

View file

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<import type="android.graphics.Typeface" />
<variable
name="viewModel"
type="org.linphone.ui.main.history.model.ConfirmationDialogModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:onClick="@{() -> viewModel.dismiss()}"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/dialog_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="2dp"
android:src="@drawable/shape_dialog_background"
android:contentDescription="@null"
app:layout_constraintWidth_max="@dimen/dialog_max_width"
app:layout_constraintBottom_toBottomOf="@id/anchor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/title" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/section_header_style"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:paddingTop="@dimen/dialog_top_bottom_margin"
android:text="@string/conversation_info_dialog_delete_all_call_logs_title"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@id/message"
app:layout_constraintStart_toStartOf="@id/dialog_background"
app:layout_constraintEnd_toEndOf="@id/dialog_background"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_marginTop="10dp"
android:text="@string/conversation_info_dialog_delete_all_message"
android:textSize="14sp"
app:layout_constraintBottom_toTopOf="@id/cancel"
app:layout_constraintStart_toStartOf="@id/dialog_background"
app:layout_constraintEnd_toEndOf="@id/dialog_background"
app:layout_constraintTop_toBottomOf="@id/title" />
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{() -> viewModel.dismiss()}"
style="@style/secondary_button_label_style"
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:text="@string/dialog_cancel"
app:layout_constraintStart_toStartOf="@id/dialog_background"
app:layout_constraintEnd_toEndOf="@id/dialog_background"
app:layout_constraintTop_toBottomOf="@id/message"
app:layout_constraintBottom_toTopOf="@id/confirm"/>
<androidx.appcompat.widget.AppCompatTextView
android:onClick="@{() -> viewModel.confirm()}"
style="@style/primary_button_label_style"
android:id="@+id/confirm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:text="@string/dialog_delete"
app:layout_constraintStart_toStartOf="@id/dialog_background"
app:layout_constraintEnd_toEndOf="@id/dialog_background"
app:layout_constraintTop_toBottomOf="@id/cancel"
app:layout_constraintBottom_toTopOf="@id/anchor"/>
<View
android:id="@+id/anchor"
android:layout_width="wrap_content"
android:layout_height="@dimen/dialog_top_bottom_margin"
app:layout_constraintTop_toBottomOf="@id/confirm"
app:layout_constraintStart_toStartOf="@id/dialog_background"
app:layout_constraintEnd_toEndOf="@id/dialog_background"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -94,7 +94,6 @@
<string name="toast_voice_recording_max_duration_reached">Durée maximale atteinte</string>
<string name="toast_failed_to_add_participant_to_group_conversation">Un ou plusieurs participants n\'ont pû être ajoutés</string>
<string name="toast_conversation_deleted">Conversation supprimée</string>
<string name="toast_conversation_history_deleted">Historique d\'appels supprimé</string>
<string name="toast_group_conversation_left">Vous avez quitté la conversation</string>
<string name="toast_low_media_volume">Le volume media est bas, vous pourriez ne rien entendre !</string>
<string name="toast_no_app_registered_to_handle_content_type_error">Aucune application trouvée pour lire ce fichier</string>
@ -494,6 +493,9 @@
<string name="conversation_info_admin_menu_unset_participant_admin">Retirer les privilèges administrateur</string>
<string name="conversation_info_menu_go_to_contact">Voir le contact</string>
<string name="conversation_info_menu_add_to_contacts">Ajouter aux contacts</string>
<string name="conversation_info_dialog_delete_all_call_logs_title">Voulez-vous tout supprimer ?</string>
<string name="conversation_info_dialog_delete_all_message">Tout les messages de cette conversation seront supprimés.</string>
<string name="conversation_info_history_deleted_toast">Historique supprimé</string>
<string name="conversation_event_conference_created">Vous avez rejoint le groupe</string>
<string name="conversation_event_conference_destroyed">Vous avez quitté le groupe</string>

View file

@ -129,7 +129,6 @@
<string name="toast_voice_recording_max_duration_reached">Max duration reached</string>
<string name="toast_failed_to_add_participant_to_group_conversation">Failed to add participant(s) to conversation</string>
<string name="toast_conversation_deleted">Conversation was successfully deleted</string>
<string name="toast_conversation_history_deleted">History has been successfully deleted</string>
<string name="toast_group_conversation_left">You have left the group</string>
<string name="toast_low_media_volume">Media volume is low, you may not hear anything!</string>
<string name="toast_no_app_registered_to_handle_content_type_error">No app found to open this kind of file</string>
@ -530,6 +529,9 @@
<string name="conversation_info_admin_menu_unset_participant_admin">Remove admin rights</string>
<string name="conversation_info_menu_go_to_contact">See contact profile</string>
<string name="conversation_info_menu_add_to_contacts">Add to contacts</string>
<string name="conversation_info_dialog_delete_all_call_logs_title">Do you really want to delete all messages?</string>
<string name="conversation_info_dialog_delete_all_message">All messages will be removed from the history</string>
<string name="conversation_info_history_deleted_toast">History has been successfully deleted</string>
<string name="conversation_event_conference_created">You have joined the group</string>
<string name="conversation_event_conference_destroyed">You have left the group</string>