Skip to content

Commit 107e835

Browse files
Make MenuDrawer advanced actions items in the RecyclerView
1 parent 4ba1b77 commit 107e835

12 files changed

+316
-152
lines changed

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/MenuDrawerAdapter.kt

+121-59
Large diffs are not rendered by default.

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/MenuDrawerAdapterCallbacks.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
package com.infomaniak.mail.ui.main.menuDrawer
1919

2020
import com.infomaniak.mail.data.models.mailbox.Mailbox
21+
import com.infomaniak.mail.ui.main.menuDrawer.items.ActionViewHolder.MenuDrawerAction.ActionType
2122

2223
interface MenuDrawerAdapterCallbacks {
2324

2425
var onMailboxesHeaderClicked: () -> Unit
2526

2627
var onValidMailboxClicked: (Int) -> Unit
27-
2828
var onLockedMailboxClicked: (String) -> Unit
2929
var onInvalidPasswordMailboxClicked: (Mailbox) -> Unit
3030

31+
var onFoldersHeaderClicked: (Boolean) -> Unit
32+
var onCreateFolderClicked: () -> Unit
33+
3134
var onFolderClicked: (folderId: String) -> Unit
3235
var onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit
3336

34-
var onCustomFoldersHeaderClicked: (Boolean) -> Unit
35-
var onCreateFolderClicked: () -> Unit
37+
var onActionsHeaderClicked: () -> Unit
38+
var onActionClicked: (ActionType) -> Unit
3639

37-
var onSyncAutoConfigClicked: () -> Unit
38-
var onImportMailsClicked: () -> Unit
39-
var onRestoreMailsClicked: () -> Unit
4040
var onFeedbackClicked: () -> Unit
4141
var onHelpClicked: () -> Unit
4242
var onAppVersionClicked: () -> Unit

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/MenuDrawerFragment.kt

+25-8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.infomaniak.lib.bugtracker.BugTrackerActivityArgs
3636
import com.infomaniak.lib.core.utils.UtilsUi.openUrl
3737
import com.infomaniak.lib.core.utils.safeNavigate
3838
import com.infomaniak.mail.BuildConfig
39+
import com.infomaniak.mail.MatomoMail.toFloat
3940
import com.infomaniak.mail.MatomoMail.trackCreateFolderEvent
4041
import com.infomaniak.mail.MatomoMail.trackMenuDrawerEvent
4142
import com.infomaniak.mail.MatomoMail.trackScreen
@@ -52,6 +53,7 @@ import com.infomaniak.mail.ui.alertDialogs.CreateFolderDialog
5253
import com.infomaniak.mail.ui.bottomSheetDialogs.LockedMailboxBottomSheetDialogArgs
5354
import com.infomaniak.mail.ui.main.InvalidPasswordFragmentArgs
5455
import com.infomaniak.mail.ui.main.folder.ThreadListFragmentDirections
56+
import com.infomaniak.mail.ui.main.menuDrawer.items.ActionViewHolder.MenuDrawerAction.ActionType
5557
import com.infomaniak.mail.utils.AccountUtils
5658
import com.infomaniak.mail.utils.ConfettiUtils
5759
import com.infomaniak.mail.utils.ConfettiUtils.ConfettiType.INFOMANIAK
@@ -125,13 +127,12 @@ class MenuDrawerFragment : Fragment() {
125127
override var onValidMailboxClicked: (Int) -> Unit = ::onValidMailboxClicked
126128
override var onLockedMailboxClicked: (String) -> Unit = ::onLockedMailboxClicked
127129
override var onInvalidPasswordMailboxClicked: (Mailbox) -> Unit = ::onInvalidPasswordMailboxClicked
130+
override var onFoldersHeaderClicked: (Boolean) -> Unit = ::onFoldersHeaderClicked
131+
override var onCreateFolderClicked: () -> Unit = ::onCreateFolderClicked
128132
override var onFolderClicked: (folderId: String) -> Unit = ::onFolderSelected
129133
override var onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit = ::onFolderCollapsed
130-
override var onCustomFoldersHeaderClicked: (Boolean) -> Unit = ::onCustomFoldersHeaderClicked
131-
override var onCreateFolderClicked: () -> Unit = ::onCreateFolderClicked
132-
override var onSyncAutoConfigClicked: () -> Unit = ::onSyncAutoConfigClicked
133-
override var onImportMailsClicked: () -> Unit = ::onImportMailsClicked
134-
override var onRestoreMailsClicked: () -> Unit = ::onRestoreMailsClicked
134+
override var onActionsHeaderClicked: () -> Unit = ::onActionsHeaderClicked
135+
override var onActionClicked: (ActionType) -> Unit = ::onActionClicked
135136
override var onFeedbackClicked: () -> Unit = ::onFeedbackClicked
136137
override var onHelpClicked: () -> Unit = ::onHelpClicked
137138
override var onAppVersionClicked: () -> Unit = ::onAppVersionClicked
@@ -178,7 +179,7 @@ class MenuDrawerFragment : Fragment() {
178179
)
179180
}
180181

181-
private fun onCustomFoldersHeaderClicked(isCollapsed: Boolean) {
182+
private fun onFoldersHeaderClicked(isCollapsed: Boolean) {
182183
trackMenuDrawerEvent("customFolders", !isCollapsed)
183184
menuDrawerViewModel.areCustomFoldersExpanded.value = !isCollapsed
184185
}
@@ -197,6 +198,19 @@ class MenuDrawerFragment : Fragment() {
197198
menuDrawerViewModel.toggleFolderCollapsingState(folderId, shouldCollapse)
198199
}
199200

201+
private fun onActionsHeaderClicked() {
202+
context?.trackMenuDrawerEvent("advancedActions", value = (!menuDrawerViewModel.areActionsExpanded.value!!).toFloat())
203+
menuDrawerViewModel.toggleActionsCollapsingState()
204+
}
205+
206+
private fun onActionClicked(type: ActionType) {
207+
when (type) {
208+
ActionType.SYNC_AUTO_CONFIG -> onSyncAutoConfigClicked()
209+
ActionType.IMPORT_MAILS -> onImportMailsClicked()
210+
ActionType.RESTORE_MAILS -> onRestoreMailsClicked()
211+
}
212+
}
213+
200214
private fun onSyncAutoConfigClicked() {
201215
trackSyncAutoConfigEvent("openFromMenuDrawer")
202216
launchSyncAutoConfigActivityForResult()
@@ -258,6 +272,7 @@ class MenuDrawerFragment : Fragment() {
258272
menuDrawerViewModel.areMailboxesExpanded,
259273
currentFoldersLive,
260274
menuDrawerViewModel.areCustomFoldersExpanded,
275+
menuDrawerViewModel.areActionsExpanded,
261276
currentPermissionsLive,
262277
currentQuotasLive,
263278
constructor = {
@@ -267,8 +282,9 @@ class MenuDrawerFragment : Fragment() {
267282
it[1] as Boolean,
268283
it[2] as List<Folder>,
269284
it[3] as Boolean,
270-
it[4] as MailboxPermissions?,
271-
it[5] as Quotas?,
285+
it[4] as Boolean,
286+
it[5] as MailboxPermissions?,
287+
it[6] as Quotas?,
272288
)
273289
}
274290
)
@@ -309,6 +325,7 @@ class MenuDrawerFragment : Fragment() {
309325
val areMailboxesExpanded: Boolean,
310326
val allFolders: List<Folder>,
311327
val areCustomFoldersExpanded: Boolean,
328+
val areActionsExpanded: Boolean,
312329
val permissions: MailboxPermissions?,
313330
val quotas: Quotas?,
314331
)

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/MenuDrawerViewModel.kt

+5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ class MenuDrawerViewModel @Inject constructor(
3939

4040
val areMailboxesExpanded = MutableLiveData(false)
4141
val areCustomFoldersExpanded = MutableLiveData(true)
42+
val areActionsExpanded = MutableLiveData(false)
4243

4344
fun toggleFolderCollapsingState(folderId: String, shouldCollapse: Boolean) = viewModelScope.launch(ioCoroutineContext) {
4445
FolderController.updateFolderAndChildren(folderId, mailboxContentRealm()) {
4546
if (it.isRoot) it.isCollapsed = shouldCollapse else it.isHidden = shouldCollapse
4647
}
4748
}
49+
50+
fun toggleActionsCollapsingState() {
51+
areActionsExpanded.value = !areActionsExpanded.value!!
52+
}
4853
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.menuDrawer.items
19+
20+
import android.view.LayoutInflater
21+
import android.view.ViewGroup
22+
import androidx.annotation.DrawableRes
23+
import androidx.annotation.StringRes
24+
import androidx.appcompat.content.res.AppCompatResources
25+
import com.infomaniak.lib.core.utils.SentryLog
26+
import com.infomaniak.mail.databinding.ItemMenuDrawerActionBinding
27+
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerAdapter.MenuDrawerViewHolder
28+
import com.infomaniak.mail.ui.main.menuDrawer.items.ActionViewHolder.MenuDrawerAction.ActionType
29+
30+
class ActionViewHolder(
31+
inflater: LayoutInflater,
32+
parent: ViewGroup,
33+
) : MenuDrawerViewHolder(ItemMenuDrawerActionBinding.inflate(inflater, parent, false)) {
34+
35+
fun displayAction(
36+
action: MenuDrawerAction,
37+
binding: ItemMenuDrawerActionBinding,
38+
onActionClicked: (ActionType) -> Unit,
39+
) {
40+
SentryLog.d("Bind", "Bind Action : ${action.type.name}")
41+
42+
binding.root.apply {
43+
icon = AppCompatResources.getDrawable(context, action.icon)
44+
text = context.getString(action.text)
45+
maxLines = action.maxLines
46+
setOnClickListener { onActionClicked(action.type) }
47+
}
48+
}
49+
50+
data class MenuDrawerAction(
51+
val type: ActionType,
52+
@DrawableRes val icon: Int,
53+
@StringRes val text: Int,
54+
val maxLines: Int,
55+
) {
56+
57+
enum class ActionType {
58+
SYNC_AUTO_CONFIG,
59+
IMPORT_MAILS,
60+
RESTORE_MAILS,
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.menuDrawer.items
19+
20+
import android.view.LayoutInflater
21+
import android.view.ViewGroup
22+
import com.infomaniak.lib.core.utils.SentryLog
23+
import com.infomaniak.mail.databinding.ItemMenuDrawerActionsHeaderBinding
24+
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerAdapter.MenuDrawerViewHolder
25+
26+
class ActionsHeaderViewHolder(
27+
inflater: LayoutInflater,
28+
parent: ViewGroup,
29+
) : MenuDrawerViewHolder(ItemMenuDrawerActionsHeaderBinding.inflate(inflater, parent, false)) {
30+
31+
fun displayActionsHeader(binding: ItemMenuDrawerActionsHeaderBinding, onActionsHeaderClicked: () -> Unit) {
32+
SentryLog.d("Bind", "Bind Actions header")
33+
binding.root.setOnClickListener { onActionsHeaderClicked() }
34+
}
35+
}

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/EmptyFoldersItem.kt renamed to app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/EmptyFoldersViewHolder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import android.view.ViewGroup
2222
import com.infomaniak.mail.databinding.ItemMenuDrawerEmptyCustomFoldersBinding
2323
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerAdapter.MenuDrawerViewHolder
2424

25-
class EmptyFoldersItem(
25+
class EmptyFoldersViewHolder(
2626
inflater: LayoutInflater,
2727
parent: ViewGroup,
2828
) : MenuDrawerViewHolder(ItemMenuDrawerEmptyCustomFoldersBinding.inflate(inflater, parent, false))

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/FoldersHeaderItem.kt renamed to app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/FoldersHeaderViewHolder.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ import com.infomaniak.lib.core.utils.SentryLog
2323
import com.infomaniak.mail.databinding.ItemMenuDrawerCustomFoldersHeaderBinding
2424
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerAdapter.MenuDrawerViewHolder
2525

26-
class FoldersHeaderItem(
26+
class FoldersHeaderViewHolder(
2727
inflater: LayoutInflater,
2828
parent: ViewGroup,
2929
) : MenuDrawerViewHolder(ItemMenuDrawerCustomFoldersHeaderBinding.inflate(inflater, parent, false)) {
3030

31-
fun displayCustomFoldersHeader(
31+
fun displayFoldersHeader(
3232
binding: ItemMenuDrawerCustomFoldersHeaderBinding,
33-
onCustomFoldersHeaderClicked: (Boolean) -> Unit,
33+
onFoldersHeaderClicked: (Boolean) -> Unit,
3434
onCreateFolderClicked: () -> Unit,
3535
) = with(binding.root) {
3636
SentryLog.d("Bind", "Bind Custom Folders header")
3737

38-
setOnClickListener { onCustomFoldersHeaderClicked(isCollapsed) }
38+
setOnClickListener { onFoldersHeaderClicked(isCollapsed) }
3939
setOnActionClickListener { onCreateFolderClicked() }
4040
}
4141
}

app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/FooterViewHolder.kt

+1-26
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ package com.infomaniak.mail.ui.main.menuDrawer.items
1919

2020
import android.view.LayoutInflater
2121
import android.view.ViewGroup
22-
import androidx.core.view.isGone
2322
import androidx.core.view.isVisible
2423
import com.infomaniak.lib.core.utils.SentryLog
2524
import com.infomaniak.lib.core.utils.context
2625
import com.infomaniak.mail.BuildConfig
27-
import com.infomaniak.mail.MatomoMail.toFloat
28-
import com.infomaniak.mail.MatomoMail.trackMenuDrawerEvent
2926
import com.infomaniak.mail.data.models.Quotas
30-
import com.infomaniak.mail.data.models.mailbox.MailboxPermissions
3127
import com.infomaniak.mail.databinding.ItemMenuDrawerFooterBinding
3228
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerAdapter.MenuDrawerViewHolder
3329

@@ -39,33 +35,12 @@ class FooterViewHolder(
3935
fun displayFooter(
4036
footer: MenuDrawerFooter,
4137
binding: ItemMenuDrawerFooterBinding,
42-
onSyncAutoConfigClicked: () -> Unit,
43-
onImportMailsClicked: () -> Unit,
44-
onRestoreMailsClicked: () -> Unit,
4538
onFeedbackClicked: () -> Unit,
4639
onHelpClicked: () -> Unit,
4740
onAppVersionClicked: () -> Unit,
4841
) = with(binding) {
4942
SentryLog.d("Bind", "Bind Footer")
5043

51-
// Actions header
52-
advancedActions.setOnClickListener {
53-
context.trackMenuDrawerEvent("advancedActions", value = (!advancedActions.isCollapsed).toFloat())
54-
advancedActionsLayout.isGone = advancedActions.isCollapsed
55-
}
56-
57-
// Calendar & contacts sync
58-
syncAutoConfig.setOnClickListener { onSyncAutoConfigClicked() }
59-
60-
// Import mails
61-
importMails.setOnClickListener { onImportMailsClicked() }
62-
63-
// Restore mails
64-
restoreMails.apply {
65-
isVisible = footer.permissions?.canRestoreEmails == true
66-
setOnClickListener { onRestoreMailsClicked() }
67-
}
68-
6944
// Feedback
7045
feedback.setOnClickListener { onFeedbackClicked() }
7146

@@ -88,5 +63,5 @@ class FooterViewHolder(
8863
}
8964
}
9065

91-
data class MenuDrawerFooter(val permissions: MailboxPermissions?, val quotas: Quotas?)
66+
data class MenuDrawerFooter(val quotas: Quotas?)
9267
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.itemViews.SimpleMenuDrawerItemView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
tools:icon="@drawable/ic_synchronize"
23+
tools:maxLines="2"
24+
tools:text="@string/syncCalendarsAndContactsTitle" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.ui.main.menuDrawer.MenuDrawerDropdownView xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:id="@+id/advancedActions"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
app:collapsedByDefault="true"
24+
app:title="@string/menuDrawerAdvancedActions" />

0 commit comments

Comments
 (0)