Added confirmation dialog for contact removal & call logs removal

This commit is contained in:
Sylvain Berfini 2023-09-21 11:29:51 +02:00
parent 6faa7b4cb6
commit 141c613eb9
8 changed files with 347 additions and 26 deletions

View file

@ -41,8 +41,10 @@ import org.linphone.databinding.CallFragmentBinding
import org.linphone.databinding.CallPopupMenuBinding
import org.linphone.ui.main.MainActivity
import org.linphone.ui.main.calls.adapter.CallHistoryListAdapter
import org.linphone.ui.main.calls.model.ConfirmationDialogModel
import org.linphone.ui.main.calls.viewmodel.CallLogViewModel
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.DialogUtils
import org.linphone.utils.Event
@UiThread
@ -175,7 +177,7 @@ class CallFragment : GenericFragment() {
}
popupView.setDeleteAllHistoryClickListener {
viewModel.deleteHistory()
showDeleteConfirmationDialog()
popupWindow.dismiss()
}
@ -188,4 +190,30 @@ class CallFragment : GenericFragment() {
popupWindow.elevation = 20f
popupWindow.showAsDropDown(binding.menu, 0, 0, Gravity.BOTTOM)
}
private fun showDeleteConfirmationDialog() {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getRemoveCallLogsConfirmationDialog(
requireActivity(),
model
)
model.dismissEvent.observe(viewLifecycleOwner) {
it.consume {
dialog.dismiss()
}
}
model.confirmRemovalEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w(
"$TAG Removing call entries with [${viewModel.callLogModel.value?.address?.asStringUriOnly()}] from database"
)
viewModel.deleteHistory()
dialog.dismiss()
}
}
dialog.show()
}
}

View file

@ -249,27 +249,7 @@ class CallsListFragment : AbstractTopBarFragment() {
)
popupView.setDeleteAllHistoryClickListener {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getRemoveAllCallLogsConfirmationDialog(
requireActivity(),
model
)
model.dismissEvent.observe(viewLifecycleOwner) {
it.consume {
dialog.dismiss()
}
}
model.confirmRemovalEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w("$TAG Removing all call entries from database")
listViewModel.removeAllCallLogs()
dialog.dismiss()
}
}
dialog.show()
showDeleteConfirmationDialog()
popupWindow.dismiss()
}
@ -277,4 +257,28 @@ class CallsListFragment : AbstractTopBarFragment() {
popupWindow.elevation = 20f
popupWindow.showAsDropDown(binding.menu, 0, 0, Gravity.BOTTOM)
}
private fun showDeleteConfirmationDialog() {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getRemoveAllCallLogsConfirmationDialog(
requireActivity(),
model
)
model.dismissEvent.observe(viewLifecycleOwner) {
it.consume {
dialog.dismiss()
}
}
model.confirmRemovalEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w("$TAG Removing all call entries from database")
listViewModel.removeAllCallLogs()
dialog.dismiss()
}
}
dialog.show()
}
}

View file

@ -41,6 +41,7 @@ import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.databinding.ContactFragmentBinding
import org.linphone.ui.main.MainActivity
import org.linphone.ui.main.calls.model.ConfirmationDialogModel
import org.linphone.ui.main.contacts.model.NumberOrAddressPickerDialogModel
import org.linphone.ui.main.contacts.model.TrustCallDialogModel
import org.linphone.ui.main.contacts.viewmodel.ContactViewModel
@ -100,9 +101,7 @@ class ContactFragment : GenericFragment() {
}
binding.setDeleteClickListener {
viewModel.deleteContact()
goBack()
// TODO: show toast ? show confirmation dialog ?
showDeleteConfirmationDialog()
}
sharedViewModel.isSlidingPaneSlideable.observe(viewLifecycleOwner) { slideable ->
@ -199,6 +198,15 @@ class ContactFragment : GenericFragment() {
}
}
viewModel.contactRemovedEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w(
"$TAG Contact [${viewModel.contact.value?.name?.value}] has been deleted"
)
goBack()
}
}
// TODO: remove later
binding.chat.isEnabled = false
}
@ -288,4 +296,31 @@ class ContactFragment : GenericFragment() {
dialog.show()
}
private fun showDeleteConfirmationDialog() {
val model = ConfirmationDialogModel()
val dialog = DialogUtils.getDeleteContactConfirmationDialog(
requireActivity(),
model,
viewModel.contact.value?.name?.value ?: ""
)
model.dismissEvent.observe(viewLifecycleOwner) {
it.consume {
dialog.dismiss()
}
}
model.confirmRemovalEvent.observe(viewLifecycleOwner) {
it.consume {
Log.w(
"$TAG Deleting contact [${viewModel.contact.value?.name?.value}]"
)
viewModel.deleteContact()
dialog.dismiss()
}
}
dialog.show()
}
}

