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

Code before:

        outState.putParcelable(STATE_CONTENT_URI, contentUri)
    }

    fun onSettingsListItemSelected(position: Int, isSelected: Boolean) {
        savedSelection = null

        updateUiModel {
            setSettingsListItemSelection(position, isSelected)
        }
    }

    private fun updateUiModel(block: SettingsExportUiModel.() -> Unit) {
        uiModel.block()
        uiModelLiveData.value = uiModel
    }

    private fun sendActionEvent(action: Action) {
        actionLiveData.value = action
    }

    companion object {
        private const val MIN_PROGRESS_DURATION = 1000L

        private const val STATE_SETTINGS_LIST_ENABLED = "settingsListEnabled"
        private const val STATE_EXPORT_BUTTON = "exportButton"
        private const val STATE_SHARE_BUTTON_VISIBLE = "shareButtonVisible"
        private const val STATE_PROGRESS_VISIBLE = "progressVisible"
        private const val STATE_STATUS_TEXT = "statusText"
        private const val STATE_INCLUDE_GENERAL_SETTINGS = "includeGeneralSettings"
        private const val STATE_SELECTED_ACCOUNTS = "selectedAccounts"
        private const val STATE_CONTENT_URI = "contentUri"
    }
}

sealed class Action {
    class PickDocument(val fileNameSuggestion: String) : Action()
    class ShareDocument(val contentUri: Uri) : Action()
}

private data class SavedListItemSelection(
    val includeGeneralSettings: Boolean,
    val selectedAccountUuids: Set<AccountUuid>,
)


Review comment (refactor):
Why did you move this to the fragment? Deciding which MIME type to use is not something that should be done in view code. 

Besides that, I also don't see how this is related to switching to the activity result API. Please try to keep pull requests as focused as possible.

Code after:

        outState.putParcelable(STATE_CONTENT_URI, contentUri)
    }

    fun onSettingsListItemSelected(position: Int, isSelected: Boolean) {
        savedSelection = null

        updateUiModel {
            setSettingsListItemSelection(position, isSelected)
        }
    }

    private fun updateUiModel(block: SettingsExportUiModel.() -> Unit) {
        uiModel.block()
        uiModelLiveData.value = uiModel
    }

    private fun sendActionEvent(action: Action) {
        actionLiveData.value = action
    }

    companion object {
        private const val MIN_PROGRESS_DURATION = 1000L
        private const val SETTINGS_MIME_TYPE = "application/octet-stream"

        private const val STATE_SETTINGS_LIST_ENABLED = "settingsListEnabled"
        private const val STATE_EXPORT_BUTTON = "exportButton"
        private const val STATE_SHARE_BUTTON_VISIBLE = "shareButtonVisible"
        private const val STATE_PROGRESS_VISIBLE = "progressVisible"
        private const val STATE_STATUS_TEXT = "statusText"
        private const val STATE_INCLUDE_GENERAL_SETTINGS = "includeGeneralSettings"
        private const val STATE_SELECTED_ACCOUNTS = "selectedAccounts"
        private const val STATE_CONTENT_URI = "contentUri"
    }
}

sealed class Action {
    class PickDocument(val fileNameSuggestion: String, val mimeType: String) : Action()
    class ShareDocument(val contentUri: Uri, val mimeType: String) : Action()
}

private data class SavedListItemSelection(
    val includeGeneralSettings: Boolean,
    val selectedAccountUuids: Set<AccountUuid>,
)