Skip to content

Commit 4211ced

Browse files
authored
Merge pull request #1974 from Infomaniak/block-specific-expeditor
Adapter to block a specific contact in a thread
2 parents dbb9471 + 32138cc commit 4211ced

File tree

11 files changed

+184
-6
lines changed

11 files changed

+184
-6
lines changed

app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,20 @@ class MainViewModel @Inject constructor(
10021002
emit(messageController.getMessage(messageUid)!!)
10031003
}
10041004

1005+
fun hasOtherExpeditors(threadUid: String) = liveData(ioCoroutineContext) {
1006+
val hasOtherExpeditors = threadController.getThread(threadUid)?.messages?.flatMap { it.from }?.any { !it.isMe() } ?: false
1007+
emit(hasOtherExpeditors)
1008+
}
1009+
1010+
fun getMessagesFromUniqueExpeditors(threadUid: String) = liveData(ioCoroutineContext) {
1011+
val messageToRecipient = threadController.getThread(threadUid)?.messages?.flatMap { message ->
1012+
message.from.filterNot { it.isMe() }
1013+
.distinct()
1014+
.map { from -> message to from }
1015+
}
1016+
emit(messageToRecipient)
1017+
}
1018+
10051019
fun selectOrUnselectAll() {
10061020
if (isEverythingSelected) {
10071021
appContext.trackMultiSelectionEvent("none")

app/src/main/java/com/infomaniak/mail/ui/main/thread/actions/JunkBottomSheetDialog.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import android.os.Bundle
2121
import android.view.LayoutInflater
2222
import android.view.View
2323
import android.view.ViewGroup
24+
import androidx.core.view.isGone
2425
import androidx.fragment.app.activityViewModels
2526
import androidx.navigation.fragment.findNavController
2627
import androidx.navigation.fragment.navArgs
2728
import com.infomaniak.lib.core.utils.safeBinding
29+
import com.infomaniak.lib.core.utils.safeNavigate
2830
import com.infomaniak.mail.MatomoMail.ACTION_SPAM_NAME
2931
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
3032
import com.infomaniak.mail.R
@@ -58,15 +60,32 @@ class JunkBottomSheetDialog : ActionsBottomSheetDialog() {
5860
}
5961

6062
observeReportPhishingResult()
63+
observeExpeditorsResult(threadUid)
6164
}
6265

63-
fun observeReportPhishingResult() {
66+
private fun observeReportPhishingResult() {
6467
mainViewModel.reportPhishingTrigger.observe(viewLifecycleOwner) {
6568
descriptionDialog.resetLoadingAndDismiss()
6669
findNavController().popBackStack()
6770
}
6871
}
6972

73+
private fun observeExpeditorsResult(threadUid: String) = with(binding) {
74+
mainViewModel.hasOtherExpeditors(threadUid).observe(viewLifecycleOwner) { hasOtherExpeditors ->
75+
if (hasOtherExpeditors) {
76+
blockSender.setClosingOnClickListener {
77+
safeNavigate(
78+
resId = R.id.userToBlockBottomSheetDialog,
79+
args = UserToBlockBottomSheetDialogArgs(threadUid).toBundle(),
80+
currentClassName = JunkBottomSheetDialog::class.java.name,
81+
)
82+
}
83+
} else {
84+
blockSender.isGone = true
85+
}
86+
}
87+
}
88+
7089
private fun handleButtons(threadUid: String, message: Message) = with(binding) {
7190

7291
spam.setClosingOnClickListener {
@@ -82,10 +101,5 @@ class JunkBottomSheetDialog : ActionsBottomSheetDialog() {
82101
onPositiveButtonClicked = { mainViewModel.reportPhishing(threadUid, message) },
83102
)
84103
}
85-
86-
blockSender.setClosingOnClickListener {
87-
trackBottomSheetThreadActionsEvent("blockUser")
88-
mainViewModel.blockUser(message)
89-
}
90104
}
91105
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Infomaniak Mail - Android
3+
* Copyright (C) 2024 Infomaniak Network SA
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.infomaniak.mail.ui.main.thread.actions
19+
20+
import android.view.LayoutInflater
21+
import android.view.ViewGroup
22+
import androidx.recyclerview.widget.RecyclerView.Adapter
23+
import com.infomaniak.mail.data.models.correspondent.Recipient
24+
import com.infomaniak.mail.data.models.message.Message
25+
import com.infomaniak.mail.databinding.ItemContactBinding
26+
import com.infomaniak.mail.ui.newMessage.ContactAdapter.ContactViewHolder
27+
28+
class UserToBlockAdapter(
29+
private val messagesToRecipients: List<Pair<Message, Recipient>>,
30+
private val onClickListener: (Message) -> Unit,
31+
) : Adapter<ContactViewHolder>() {
32+
33+
init {
34+
setHasStableIds(true)
35+
}
36+
37+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ContactViewHolder {
38+
return ContactViewHolder(ItemContactBinding.inflate(LayoutInflater.from(parent.context), parent, false))
39+
}
40+
41+
override fun getItemCount() = messagesToRecipients.count()
42+
43+
override fun onBindViewHolder(holder: ContactViewHolder, position: Int) = with(holder.binding) {
44+
contactDetails.setCorrespondent(messagesToRecipients[position].second)
45+
root.setOnClickListener { onClickListener(messagesToRecipients[position].first) }
46+
}
47+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Infomaniak Mail - Android
3+
* Copyright (C) 2024 Infomaniak Network SA
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.infomaniak.mail.ui.main.thread.actions
19+
20+
import android.os.Bundle
21+
import android.view.LayoutInflater
22+
import android.view.View
23+
import android.view.ViewGroup
24+
import androidx.fragment.app.activityViewModels
25+
import androidx.navigation.fragment.navArgs
26+
import com.infomaniak.lib.core.utils.safeBinding
27+
import com.infomaniak.mail.MatomoMail.trackBottomSheetThreadActionsEvent
28+
import com.infomaniak.mail.databinding.BottomSheetUserToBlockBinding
29+
import com.infomaniak.mail.ui.MainViewModel
30+
31+
class UserToBlockBottomSheetDialog : ActionsBottomSheetDialog() {
32+
33+
private var binding: BottomSheetUserToBlockBinding by safeBinding()
34+
private val navigationArgs: UserToBlockBottomSheetDialogArgs by navArgs()
35+
override val mainViewModel: MainViewModel by activityViewModels()
36+
37+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
38+
return BottomSheetUserToBlockBinding.inflate(inflater, container, false).also { binding = it }.root
39+
}
40+
41+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) = with(navigationArgs) {
42+
super.onViewCreated(view, savedInstanceState)
43+
mainViewModel.getMessagesFromUniqueExpeditors(threadUid).observe(viewLifecycleOwner) { messages ->
44+
messages?.let {
45+
binding.recipients.adapter = UserToBlockAdapter(messages) { message ->
46+
trackBottomSheetThreadActionsEvent("blockUser")
47+
mainViewModel.blockUser(message)
48+
dismiss()
49+
}
50+
}
51+
}
52+
}
53+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Infomaniak Mail - Android
3+
~ Copyright (C) 2024 Infomaniak Network SA
4+
~
5+
~ This program is free software: you can redistribute it and/or modify
6+
~ it under the terms of the GNU General Public License as published by
7+
~ the Free Software Foundation, either version 3 of the License, or
8+
~ (at your option) any later version.
9+
~
10+
~ This program is distributed in the hope that it will be useful,
11+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
~ GNU General Public License for more details.
14+
~
15+
~ You should have received a copy of the GNU General Public License
16+
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
-->
18+
<com.infomaniak.mail.views.BottomSheetScaffoldingView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
xmlns:tools="http://schemas.android.com/tools"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
app:title="@string/blockAnExpeditorTitle"
24+
app:useDefaultLayout="false"
25+
tools:context=".ui.main.thread.actions.UserToBlockBottomSheetDialog">
26+
27+
<androidx.recyclerview.widget.RecyclerView
28+
android:id="@+id/recipients"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
32+
tools:itemCount="10"
33+
tools:listitem="@layout/item_contact" />
34+
35+
</com.infomaniak.mail.views.BottomSheetScaffoldingView>

app/src/main/res/navigation/main_navigation.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@
168168
app:argType="string" />
169169
</dialog>
170170

171+
<dialog
172+
android:id="@+id/userToBlockBottomSheetDialog"
173+
android:name="com.infomaniak.mail.ui.main.thread.actions.UserToBlockBottomSheetDialog"
174+
android:label="UserToBlockBottomSheetDialog"
175+
tools:layout="@layout/bottom_sheet_user_to_block">
176+
<argument
177+
android:name="threadUid"
178+
app:argType="string" />
179+
</dialog>
180+
171181
<fragment
172182
android:id="@+id/switchUserFragment"
173183
android:name="com.infomaniak.mail.ui.main.user.SwitchUserFragment"

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</plurals>
105105
<string name="attendeesListTitle">Liste der Teilnehmer (%d)</string>
106106
<string name="bccTitle">Bcc:</string>
107+
<string name="blockAnExpeditorTitle">Einen Absender blockieren</string>
107108
<plurals name="blockedPasswordTitle">
108109
<item quantity="one">Passwort blockiert</item>
109110
<item quantity="other">Blockierte Passwörter</item>

app/src/main/res/values-es/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</plurals>
105105
<string name="attendeesListTitle">Lista de asistentes (%d)</string>
106106
<string name="bccTitle">CCO:</string>
107+
<string name="blockAnExpeditorTitle">Bloquear un remitente</string>
107108
<plurals name="blockedPasswordTitle">
108109
<item quantity="one">Contraseña bloqueada</item>
109110
<item quantity="other">Contraseñas bloqueadas</item>

app/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
</plurals>
106106
<string name="attendeesListTitle">Liste des participants (%d)</string>
107107
<string name="bccTitle">Cci :</string>
108+
<string name="blockAnExpeditorTitle">Bloquer un expéditeur</string>
108109
<plurals name="blockedPasswordTitle">
109110
<item quantity="one">Mot de passe bloqué</item>
110111
<item quantity="other">Mots de passe bloqués</item>

app/src/main/res/values-it/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</plurals>
105105
<string name="attendeesListTitle">Elenco dei partecipanti (%d)</string>
106106
<string name="bccTitle">Bcc:</string>
107+
<string name="blockAnExpeditorTitle">Bloccare un mittente</string>
107108
<plurals name="blockedPasswordTitle">
108109
<item quantity="one">Password bloccata</item>
109110
<item quantity="other">Password bloccate</item>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
</plurals>
111111
<string name="attendeesListTitle">List of attendees (%d)</string>
112112
<string name="bccTitle">Bcc:</string>
113+
<string name="blockAnExpeditorTitle">Block a sender</string>
113114
<plurals name="blockedPasswordTitle">
114115
<item quantity="one">Blocked password</item>
115116
<item quantity="other">Blocked passwords</item>

0 commit comments

Comments
 (0)