Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dialog to confirm we want to block a user #2046

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class MainViewModel @Inject constructor(
val reportPhishingTrigger = SingleLiveEvent<Unit>()
val reportDisplayProblemTrigger = SingleLiveEvent<Unit>()
val canInstallUpdate = MutableLiveData(false)
val messageOfUserToBlock = SingleLiveEvent<Message>()

val autoAdvanceThreadsUids = MutableLiveData<List<String>>()

Expand Down Expand Up @@ -1062,8 +1063,14 @@ class MainViewModel @Inject constructor(
emit(hasOtherExpeditors)
}

fun hasMoreThanOneExpeditor(threadUid: String) = liveData(ioCoroutineContext) {
val hasMoreThanOneExpeditor =
(threadController.getThread(threadUid)?.messages?.flatMap { it.from }?.filter { it.isMe() }?.size ?: 0) > 1
emit(hasMoreThanOneExpeditor)
}

fun getMessagesFromUniqueExpeditors(threadUid: String) = liveData(ioCoroutineContext) {
val messageToRecipient = threadController.getThread(threadUid)?.messages?.flatMap { message ->
val messageToRecipient = threadController.getThread(threadUid)?.messages?.distinctBy { it.from }?.flatMap { message ->
message.from.filterNot { it.isMe() }
.distinct()
.map { from -> message to from }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.infomaniak.mail.MatomoMail.ACTION_REPLY_NAME
import com.infomaniak.mail.MatomoMail.OPEN_ACTION_BOTTOM_SHEET
import com.infomaniak.mail.MatomoMail.OPEN_FROM_DRAFT_NAME
import com.infomaniak.mail.MatomoMail.trackAttachmentActionsEvent
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
import com.infomaniak.mail.MatomoMail.trackMessageActionsEvent
import com.infomaniak.mail.MatomoMail.trackNewMessageEvent
import com.infomaniak.mail.MatomoMail.trackThreadActionsEvent
Expand All @@ -71,10 +72,7 @@ import com.infomaniak.mail.ui.main.folder.TwoPaneViewModel.NavData
import com.infomaniak.mail.ui.main.thread.SubjectFormatter.SubjectData
import com.infomaniak.mail.ui.main.thread.ThreadAdapter.ContextMenuType
import com.infomaniak.mail.ui.main.thread.ThreadAdapter.ThreadAdapterCallbacks
import com.infomaniak.mail.ui.main.thread.actions.AttachmentActionsBottomSheetDialogArgs
import com.infomaniak.mail.ui.main.thread.actions.MessageActionsBottomSheetDialogArgs
import com.infomaniak.mail.ui.main.thread.actions.ReplyBottomSheetDialogArgs
import com.infomaniak.mail.ui.main.thread.actions.ThreadActionsBottomSheetDialogArgs
import com.infomaniak.mail.ui.main.thread.actions.*
import com.infomaniak.mail.ui.main.thread.calendar.AttendeesBottomSheetDialogArgs
import com.infomaniak.mail.utils.PermissionUtils
import com.infomaniak.mail.utils.UiUtils
Expand Down Expand Up @@ -111,6 +109,9 @@ class ThreadFragment : Fragment() {
@Inject
lateinit var phoneContextualMenuAlertDialog: PhoneContextualMenuAlertDialog

@Inject
lateinit var confirmationToBlockUserDialog: ConfirmationToBlockUserDialog

@Inject
lateinit var permissionUtils: PermissionUtils

Expand Down Expand Up @@ -155,12 +156,26 @@ class ThreadFragment : Fragment() {
observeAutoAdvance()

observeReportDisplayProblemResult()

observeMessageOfUserToBlock()
}

private fun observeReportDisplayProblemResult() {
mainViewModel.reportDisplayProblemTrigger.observe(viewLifecycleOwner) { descriptionDialog.resetLoadingAndDismiss() }
}

private fun observeMessageOfUserToBlock() = with(confirmationToBlockUserDialog) {
mainViewModel.messageOfUserToBlock.observe(viewLifecycleOwner) {
setPositiveButtonCallback { messageOfUserToBlock ->
messageOfUserToBlock?.let {
trackBottomSheetThreadActionsEvent("blockUser")
mainViewModel.blockUser(messageOfUserToBlock)
}
}
show(it)
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
threadAdapter.reRenderMails()
super.onConfigurationChanged(newConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* 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 com.infomaniak.mail.ui.main.thread.actions

import android.content.Context
import androidx.appcompat.app.AlertDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.infomaniak.lib.core.utils.context
import com.infomaniak.mail.R
import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.databinding.DialogConfirmationToBlockUserBinding
import com.infomaniak.mail.ui.alertDialogs.BaseAlertDialog
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject
import com.infomaniak.lib.core.R as RCore

@ActivityScoped
class ConfirmationToBlockUserDialog @Inject constructor(
@ActivityContext private val activityContext: Context,
) : BaseAlertDialog(activityContext) {

private val binding: DialogConfirmationToBlockUserBinding by lazy {
DialogConfirmationToBlockUserBinding.inflate(activity.layoutInflater)
}

private var onPositiveButtonClick: ((Message?) -> Unit)? = null
private var messageOfUserToBlock: Message? = null

override val alertDialog: AlertDialog = with(binding) {
MaterialAlertDialogBuilder(context)
.setView(root)
.setPositiveButton(R.string.buttonConfirm) { _, _ ->
onPositiveButtonClick?.invoke(messageOfUserToBlock)
}
.setNegativeButton(RCore.string.buttonCancel, null)
.create()
}

override fun resetCallbacks() {
onPositiveButtonClick = null
}

fun show(message: Message) = with(binding) {
messageOfUserToBlock = message
val recipient = message.from[0]
val title = recipient.name.ifBlank { recipient.email }
blockExpeditorTitle.text = activityContext.getString(R.string.blockExpeditorTitle, title)
blockExpeditorDescription.text = activityContext.getString(R.string.confirmationToBlockAnExpeditorText, recipient.email)
alertDialog.show()
}

fun setPositiveButtonCallback(onPositiveButtonClick: (Message?) -> Unit) {
this.onPositiveButtonClick = onPositiveButtonClick
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class JunkBottomSheetDialog : ActionsBottomSheetDialog() {

private var binding: BottomSheetJunkBinding by safeBinding()
private val navigationArgs: JunkBottomSheetDialogArgs by navArgs()

private var messageOfUserToBlock: Message? = null

override val mainViewModel: MainViewModel by activityViewModels()

@Inject
Expand All @@ -56,6 +59,7 @@ class JunkBottomSheetDialog : ActionsBottomSheetDialog() {
super.onViewCreated(view, savedInstanceState)

mainViewModel.getMessage(messageUid).observe(viewLifecycleOwner) { message ->
[email protected] = message
handleButtons(threadUid, message)
}

Expand All @@ -70,24 +74,35 @@ class JunkBottomSheetDialog : ActionsBottomSheetDialog() {
}
}

private fun observeExpeditorsResult(threadUid: String) = with(binding) {
mainViewModel.hasOtherExpeditors(threadUid).observe(viewLifecycleOwner) { hasOtherExpeditors ->
if (hasOtherExpeditors) {
blockSender.setClosingOnClickListener {
private fun observeHasMoreThanOneExpeditor(threadUid: String) {
mainViewModel.hasMoreThanOneExpeditor(threadUid).observe(viewLifecycleOwner) { hasMoreThanOneExpeditor ->
binding.blockSender.setClosingOnClickListener {
if (hasMoreThanOneExpeditor) {
safeNavigate(
resId = R.id.userToBlockBottomSheetDialog,
args = UserToBlockBottomSheetDialogArgs(threadUid).toBundle(),
currentClassName = JunkBottomSheetDialog::class.java.name,
)
} else {
messageOfUserToBlock?.let {
mainViewModel.messageOfUserToBlock.value = messageOfUserToBlock
}
}
}
}
}

private fun observeExpeditorsResult(threadUid: String) {
mainViewModel.hasOtherExpeditors(threadUid).observe(viewLifecycleOwner) { hasOtherExpeditors ->
if (hasOtherExpeditors) {
observeHasMoreThanOneExpeditor(threadUid)
} else {
blockSender.isGone = true
binding.blockSender.isGone = true
}
}
}

private fun handleButtons(threadUid: String, message: Message) = with(binding) {

spam.setClosingOnClickListener {
trackBottomSheetThreadActionsEvent(ACTION_SPAM_NAME, value = message.folder.role == FolderRole.SPAM)
mainViewModel.toggleThreadSpamStatus(threadUid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@
*/
package com.infomaniak.mail.ui.main.thread.actions

import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.navArgs
import com.infomaniak.lib.core.utils.safeBinding
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.databinding.BottomSheetUserToBlockBinding
import com.infomaniak.mail.ui.MainViewModel

class UserToBlockBottomSheetDialog : ActionsBottomSheetDialog() {

private var binding: BottomSheetUserToBlockBinding by safeBinding()
private val navigationArgs: UserToBlockBottomSheetDialogArgs by navArgs()

private var messageOfUserToBlock: Message? = null

override val mainViewModel: MainViewModel by activityViewModels()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand All @@ -43,11 +47,15 @@ class UserToBlockBottomSheetDialog : ActionsBottomSheetDialog() {
mainViewModel.getMessagesFromUniqueExpeditors(threadUid).observe(viewLifecycleOwner) { messages ->
messages?.let {
binding.recipients.adapter = UserToBlockAdapter(messages) { message ->
trackBottomSheetThreadActionsEvent("blockUser")
mainViewModel.blockUser(message)
messageOfUserToBlock = message
dismiss()
}
}
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
messageOfUserToBlock?.let { mainViewModel.messageOfUserToBlock.value = it }
}
}
41 changes: 41 additions & 0 deletions app/src/main/res/layout/dialog_confirmation_to_block_user.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Infomaniak Mail - Android
~ Copyright (C) 2024 Infomaniak Network SA
~
~ 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/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="@dimen/marginStandard"
android:paddingVertical="@dimen/marginStandardSmall">

<TextView
android:id="@+id/blockExpeditorTitle"
style="@style/BottomSheetTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marginStandard"
tools:text="Block Jean-Michel" />

<TextView
android:id="@+id/blockExpeditorDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marginStandardMedium"
tools:text="@string/confirmationToBlockAnExpeditorText" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<string name="attendeesListTitle">Liste der Teilnehmer (%d)</string>
<string name="bccTitle">Bcc:</string>
<string name="blockAnExpeditorTitle">Einen Absender blockieren</string>
<string name="blockExpeditorTitle">Block %s</string>
<plurals name="blockedPasswordTitle">
<item quantity="one">Passwort blockiert</item>
<item quantity="other">Blockierte Passwörter</item>
Expand Down Expand Up @@ -176,6 +177,7 @@
<string name="commercialFolder">Werbeaktionen</string>
<string name="confirmLogoutDescription">Sind Sie sicher, dass Sie sich von %s abmelden möchten?</string>
<string name="confirmLogoutTitle">Abmelden</string>
<string name="confirmationToBlockAnExpeditorText">Diese E-Mail und alle zukünftigen Nachrichten von %s werden in den Junk-Mail-Ordner verschoben.</string>
<string name="contactActionAddToContacts">Zu Kontakten hinzufügen</string>
<string name="contactActionCopyEmailAddress">E-Mail Adresse kopieren</string>
<string name="contactActionWriteEmail">Schreiben Sie eine E-Mail</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<string name="attendeesListTitle">Lista de asistentes (%d)</string>
<string name="bccTitle">CCO:</string>
<string name="blockAnExpeditorTitle">Bloquear un remitente</string>
<string name="blockExpeditorTitle">Bloquear %s</string>
<plurals name="blockedPasswordTitle">
<item quantity="one">Contraseña bloqueada</item>
<item quantity="other">Contraseñas bloqueadas</item>
Expand Down Expand Up @@ -176,6 +177,7 @@
<string name="commercialFolder">Promociones</string>
<string name="confirmLogoutDescription">¿Seguro que quieres desconectarte de %s?</string>
<string name="confirmLogoutTitle">Cerrar sesión</string>
<string name="confirmationToBlockAnExpeditorText">Este correo electrónico y todos los futuros mensajes de %s se moverán a la carpeta de correo no deseado.</string>
<string name="contactActionAddToContacts">Añadir a contactos</string>
<string name="contactActionCopyEmailAddress">Copiar dirección de correo electrónico</string>
<string name="contactActionWriteEmail">Escriba un correo electrónico</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<string name="attendeesListTitle">Liste des participants (%d)</string>
<string name="bccTitle">Cci :</string>
<string name="blockAnExpeditorTitle">Bloquer un expéditeur</string>
<string name="blockExpeditorTitle">Bloquer %s</string>
<plurals name="blockedPasswordTitle">
<item quantity="one">Mot de passe bloqué</item>
<item quantity="other">Mots de passe bloqués</item>
Expand Down Expand Up @@ -178,6 +179,7 @@
<string name="commercialFolder">Promotions</string>
<string name="confirmLogoutDescription">Êtes-vous sûr de vouloir vous déconnecter du compte %s ?</string>
<string name="confirmLogoutTitle">Me déconnecter</string>
<string name="confirmationToBlockAnExpeditorText">Cet e-mail et tous les futurs messages de %s seront déplacés dans le dossier Courrier indésirable.</string>
<string name="contactActionAddToContacts">Ajouter aux contacts</string>
<string name="contactActionCopyEmailAddress">Copier l’adresse mail</string>
<string name="contactActionWriteEmail">Écrire un e-mail</string>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
</plurals>
<string name="attendeesListTitle">Elenco dei partecipanti (%d)</string>
<string name="bccTitle">Bcc:</string>
<string name="blockAnExpeditorTitle">Bloccare un mittente</string>
<string name="blockAnExpeditorTitle">Blocca un mittente</string>
<string name="blockExpeditorTitle">Blocca %s</string>
<plurals name="blockedPasswordTitle">
<item quantity="one">Password bloccata</item>
<item quantity="other">Password bloccate</item>
Expand Down Expand Up @@ -176,6 +177,7 @@
<string name="commercialFolder">Promozioni</string>
<string name="confirmLogoutDescription">Sei sicuro di volerti disconnettere da %s?</string>
<string name="confirmLogoutTitle">Disconnettersi</string>
<string name="confirmationToBlockAnExpeditorText">Questa e-mail e tutti i futuri messaggi di %s saranno spostati nella cartella della posta indesiderata.</string>
<string name="contactActionAddToContacts">Aggiungi ai contatti</string>
<string name="contactActionCopyEmailAddress">Copia l’indirizzo e-mail</string>
<string name="contactActionWriteEmail">Scrivi un’e-mail</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<string name="attendeesListTitle">List of attendees (%d)</string>
<string name="bccTitle">Bcc:</string>
<string name="blockAnExpeditorTitle">Block a sender</string>
<string name="blockExpeditorTitle">Block %s</string>
<plurals name="blockedPasswordTitle">
<item quantity="one">Blocked password</item>
<item quantity="other">Blocked passwords</item>
Expand Down Expand Up @@ -182,6 +183,7 @@
<string name="commercialFolder">Promotions</string>
<string name="confirmLogoutDescription">Are you sure you want to log out from %s?</string>
<string name="confirmLogoutTitle">Log out</string>
<string name="confirmationToBlockAnExpeditorText">This email and all future messages from %s will be moved to the Junk Mail folder.</string>
<string name="contactActionAddToContacts">Add to contacts</string>
<string name="contactActionCopyEmailAddress">Copy email address</string>
<string name="contactActionWriteEmail">Write an email</string>
Expand Down
Loading