Repository: thunderbird/thunderbird-android
File: legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt (Kotlin)

Code before:
            folderServerId: String,
            total: Int,
            completed: Int,
        ) {
            synchronized(lock) {
                folderCompleted = 0
                folderTotal = 0
            }

            informUserOfStatus()
        }

        override fun synchronizeMailboxProgress(account: LegacyAccountDto, folderId: Long, completed: Int, total: Int) {
            synchronized(lock) {
                folderCompleted = completed
                folderTotal = total
            }

            informUserOfStatus()
        }

        override fun synchronizeMailboxFinished(account: LegacyAccountDto, folderId: Long) {
            if (updateForMe(account, folderId)) {
                handler.progress(false)
                handler.folderLoading(folderId, false)
            }
        }

        override fun synchronizeMailboxFailed(account: LegacyAccountDto, folderId: Long, message: String) {
            if (updateForMe(account, folderId)) {
                handler.progress(false)
                handler.folderLoading(folderId, false)
            }
        }

        override fun checkMailFinished(context: Context?, account: LegacyAccountDto?) {
            handler.progress(false)
        }

        private fun updateForMe(account: LegacyAccountDto?, folderId: Long): Boolean {
            if (account == null || account.uuid !in accountUuids) return false

            val folderIds = localSearch.folderIds
            return folderIds.isEmpty() || folderId in folderIds
        }

        fun getFolderCompleted(): Int {
            synchronized(lock) {
                return folderCompleted
            }
        }

Review comment (refactor):
If adding these functions results in the "Too many functions" warning, do all of these functions need to be in this file? MessageListFragment has become a catch-all, and it may be better if functions that don't rely on anything directly in the messagelistfragment are placed in a more suitable location. At a minimum this filter could probably go in a helper or util file

Code after:
            }
        }
    }

    private fun notifyItemChanged(item: MessageListItem) {
        val position = adapter.getPosition(item) ?: return
        adapter.notifyItemChanged(position)
    }

    private val swipeActionSupportProvider = SwipeActionSupportProvider { item, action ->
        when (action) {
            SwipeAction.None -> false
            SwipeAction.ToggleSelection -> true
            SwipeAction.ToggleRead -> !isOutbox
            SwipeAction.ToggleStar -> !isOutbox
            SwipeAction.Archive, SwipeAction.ArchiveDisabled, SwipeAction.ArchiveSetupArchiveFolder -> {
                !isOutbox && item.folderId != item.account.archiveFolderId
            }

            SwipeAction.Delete -> true
            SwipeAction.Move -> !isOutbox && messagingController.isMoveCapable(item.account.id)
            SwipeAction.Spam -> !isOutbox && item.account.hasSpamFolder() && item.folderId != item.account.spamFolderId
        }
    }

    override fun filterInAppNotificationEvents(event: InAppNotificationEvent): Boolean {
        val accountUuid = event.notification.accountUuid
        return accountUuid != null && accountUuid in accountUuids
    }

    override fun onNotificationActionClicked(action: NotificationAction) = onNotificationActionClick(action)

    override fun onNotificationActionClick(action: NotificationAction) {
        when (action) {
            is NotificationAction.UpdateIncomingServerSettings ->
                FeatureLauncherActivity.launch(
                    context = requireContext(),
                    target = FeatureLauncherTarget.AccountEditIncomingSettings(action.accountUuid),
                )

            is NotificationAction.UpdateOutgoingServerSettings ->
                FeatureLauncherActivity.launch(
                    context = requireContext(),
                    target = FeatureLauncherTarget.AccountEditOutgoingSettings(action.accountUuid),
                )

            is NotificationAction.OpenNotificationCentre ->
                errorNotificationsDialogFragmentFactory.show(fragmentManager = childFragmentManager)

            else -> Unit
        }