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

Code before:
    private fun onCopy(messages: List<MessageReference>) {
        if (!checkCopyOrMovePossible(messages, FolderOperation.COPY)) return

        val folderId = when {
            isThreadDisplay -> messages.first().folderId
            isSingleFolderMode -> currentFolder!!.databaseId
            else -> null
        }

        displayFolderChoice(
            operation = FolderOperation.COPY,
            sourceFolderId = folderId,
            accountUuid = messages.first().accountUuid,
            lastSelectedFolderId = null,
            messages = messages,
        )
    }

    private fun displayFolderChoice(
        operation: FolderOperation,
        sourceFolderId: Long?,
        accountUuid: String,
        lastSelectedFolderId: Long?,
        messages: List<MessageReference>,
    ) {
        // remember the selected messages for #onActivityResult
        activeMessages = messages

        val input = ChooseFolderResultContract.Input(
            accountUuid = accountUuid,
            currentFolderId = sourceFolderId,
            scrollToFolderId = lastSelectedFolderId,
        )
        when (operation) {
            FolderOperation.COPY -> chooseFolderToCopyResultLauncher.launch(input)
            FolderOperation.MOVE -> chooseFolderToMoveResultLauncher.launch(input)
        }
    }

    private fun handleChooseFolderResult(
        result: ChooseFolderResultContract.Result?,
        action: (Long, List<MessageReference>) -> Unit,
    ) {
        if (result == null) return

        val destinationFolderId = result.folderId
        val messages = activeMessages!!

        if (destinationFolderId != -1L) {
            activeMessages = null


Review comment (suggestion):
This comment is now misleading or at least requires knowledge of how `ActivityResultLauncher` is implemented. 

```suggestion
        // Remember the selected messages so they are available in the registerForActivityResult() callbacks
```

Code after:
    private fun onCopy(messages: List<MessageReference>) {
        if (!checkCopyOrMovePossible(messages, FolderOperation.COPY)) return

        val folderId = when {
            isThreadDisplay -> messages.first().folderId
            isSingleFolderMode -> currentFolder!!.databaseId
            else -> null
        }

        displayFolderChoice(
            operation = FolderOperation.COPY,
            sourceFolderId = folderId,
            accountUuid = messages.first().accountUuid,
            lastSelectedFolderId = null,
            messages = messages,
        )
    }

    private fun displayFolderChoice(
        operation: FolderOperation,
        sourceFolderId: Long?,
        accountUuid: String,
        lastSelectedFolderId: Long?,
        messages: List<MessageReference>,
    ) {
        // Remember the selected messages so they are available in the registerForActivityResult() callbacks
        activeMessages = messages

        val input = ChooseFolderResultContract.Input(
            accountUuid = accountUuid,
            currentFolderId = sourceFolderId,
            scrollToFolderId = lastSelectedFolderId,
        )
        when (operation) {
            FolderOperation.COPY -> chooseFolderForCopyLauncher.launch(input)
            FolderOperation.MOVE -> chooseFolderForMoveLauncher.launch(input)
        }
    }

    private fun handleChooseFolderResult(
        result: ChooseFolderResultContract.Result?,
        action: (Long, List<MessageReference>) -> Unit,
    ) {
        if (result == null) return

        val destinationFolderId = result.folderId
        val messages = activeMessages!!

        if (destinationFolderId != -1L) {
            activeMessages = null