diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt index b37a0dd361..c1a38d35b6 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt @@ -269,8 +269,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt } } - // TODO add save feature for image => check it works for video as well, - // check if it is already possible to save from menu with long press on video override fun onDownload() { // TODO // call usecase using viewModel into handle method @@ -279,6 +277,8 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt // show message on error event: see TimelineFragment // check write file permissions: see TimelineFragment // should we check if media is saveable? + // check if it is already possible to save from menu with long press on video + // check if it works for video or other media type as well // add unit tests for usecase? TODO("Not yet implemented") } diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt index 8d0c376dd5..2b3266ee7e 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt @@ -20,6 +20,5 @@ import im.vector.app.core.platform.VectorViewEvents sealed class VectorAttachmentViewerViewEvents : VectorViewEvents { object DownloadingMedia : VectorAttachmentViewerViewEvents() - object MediaDownloaded : VectorAttachmentViewerViewEvents() object ErrorDownloadingMedia : VectorAttachmentViewerViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt index e6d86d2e7c..039977d573 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt @@ -23,9 +23,12 @@ import dagger.assisted.AssistedInject import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.platform.VectorDummyViewState import im.vector.app.core.platform.VectorViewModel +import im.vector.app.features.media.domain.usecase.DownloadMediaUseCase +import kotlinx.coroutines.launch class VectorAttachmentViewerViewModel @AssistedInject constructor( - @Assisted initialState: VectorDummyViewState + @Assisted initialState: VectorDummyViewState, + private val downloadMediaUseCase: DownloadMediaUseCase ) : VectorViewModel(initialState) { /* ========================================================================================== @@ -42,6 +45,22 @@ class VectorAttachmentViewerViewModel @AssistedInject constructor( * ========================================================================================== */ override fun handle(action: VectorAttachmentViewerAction) { - TODO("Not yet implemented") + when (action) { + is VectorAttachmentViewerAction.DownloadMedia -> handleDownloadAction(action) + } + } + + /* ========================================================================================== + * Private methods + * ========================================================================================== */ + + private fun handleDownloadAction(action: VectorAttachmentViewerAction.DownloadMedia) { + viewModelScope.launch { + _viewEvents.post(VectorAttachmentViewerViewEvents.DownloadingMedia) + + // Success event is handled via a notification inside use case + downloadMediaUseCase.execute(action.file) + .onFailure { _viewEvents.post(VectorAttachmentViewerViewEvents.ErrorDownloadingMedia) } + } } }