Interface for UseCase
This commit is contained in:
parent
38236e7815
commit
374ac45505
@ -273,7 +273,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt
|
|||||||
// check if it is already possible to save from menu with long press on video
|
// check if it is already possible to save from menu with long press on video
|
||||||
override fun onDownload() {
|
override fun onDownload() {
|
||||||
// TODO
|
// TODO
|
||||||
// create interface for base use case
|
|
||||||
// create ViewModel with action downloadAction, events downloading, downloaded, error
|
// create ViewModel with action downloadAction, events downloading, downloaded, error
|
||||||
// call usecase using viewModel
|
// call usecase using viewModel
|
||||||
// launch coroutine in Activity using repeatOnLifeCycle extension
|
// launch coroutine in Activity using repeatOnLifeCycle extension
|
||||||
|
@ -30,20 +30,20 @@ import javax.inject.Inject
|
|||||||
class DownloadMediaUseCase @Inject constructor(
|
class DownloadMediaUseCase @Inject constructor(
|
||||||
@ApplicationContext private val appContext: Context,
|
@ApplicationContext private val appContext: Context,
|
||||||
private val notificationUtils: NotificationUtils
|
private val notificationUtils: NotificationUtils
|
||||||
) {
|
) : VectorInOutUseCase<File, Unit> {
|
||||||
|
|
||||||
/* ==========================================================================================
|
/* ==========================================================================================
|
||||||
* Public API
|
* Public API
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|
||||||
// TODO find a way to provide Dispatchers via Interface to be able to unit tests
|
// TODO find a way to provide Dispatchers via Interface to be able to unit tests
|
||||||
suspend fun execute(file: File): Result<Unit> = withContext(Dispatchers.IO) {
|
override suspend fun execute(input: File): Result<Unit> = withContext(Dispatchers.IO) {
|
||||||
runCatching {
|
runCatching {
|
||||||
saveMedia(
|
saveMedia(
|
||||||
context = appContext,
|
context = appContext,
|
||||||
file = file,
|
file = input,
|
||||||
title = file.name,
|
title = input.name,
|
||||||
mediaMimeType = getMimeTypeFromUri(appContext, file.toUri()),
|
mediaMimeType = getMimeTypeFromUri(appContext, input.toUri()),
|
||||||
notificationUtils = notificationUtils
|
notificationUtils = notificationUtils
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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<T, R> {
|
||||||
|
suspend fun execute(input: T): Result<R>
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user