diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerAction.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerAction.kt new file mode 100644 index 0000000000..8c9ca1e1ad --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerAction.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.media + +import im.vector.app.core.platform.VectorViewModelAction +import java.io.File + +sealed class VectorAttachmentViewerAction : VectorViewModelAction { + data class DownloadMedia(val file: File) : VectorAttachmentViewerAction() +} 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 2c51bf0947..b37a0dd361 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 @@ -273,9 +273,12 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt // check if it is already possible to save from menu with long press on video override fun onDownload() { // TODO - // create ViewModel with action downloadAction, events downloading, downloaded, error - // call usecase using viewModel + // call usecase using viewModel into handle method // launch coroutine in Activity using repeatOnLifeCycle extension + // call ViewModel.handle inside this method + // show message on error event: see TimelineFragment + // check write file permissions: see TimelineFragment + // should we check if media is saveable? // add unit tests for usecase? TODO("Not yet implemented") } diff --git a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerViewModel.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt similarity index 63% rename from library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerViewModel.kt rename to vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt index fbb46d4348..8d0c376dd5 100644 --- a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewEvents.kt @@ -1,6 +1,5 @@ /* * Copyright (c) 2020 New Vector Ltd - * Copyright (C) 2018 stfalcon.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +14,12 @@ * limitations under the License. */ -package im.vector.lib.attachmentviewer +package im.vector.app.features.media -class AttachmentViewerViewModel { +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 new file mode 100644 index 0000000000..e6d86d2e7c --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * Copyright (C) 2018 stfalcon.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.media + +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +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 + +class VectorAttachmentViewerViewModel @AssistedInject constructor( + @Assisted initialState: VectorDummyViewState +) : VectorViewModel(initialState) { + + /* ========================================================================================== + * Factory + * ========================================================================================== */ + + @AssistedFactory + interface Factory : MavericksAssistedViewModelFactory { + override fun create(initialState: VectorDummyViewState): VectorAttachmentViewerViewModel + } + + /* ========================================================================================== + * Specialization + * ========================================================================================== */ + + override fun handle(action: VectorAttachmentViewerAction) { + TODO("Not yet implemented") + } +}