mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Changing usage of viewModelScope to Session scope
This commit is contained in:
parent
157feb1e4c
commit
aea78b70f1
1 changed files with 5 additions and 1 deletions
|
@ -26,10 +26,13 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
|
|||
import im.vector.app.core.platform.VectorDummyViewState
|
||||
import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.media.domain.usecase.DownloadMediaUseCase
|
||||
import im.vector.app.features.session.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
||||
class VectorAttachmentViewerViewModel @AssistedInject constructor(
|
||||
@Assisted initialState: VectorDummyViewState,
|
||||
private val session: Session,
|
||||
private val downloadMediaUseCase: DownloadMediaUseCase
|
||||
) : VectorViewModel<VectorDummyViewState, VectorAttachmentViewerAction, VectorAttachmentViewerViewEvents>(initialState) {
|
||||
|
||||
|
@ -65,7 +68,8 @@ class VectorAttachmentViewerViewModel @AssistedInject constructor(
|
|||
* ========================================================================================== */
|
||||
|
||||
private fun handleDownloadAction(action: VectorAttachmentViewerAction.DownloadMedia) {
|
||||
viewModelScope.launch {
|
||||
// launch in the coroutine scope session to avoid binding the coroutine to the lifecycle of the VM
|
||||
session.coroutineScope.launch {
|
||||
// Success event is handled via a notification inside the use case
|
||||
downloadMediaUseCase.execute(action.file)
|
||||
.onFailure { _viewEvents.post(VectorAttachmentViewerViewEvents.ErrorDownloadingMedia(it)) }
|
||||
|
|
Loading…
Reference in a new issue