From ff002a3b23c2796885b19c83f7284d7d0527fbb5 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Thu, 25 Jan 2024 04:08:41 +0530 Subject: [PATCH] add use-case Signed-off-by: parneet-guraya --- .../usecases/GetIfFileFolderLocalUseCase.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetIfFileFolderLocalUseCase.kt diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetIfFileFolderLocalUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetIfFileFolderLocalUseCase.kt new file mode 100644 index 00000000000..277944f1040 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetIfFileFolderLocalUseCase.kt @@ -0,0 +1,42 @@ +/** + * ownCloud Android client application + * + * @author Parneet Singh + * Copyright (C) 2024 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.owncloud.android.domain.files.usecases + +import com.owncloud.android.domain.BaseUseCaseWithResult +import com.owncloud.android.domain.files.FileRepository +import com.owncloud.android.domain.files.model.OCFile + +class GetIfFileFolderLocalUseCase(private val fileRepository: FileRepository) : BaseUseCaseWithResult() { + + override fun run(params: Params): Boolean = getIfFileFolderLocal(params.listOfFiles) + + private fun getIfFileFolderLocal(listOfFiles: List): Boolean { + listOfFiles.forEach { file -> + if (file.isFolder) { + if (getIfFileFolderLocal(fileRepository.getFolderContent(file.id!!))) return true + } else { + if (file.isAvailableLocally) return true + } + } + return false + } + + data class Params(val listOfFiles: List) + +}