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 3dae1f5ed2..2c51bf0947 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,7 +273,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt // check if it is already possible to save from menu with long press on video override fun onDownload() { // TODO - // create interface for base use case // create ViewModel with action downloadAction, events downloading, downloaded, error // call usecase using viewModel // launch coroutine in Activity using repeatOnLifeCycle extension diff --git a/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt b/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt index e7b7d02f01..f493058281 100644 --- a/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt @@ -30,20 +30,20 @@ import javax.inject.Inject class DownloadMediaUseCase @Inject constructor( @ApplicationContext private val appContext: Context, private val notificationUtils: NotificationUtils -) { +) : VectorInOutUseCase { /* ========================================================================================== * Public API * ========================================================================================== */ // TODO find a way to provide Dispatchers via Interface to be able to unit tests - suspend fun execute(file: File): Result = withContext(Dispatchers.IO) { + override suspend fun execute(input: File): Result = withContext(Dispatchers.IO) { runCatching { saveMedia( context = appContext, - file = file, - title = file.name, - mediaMimeType = getMimeTypeFromUri(appContext, file.toUri()), + file = input, + title = input.name, + mediaMimeType = getMimeTypeFromUri(appContext, input.toUri()), notificationUtils = notificationUtils ) } diff --git a/vector/src/main/java/im/vector/app/features/media/domain/usecase/VectorInOutUseCase.kt b/vector/src/main/java/im/vector/app/features/media/domain/usecase/VectorInOutUseCase.kt new file mode 100644 index 0000000000..d7c7585250 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/media/domain/usecase/VectorInOutUseCase.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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.domain.usecase + +// TODO move into Core packages +interface VectorInOutUseCase { + suspend fun execute(input: T): Result +}