View file

@ -93,6 +93,10 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Pair<String, String>>>()
}
val contactRemovedEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
private val listener = object : ContactNumberOrAddressClickListener {
@UiThread
override fun onClicked(model: ContactNumberOrAddressModel) {
@ -274,6 +278,7 @@ class ContactViewModel @UiThread constructor() : ViewModel() {
Log.w("$TAG Deleting friend [$friend]")
friend.remove()
coreContext.contactsManager.notifyContactsListChanged()
contactRemovedEvent.postValue(Event(true))
}
}
}

View file

@ -39,9 +39,11 @@ import org.linphone.databinding.DialogCancelContactChangesBinding
import org.linphone.databinding.DialogConfirmZrtpSasBinding
import org.linphone.databinding.DialogContactConfirmTrustCallBinding
import org.linphone.databinding.DialogContactTrustProcessBinding
import org.linphone.databinding.DialogDeleteContactBinding
import org.linphone.databinding.DialogPickNumberOrAddressBinding
import org.linphone.databinding.DialogRemoveAccountBinding
import org.linphone.databinding.DialogRemoveAllCallLogsBinding
import org.linphone.databinding.DialogRemoveCallLogsBinding
import org.linphone.ui.assistant.model.AcceptConditionsAndPolicyDialogModel
import org.linphone.ui.assistant.model.ConfirmPhoneNumberDialogModel
import org.linphone.ui.main.calls.model.ConfirmationDialogModel
@ -176,6 +178,43 @@ class DialogUtils {
return dialog
}
@UiThread
fun getDeleteContactConfirmationDialog(
context: Context,
viewModel: ConfirmationDialogModel,
contactName: String
): Dialog {
val binding: DialogDeleteContactBinding = DataBindingUtil.inflate(
LayoutInflater.from(context),
R.layout.dialog_delete_contact,
null,
false
)
binding.viewModel = viewModel
binding.title.text = context.getString(
R.string.dialog_contact_delete_title,
contactName
)
return getDialog(context, binding)
}
@UiThread
fun getRemoveCallLogsConfirmationDialog(
context: Context,
viewModel: ConfirmationDialogModel
): Dialog {
val binding: DialogRemoveCallLogsBinding = DataBindingUtil.inflate(
LayoutInflater.from(context),
R.layout.dialog_remove_call_logs,
null,
false
)
binding.viewModel = viewModel
return getDialog(context, binding)
}
@UiThread
fun getRemoveAllCallLogsConfirmationDialog(
context: Context,

View file

@ -0,0 +1,103 @@
<?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.calls.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"
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/dialog_contact_delete_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/dialog_contact_delete_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.confirmRemoval()}"
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

@ -0,0 +1,103 @@
<?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.calls.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"
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/dialog_delete_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/dialog_delete_call_logs_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.confirmRemoval()}"
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

@ -71,9 +71,13 @@
<string name="dialog_contact_increase_trust_level_message">You\'re about to make a call to $1%s\'s device $2%s.\nDo you want to make the call?</string>
<string name="dialog_contact_devices_trust_help_title">What does it mean?</string>
<string name="dialog_contact_devices_trust_help_message">Blah blah blah</string> <!-- TODO FIXME -->
<string name="dialog_contact_delete_title">Delete %s?</string>
<string name="dialog_contact_delete_message">This contact will be definitively removed.</string>
<string name="dialog_pick_phone_number_or_sip_address_title">Which canal do you choose?</string>
<string name="dialog_delete_all_call_logs_title">Do you really want to delete all calls history?</string>
<string name="dialog_delete_all_call_logs_message">All calls will be deleted of the history</string>
<string name="dialog_delete_all_call_logs_message">All calls will be removed from the history</string>
<string name="dialog_delete_call_logs_title">Do you really want to delete the history with that person?</string>
<string name="dialog_delete_call_logs_message">All calls will be removed from the history</string>
<string name="dialog_account_secure_mode_default_message">Blah</string> <!-- TODO -->
<string name="dialog_account_secure_mode_interoperable_message">Blah</string> <!-- TODO -->
<string name="dialog_remove_account_title">Delete %s?</string>