Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Jun 7, 2024
1 parent f1b3a22 commit 7f9994f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ class FolderController @Inject constructor(
) {

//region Get data
fun getCustomFolders(): RealmResults<Folder> {
return getCustomFoldersQuery(mailboxContentRealm()).find()
}

fun getMoveFolders(): RealmResults<Folder> {
return getMoveFoldersQuery(mailboxContentRealm()).find()
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import com.infomaniak.mail.data.models.draft.Draft.DraftAction
import com.infomaniak.mail.databinding.ActivityMainBinding
import com.infomaniak.mail.firebase.RegisterFirebaseBroadcastReceiver
import com.infomaniak.mail.ui.alertDialogs.DescriptionAlertDialog
import com.infomaniak.mail.ui.alertDialogs.TitleAlertDialog
import com.infomaniak.mail.ui.main.SnackbarManager
import com.infomaniak.mail.ui.main.folder.TwoPaneFragment
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerFragment
Expand Down Expand Up @@ -139,9 +138,6 @@ class MainActivity : BaseActivity() {
@Inject
lateinit var descriptionDialog: DescriptionAlertDialog

@Inject
lateinit var titleDialog: TitleAlertDialog

@Inject
lateinit var permissionUtils: PermissionUtils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface MailboxListFragment {
)
}

fun Fragment.onValidMailboxClicked(mailboxId: Int) {
lifecycleScope.launch { AccountUtils.switchToMailbox(mailboxId) }
fun Fragment.onValidMailboxClicked(mailboxId: Int) = lifecycleScope.launch {
AccountUtils.switchToMailbox(mailboxId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ class ThreadListAdapter @Inject constructor(

override fun onBindViewHolder(item: Any, viewHolder: ThreadListViewHolder, position: Int) = with(viewHolder.binding) {
when (getItemViewType(position)) {
DisplayType.THREAD.layout ->{
DisplayType.THREAD.layout -> {
(this as CardviewThreadItemBinding).displayThread(item as Thread, position)
}
DisplayType.DATE_SEPARATOR.layout ->{
DisplayType.DATE_SEPARATOR.layout -> {
(this as ItemThreadDateSeparatorBinding).displayDateSeparator(item as String)
}
DisplayType.FLUSH_FOLDER_BUTTON.layout ->{
DisplayType.FLUSH_FOLDER_BUTTON.layout -> {
(this as ItemBannerWithActionViewBinding).displayFlushFolderButton(item as FolderRole)
}
DisplayType.LOAD_MORE_BUTTON.layout ->{
DisplayType.LOAD_MORE_BUTTON.layout -> {
(this as ItemThreadLoadMoreButtonBinding).displayLoadMoreButton()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class FolderAdapter @Inject constructor(
return this
}

override fun getItemCount(): Int = runCatchingRealm { items.size }.getOrDefault(0)

override fun getItemViewType(position: Int): Int {
return if (isInMenuDrawer) DisplayType.MENU_DRAWER.layout else DisplayType.SELECTABLE_FOLDER.layout
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FolderViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = if (viewType == DisplayType.SELECTABLE_FOLDER.layout) {
Expand Down Expand Up @@ -107,12 +113,6 @@ class FolderAdapter @Inject constructor(
}
}

override fun getItemViewType(position: Int): Int {
return if (isInMenuDrawer) DisplayType.MENU_DRAWER.layout else DisplayType.SELECTABLE_FOLDER.layout
}

override fun getItemCount(): Int = runCatchingRealm { items.size }.getOrDefault(0)

private fun UnreadFolderItemView.displayMenuDrawerFolder(folder: Folder) {

val unread = when (folder.role) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ fun List<Folder>.getMenuFolders(): Pair<List<Folder>, List<Folder>> {
}
}

fun List<Folder>.getDefaultMenuFolders(): List<Folder> {
return sortedBy { it.role?.order }.flattenFolderChildren()
}
fun List<Folder>.getDefaultMenuFolders(): List<Folder> = sortedBy { it.role?.order }.flattenFolderChildren()

fun List<Folder>.getCustomMenuFolders(dismissHiddenChildren: Boolean = false): List<Folder> {
return flattenFolderChildren(dismissHiddenChildren)
Expand Down

0 comments on commit 7f9994f

Please sign in to comment.