-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move each MenuDrawerAdapter's items binding to its own file
- Loading branch information
1 parent
e49d41c
commit 9c9dbcb
Showing
11 changed files
with
720 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
330 changes: 74 additions & 256 deletions
330
app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/MenuDrawerAdapter.kt
Large diffs are not rendered by default.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/DividerItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.menuDrawer.items | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.viewbinding.ViewBinding | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.databinding.ItemMenuDrawerDividerBinding | ||
|
||
object DividerItem { | ||
|
||
@Suppress("MayBeConstant") | ||
val viewType = R.layout.item_menu_drawer_divider | ||
|
||
fun binding(inflater: LayoutInflater, parent: ViewGroup): ViewBinding { | ||
return ItemMenuDrawerDividerBinding.inflate(inflater, parent, false) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/EmptyFoldersItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.menuDrawer.items | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.viewbinding.ViewBinding | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.databinding.ItemMenuDrawerEmptyCustomFoldersBinding | ||
|
||
object EmptyFoldersItem { | ||
|
||
@Suppress("MayBeConstant") | ||
val viewType = R.layout.item_menu_drawer_empty_custom_folders | ||
|
||
fun binding(inflater: LayoutInflater, parent: ViewGroup): ViewBinding { | ||
return ItemMenuDrawerEmptyCustomFoldersBinding.inflate(inflater, parent, false) | ||
} | ||
} |
179 changes: 179 additions & 0 deletions
179
app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/FolderItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* 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.menuDrawer.items | ||
|
||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.annotation.DrawableRes | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.viewbinding.ViewBinding | ||
import com.infomaniak.mail.MatomoMail.trackMenuDrawerEvent | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.data.models.Folder | ||
import com.infomaniak.mail.databinding.ItemMenuDrawerFolderBinding | ||
import com.infomaniak.mail.utils.UnreadDisplay | ||
import com.infomaniak.mail.views.itemViews.* | ||
import kotlin.math.min | ||
|
||
object FolderItem { | ||
|
||
@Suppress("MayBeConstant") | ||
val viewType = R.layout.item_menu_drawer_folder | ||
|
||
fun binding(inflater: LayoutInflater, parent: ViewGroup): ViewBinding { | ||
return ItemMenuDrawerFolderBinding.inflate(inflater, parent, false) | ||
} | ||
|
||
fun display( | ||
item: Any, | ||
binding: ViewBinding, | ||
currentFolderId: String?, | ||
hasCollapsableDefaultFolder: Boolean, | ||
hasCollapsableCustomFolder: Boolean, | ||
onFolderClicked: (folderId: String) -> Unit, | ||
onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit, | ||
) { | ||
item as Folder | ||
binding as ItemMenuDrawerFolderBinding | ||
|
||
Log.d("Bind", "Bind Folder : ${item.name}") | ||
binding.displayFolder( | ||
item, | ||
currentFolderId, | ||
hasCollapsableDefaultFolder, | ||
hasCollapsableCustomFolder, | ||
onFolderClicked, | ||
onCollapseChildrenClicked, | ||
) | ||
} | ||
|
||
fun displayWithPayload( | ||
item: Any, | ||
binding: ViewBinding, | ||
currentFolderId: String?, | ||
hasCollapsableDefaultFolder: Boolean, | ||
hasCollapsableCustomFolder: Boolean, | ||
onFolderClicked: (folderId: String) -> Unit, | ||
onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit, | ||
) { | ||
item as Folder | ||
binding as ItemMenuDrawerFolderBinding | ||
|
||
Log.d("Bind", "Bind Custom folders because of collapse change = ${item.name}") | ||
binding.displayFolder( | ||
item, | ||
currentFolderId, | ||
hasCollapsableDefaultFolder, | ||
hasCollapsableCustomFolder, | ||
onFolderClicked, | ||
onCollapseChildrenClicked, | ||
) | ||
} | ||
|
||
private fun ItemMenuDrawerFolderBinding.displayFolder( | ||
folder: Folder, | ||
currentFolderId: String?, | ||
hasCollapsableDefaultFolder: Boolean, | ||
hasCollapsableCustomFolder: Boolean, | ||
onFolderClicked: (folderId: String) -> Unit, | ||
onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit, | ||
) = with(root) { | ||
|
||
val unread = when (folder.role) { | ||
Folder.FolderRole.DRAFT -> UnreadDisplay(folder.threads.count()) | ||
Folder.FolderRole.SENT, Folder.FolderRole.TRASH -> UnreadDisplay(0) | ||
else -> folder.unreadCountDisplay | ||
} | ||
|
||
folder.role?.let { | ||
setFolderUi( | ||
folder = folder, | ||
iconId = it.folderIconRes, | ||
unread = unread, | ||
currentFolderId = currentFolderId, | ||
hasCollapsableDefaultFolder = hasCollapsableDefaultFolder, | ||
hasCollapsableCustomFolder = hasCollapsableCustomFolder, | ||
onFolderClicked = onFolderClicked, | ||
onCollapseChildrenClicked = onCollapseChildrenClicked, | ||
trackerName = it.matomoValue, | ||
) | ||
} ?: run { | ||
val indentLevel = folder.path.split(folder.separator).size - 1 | ||
setFolderUi( | ||
folder = folder, | ||
iconId = if (folder.isFavorite) R.drawable.ic_folder_star else R.drawable.ic_folder, | ||
unread = unread, | ||
currentFolderId = currentFolderId, | ||
hasCollapsableDefaultFolder = hasCollapsableDefaultFolder, | ||
hasCollapsableCustomFolder = hasCollapsableCustomFolder, | ||
onFolderClicked = onFolderClicked, | ||
onCollapseChildrenClicked = onCollapseChildrenClicked, | ||
trackerName = "customFolder", | ||
trackerValue = indentLevel.toFloat(), | ||
folderIndent = min(indentLevel, Folder.MAX_SUB_FOLDERS_INDENT), | ||
) | ||
} | ||
} | ||
|
||
private fun SelectableItemView.setFolderUi( | ||
folder: Folder, | ||
@DrawableRes iconId: Int, | ||
unread: UnreadDisplay?, | ||
currentFolderId: String?, | ||
hasCollapsableDefaultFolder: Boolean, | ||
hasCollapsableCustomFolder: Boolean, | ||
onFolderClicked: (folderId: String) -> Unit, | ||
onCollapseChildrenClicked: (folderId: String, shouldCollapse: Boolean) -> Unit, | ||
trackerName: String, | ||
trackerValue: Float? = null, | ||
folderIndent: Int = 0, | ||
) { | ||
val folderName = folder.getLocalizedName(context) | ||
|
||
text = folderName | ||
icon = AppCompatResources.getDrawable(context, iconId) | ||
setSelectedState(folder.id == currentFolderId) | ||
|
||
when (this) { | ||
is SelectableFolderItemView -> setIndent(folderIndent) | ||
is UnreadFolderItemView -> { | ||
initOnCollapsableClickListener { onCollapseChildrenClicked(folder.id, isCollapsed) } | ||
isPastilleDisplayed = unread?.shouldDisplayPastille ?: false | ||
unreadCount = unread?.count ?: 0 | ||
isCollapsed = folder.isCollapsed | ||
canBeCollapsed = folder.canBeCollapsed | ||
val hasCollapsableFolder = if (folder.role == null) hasCollapsableCustomFolder else hasCollapsableDefaultFolder | ||
setIndent( | ||
indent = folderIndent, | ||
hasCollapsableFolder = hasCollapsableFolder, | ||
canBeCollapsed = canBeCollapsed, | ||
) | ||
setCollapsingButtonContentDescription(folderName) | ||
} | ||
is SelectableMailboxItemView, is UnreadItemView -> { | ||
error("`${this::class.simpleName}` cannot exists here. Only Folder classes are allowed") | ||
} | ||
} | ||
|
||
setOnClickListener { | ||
context.trackMenuDrawerEvent(trackerName, value = trackerValue) | ||
onFolderClicked.invoke(folder.id) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/infomaniak/mail/ui/main/menuDrawer/items/FoldersHeaderItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.menuDrawer.items | ||
|
||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.viewbinding.ViewBinding | ||
import com.infomaniak.mail.R | ||
import com.infomaniak.mail.databinding.ItemMenuDrawerCustomFoldersHeaderBinding | ||
|
||
object FoldersHeaderItem { | ||
|
||
@Suppress("MayBeConstant") | ||
val viewType = R.layout.view_menu_drawer_dropdown | ||
|
||
fun binding(inflater: LayoutInflater, parent: ViewGroup): ViewBinding { | ||
return ItemMenuDrawerCustomFoldersHeaderBinding.inflate(inflater, parent, false) | ||
} | ||
|
||
fun display( | ||
binding: ViewBinding, | ||
onCustomFoldersHeaderClicked: (Boolean) -> Unit, | ||
onCreateFolderClicked: () -> Unit, | ||
) { | ||
binding as ItemMenuDrawerCustomFoldersHeaderBinding | ||
|
||
Log.d("Bind", "Bind Custom Folders header") | ||
binding.displayCustomFoldersHeader(onCustomFoldersHeaderClicked, onCreateFolderClicked) | ||
} | ||
|
||
private fun ItemMenuDrawerCustomFoldersHeaderBinding.displayCustomFoldersHeader( | ||
onCustomFoldersHeaderClicked: (Boolean) -> Unit, | ||
onCreateFolderClicked: () -> Unit, | ||
) = with(root) { | ||
setOnClickListener { onCustomFoldersHeaderClicked(isCollapsed) } | ||
setOnActionClickListener { onCreateFolderClicked() } | ||
} | ||
} |
Oops, something went wrong.