DownloadView initially downloads a Record from a Performance and when a DownloadAudioFile button is clicked the FileService will download the Record's Audio file.
Is there a better place to store Performance, Record, and Audio other than private variables? I was thinking about creating DownloadModel, a model class for the DownloadView that can handle data that isn't being shown to UI.
I thought about only using ViewState but it feels weird accessing and storing data in there when it isn't shown to the UI. Record could be accessed from ViewState but what about Performance or Audio?
Just within the MVI context, not talking about storing it on a db or something.
class DownloadViewModel(val fileService: FileService, val scope: CoroutineScope,private val performance: Performance) {
private val _viewState: MutableStateFlow<ViewState> = MutableStateFlow(ViewState())
val viewState = _viewState.asStateFlow()
private val _oneShotEvents = Channel<OneShotEvent>(Channel.BUFFERED)
val oneShotEvents = _oneShotEvents.receiveAsFlow()
//val model: DownloadModel = DownloadModel(performance)
private lateinit var record: Record
init {
scope.launch {
record = fileService.performanceRequest(performance)
_viewState.value = _viewState.value.copy( record = record)
}
}
fun onAction(action: UiAction){
when(action){
UiAction.DownloadAudioFile -> {
scope.launch {
fileService.downloadAudio()
}
}
}
}
sealed class UiAction{
object DownloadAudioFile: UiAction()
}
data class ViewState(val record: models.Record? = null)
sealed class OneShotEvent{
}
}