mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 03:49:04 +03:00
Interface for UseCase
This commit is contained in:
parent
38236e7815
commit
374ac45505
3 changed files with 27 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -30,20 +30,20 @@ import javax.inject.Inject
|
|||
class DownloadMediaUseCase @Inject constructor(
|
||||
@ApplicationContext private val appContext: Context,
|
||||
private val notificationUtils: NotificationUtils
|
||||
) {
|
||||
) : VectorInOutUseCase<File, Unit> {
|
||||
|
||||
/* ==========================================================================================
|
||||
* Public API
|
||||
* ========================================================================================== */
|
||||
|
||||
// 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 {
|
||||
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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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 a new issue