diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt index 32f288ce79e..ac83fdbd27a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt @@ -42,6 +42,7 @@ import com.owncloud.android.domain.files.usecases.GetFileByIdUseCase import com.owncloud.android.domain.files.usecases.GetFileByRemotePathUseCase import com.owncloud.android.domain.files.usecases.GetFilesAvailableOfflineUseCase import com.owncloud.android.domain.files.usecases.GetFilesSharedByLinkUseCase +import com.owncloud.android.domain.files.usecases.GetSearchFolderContentUseCase import com.owncloud.android.domain.files.usecases.GetFolderContentAsLiveDataUseCase import com.owncloud.android.domain.files.usecases.GetFolderContentUseCase import com.owncloud.android.domain.files.usecases.GetFolderImagesUseCase @@ -103,6 +104,7 @@ val useCaseModule = module { factory { SaveFileOrFolderUseCase(get()) } factory { GetFilesSharedByLinkUseCase(get()) } factory { GetFilesAvailableOfflineUseCase(get()) } + factory { GetSearchFolderContentUseCase(get()) } // Sharing factory { CreatePrivateShareAsyncUseCase(get()) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt index 9db66854f68..f1bf08f9873 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -75,5 +75,5 @@ val viewModelModule = module { viewModel { PreviewImageViewModel(get(), get(), get()) } viewModel { FileDetailsViewModel(get(), get(), get(), get(), get()) } viewModel { FileOperationViewModel(get(), get(), get(), get(), get(), get()) } - viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get()) } + viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get(), get()) } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt index 1b4525f8582..5ea267bd37a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListFragment.kt @@ -26,6 +26,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager @@ -51,14 +52,14 @@ import com.owncloud.android.presentation.ui.files.SortType import com.owncloud.android.presentation.ui.files.ViewType import com.owncloud.android.presentation.ui.files.createfolder.CreateFolderDialogFragment import com.owncloud.android.presentation.viewmodels.files.FilesViewModel -import com.owncloud.android.ui.activity.FileListOption +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.utils.ColumnQuantity import com.owncloud.android.utils.FileStorageUtils import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.java.KoinJavaComponent.get class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.SortOptionsListener, SortOptionsView.CreateFolderListener, - CreateFolderDialogFragment.CreateFolderListener { + CreateFolderDialogFragment.CreateFolderListener, SearchView.OnQueryTextListener { private val mainFileListViewModel by viewModel() @@ -75,6 +76,8 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor private lateinit var fileListAdapter: FileListAdapter private lateinit var viewType: ViewType + private var fileListOption: FileListOption? = FileListOption.ALL_FILES + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -88,16 +91,16 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor initViews() subscribeToViewModels() - var fileListOption: FileListOption? = + fileListOption = if (requireArguments().getParcelable(ARG_LIST_FILE_OPTION) != null) requireArguments().getParcelable(ARG_LIST_FILE_OPTION) else - null + FileListOption.ALL_FILES if (fileListOption == null) { fileListOption = FileListOption.ALL_FILES } - updateFab(fileListOption) + updateFab(fileListOption!!) } private fun initViews() { @@ -174,6 +177,13 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor updateFileListData(files = data ?: emptyList()) } }) + + // Observe the action of retrieving the list of searched files from DB. + mainFileListViewModel.getSearchedFilesData.observe(viewLifecycleOwner, Event.EventObserver { + it.onSuccess { data -> + updateFileListData(files = data ?: emptyList()) + } + }) } fun listDirectory(directory: OCFile) { @@ -262,6 +272,7 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor } fun updateFileListOption(newFileListOption: FileListOption) { + fileListOption = newFileListOption when (newFileListOption) { FileListOption.ALL_FILES -> mainFileListViewModel.listCurrentDirectory() FileListOption.AV_OFFLINE -> mainFileListViewModel.getAvailableOfflineFilesList() @@ -402,5 +413,16 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor override fun onCreateFolderListener() { //TODO("Not yet implemented") } + + override fun onQueryTextSubmit(query: String?): Boolean = false + + override fun onQueryTextChange(newText: String?): Boolean { + newText?.let { mainFileListViewModel.listSearchCurrentDirectory(fileListOption!!, it) } + return true + } + + fun setSearchListener(searchView: SearchView) { + searchView.setOnQueryTextListener(this) + } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListViewModel.kt index e5f75cd9943..909fe92905b 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/ui/files/filelist/MainFileListViewModel.kt @@ -25,19 +25,20 @@ import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.owncloud.android.R import com.owncloud.android.data.preferences.datasources.SharedPreferencesProvider import com.owncloud.android.db.PreferenceManager import com.owncloud.android.domain.UseCaseResult import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.usecases.GetFilesAvailableOfflineUseCase import com.owncloud.android.domain.files.usecases.GetFilesSharedByLinkUseCase +import com.owncloud.android.domain.files.usecases.GetSearchFolderContentUseCase import com.owncloud.android.domain.files.usecases.GetFolderContentAsLiveDataUseCase import com.owncloud.android.domain.files.usecases.RefreshFolderFromServerAsyncUseCase import com.owncloud.android.domain.utils.Event import com.owncloud.android.presentation.UIResult import com.owncloud.android.providers.ContextProvider import com.owncloud.android.providers.CoroutinesDispatcherProvider +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.utils.FileStorageUtils import kotlinx.coroutines.launch @@ -45,6 +46,7 @@ class MainFileListViewModel( private val getFolderContentAsLiveDataUseCase: GetFolderContentAsLiveDataUseCase, private val getFilesSharedByLinkUseCase: GetFilesSharedByLinkUseCase, private val getFilesAvailableOfflineUseCase: GetFilesAvailableOfflineUseCase, + private val getSearchFolderContentUseCase: GetSearchFolderContentUseCase, private val refreshFolderFromServerAsyncUseCase: RefreshFolderFromServerAsyncUseCase, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val sharedPreferencesProvider: SharedPreferencesProvider, @@ -65,6 +67,10 @@ class MainFileListViewModel( val getFilesAvailableOfflineData: LiveData>>> get() = _getFilesAvailableOfflineData + private val _getSearchedFilesData = MutableLiveData>>>() + val getSearchedFilesData: LiveData>>> + get() = _getSearchedFilesData + private fun getFilesList(folderId: Long) { val filesListLiveData: LiveData> = getFolderContentAsLiveDataUseCase.execute(GetFolderContentAsLiveDataUseCase.Params(folderId = folderId)) @@ -96,6 +102,21 @@ class MainFileListViewModel( } } + private fun getSearchFilesList(fileListOption: FileListOption, folderId: Long, searchText: String) { + viewModelScope.launch(coroutinesDispatcherProvider.io) { + getSearchFolderContentUseCase.execute(GetSearchFolderContentUseCase.Params( + fileListOption = fileListOption, + folderId = folderId, + search = searchText) + ).let { + when (it) { + is UseCaseResult.Error -> _getSearchedFilesData.postValue(Event(UIResult.Error(it.getThrowableOrNull()))) + is UseCaseResult.Success -> _getSearchedFilesData.postValue(Event(UIResult.Success(it.getDataOrNull()))) + } + } + } + } + private fun refreshFilesList(remotePath: String) { viewModelScope.launch(coroutinesDispatcherProvider.io) { _getFilesListStatusLiveData.postValue(Event(UIResult.Loading())) @@ -112,6 +133,10 @@ class MainFileListViewModel( getFilesList(directory.id!!) } + fun listSearchCurrentDirectory(fileListOption: FileListOption, searchText: String) { + getSearchFilesList(fileListOption, file.id!!, searchText) + } + fun refreshDirectory() { refreshFilesList(file.remotePath) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt index 092f973b541..b738e84d46e 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.kt @@ -53,6 +53,7 @@ import com.owncloud.android.BuildConfig import com.owncloud.android.MainApp.Companion.initDependencyInjection import com.owncloud.android.R import com.owncloud.android.authentication.AccountUtils +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.extensions.goToUrl import com.owncloud.android.extensions.sendEmail import com.owncloud.android.lib.common.OwnCloudAccount diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index 06f4994e45a..8e828e52e59 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -40,6 +40,7 @@ import com.google.android.material.snackbar.Snackbar; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.domain.files.model.FileListOption; import com.owncloud.android.domain.files.model.OCFile; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt index 7b384c84e98..29f4511db27 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt @@ -60,6 +60,7 @@ import com.owncloud.android.authentication.PatternManager import com.owncloud.android.databinding.ActivityMainBinding import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.domain.exceptions.SSLRecoverablePeerUnverifiedException +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.utils.Event import com.owncloud.android.extensions.observeWorkerTillItFinishes @@ -351,6 +352,8 @@ class FileDisplayActivity : FileActivity(), FileFragment.ContainerActivity, OnEn val transaction = supportFragmentManager.beginTransaction() transaction.add(R.id.left_fragment_container, mainListOfFiles, TAG_LIST_OF_FILES_BIS) transaction.commit() + + mainListOfFiles.setSearchListener(findViewById(R.id.root_toolbar_search_view)) } private fun initFragmentsWithFile() { @@ -1144,7 +1147,7 @@ class FileDisplayActivity : FileActivity(), FileFragment.ContainerActivity, OnEn FileListOption.ALL_FILES -> getString(R.string.default_display_name_for_root_folder) } setupRootToolbar(title, isSearchEnabled = true) - listOfFilesFragment?.setSearchListener(findViewById(R.id.root_toolbar_search_view)) + listMainFileFragment?.setSearchListener(findViewById(R.id.root_toolbar_search_view)) } else { updateStandardToolbar(title = chosenFile.fileName, displayHomeAsUpEnabled = true, homeButtonEnabled = true) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java index ba40f36bfc9..6224e25e02f 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -42,6 +42,7 @@ import androidx.fragment.app.FragmentTransaction; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.owncloud.android.R; +import com.owncloud.android.domain.files.model.FileListOption; import com.owncloud.android.domain.files.model.OCFile; import com.owncloud.android.extensions.ThrowableExtKt; import com.owncloud.android.lib.common.operations.RemoteOperationResult; diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 3ad3c86c62f..a244d21c89f 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -77,7 +77,7 @@ import com.owncloud.android.presentation.viewmodels.files.FilesViewModel; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; -import com.owncloud.android.ui.activity.FileListOption; +import com.owncloud.android.domain.files.model.FileListOption; import com.owncloud.android.ui.activity.FolderPickerActivity; import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; import com.owncloud.android.ui.adapter.FileListListAdapter; diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt index 425a500f049..bbb7c9cc0ce 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt @@ -54,7 +54,7 @@ import com.owncloud.android.presentation.manager.DOWNLOAD_FINISH_MESSAGE import com.owncloud.android.presentation.ui.files.operations.FileOperationViewModel import com.owncloud.android.ui.activity.FileActivity import com.owncloud.android.ui.activity.FileDisplayActivity -import com.owncloud.android.ui.activity.FileListOption +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.ui.fragment.FileFragment import com.owncloud.android.utils.FileStorageUtils import com.owncloud.android.utils.PreferenceUtils diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt index 7acfb6239a3..9633b10e457 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt @@ -28,6 +28,9 @@ interface LocalFileDataSource { fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? fun getFolderContent(folderId: Long): List + fun getSearchFolderContent(folderId: Long, search: String): List + fun getSearchAvailableOfflineFolderContent(folderId: Long, search: String): List + fun getSearchSharedByLinkFolderContent(folderId: Long, search: String): List fun getFolderContentAsLiveData(folderId: Long): LiveData> fun getFolderImages(folderId: Long): List fun getFilesSharedByLink(owner: String): List diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt index d489be6f018..2e6e9f2ca09 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt @@ -69,6 +69,21 @@ class OCLocalFileDataSource( it.toModel() } + override fun getSearchFolderContent(folderId: Long, search: String): List = + fileDao.getSearchFolderContent(folderId = folderId, search = search).map { + it.toModel() + } + + override fun getSearchAvailableOfflineFolderContent(folderId: Long, search: String): List = + fileDao.getSearchAvailableOfflineFolderContent(folderId = folderId, search = search).map { + it.toModel() + } + + override fun getSearchSharedByLinkFolderContent(folderId: Long, search: String): List = + fileDao.getSearchSharedByLinkFolderContent(folderId = folderId, search = search).map { + it.toModel() + } + override fun getFolderContentAsLiveData(folderId: Long): LiveData> = Transformations.map(fileDao.getFolderContentAsLiveData(folderId = folderId)) { list -> list.map { diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt index e2212846d21..cfd8190882b 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt @@ -41,6 +41,24 @@ abstract class FileDao { remotePath: String ): OCFileEntity? + @Query(SELECT_FILTERED_FOLDER_CONTENT) + abstract fun getSearchFolderContent( + folderId: Long, + search: String + ): List + + @Query(SELECT_FILTERED_AVAILABLE_OFFLINE_FOLDER_CONTENT) + abstract fun getSearchAvailableOfflineFolderContent( + folderId: Long, + search: String + ): List + + @Query(SELECT_FILTERED_SHARED_BY_LINK_FOLDER_CONTENT) + abstract fun getSearchSharedByLinkFolderContent( + folderId: Long, + search: String + ): List + @Query(SELECT_FOLDER_CONTENT) abstract fun getFolderContent( folderId: Long @@ -240,6 +258,27 @@ abstract class FileDao { "FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} " + "WHERE parentId = :folderId" + private const val SELECT_FILTERED_FOLDER_CONTENT = + "SELECT * " + + "FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} " + + "WHERE parentId = :folderId " + + "AND remotePath LIKE '%' || :search || '%'" + + private const val SELECT_FILTERED_AVAILABLE_OFFLINE_FOLDER_CONTENT = + "SELECT * " + + "FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} " + + "WHERE parentId = :folderId " + + "AND keepInSync = '1' " + + "AND remotePath LIKE '%' || :search || '%'" + + private const val SELECT_FILTERED_SHARED_BY_LINK_FOLDER_CONTENT = + "SELECT * " + + "FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} " + + "WHERE parentId = :folderId " + + "AND remotePath LIKE '%' || :search || '%'" + + "AND sharedByLink NOT LIKE '%0%' " + + "OR sharedWithSharee NOT LIKE '%0%' " + private const val SELECT_FOLDER_BY_MIMETYPE = "SELECT * " + "FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} " + diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt index 2ccfe5b3125..6fe9860b852 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt @@ -28,6 +28,7 @@ import com.owncloud.android.domain.exceptions.ConflictException import com.owncloud.android.domain.exceptions.FileAlreadyExistsException import com.owncloud.android.domain.exceptions.FileNotFoundException import com.owncloud.android.domain.files.FileRepository +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.domain.files.model.MIME_DIR import com.owncloud.android.domain.files.model.OCFile import timber.log.Timber @@ -111,6 +112,13 @@ class OCFileRepository( override fun getFileByRemotePath(remotePath: String, owner: String): OCFile? = localFileDataSource.getFileByRemotePath(remotePath, owner) + override fun getSearchFolderContent(fileListOption: FileListOption, folderId: Long, search: String): List = + when (fileListOption) { + FileListOption.ALL_FILES -> localFileDataSource.getSearchFolderContent(folderId, search) + FileListOption.AV_OFFLINE -> localFileDataSource.getSearchAvailableOfflineFolderContent(folderId, search) + FileListOption.SHARED_BY_LINK -> localFileDataSource.getSearchSharedByLinkFolderContent(folderId, search) + } + override fun getFolderContent(folderId: Long): List = localFileDataSource.getFolderContent(folderId) diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt index e8b8fe31794..cf1af2b78fe 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt @@ -21,6 +21,7 @@ package com.owncloud.android.domain.files import androidx.lifecycle.LiveData +import com.owncloud.android.domain.files.model.FileListOption import com.owncloud.android.domain.files.model.OCFile interface FileRepository { @@ -28,6 +29,7 @@ interface FileRepository { fun copyFile(listOfFilesToCopy: List, targetFolder: OCFile) fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? + fun getSearchFolderContent(fileListOption: FileListOption, folderId: Long, search: String): List fun getFolderContent(folderId: Long): List fun getFolderContentAsLiveData(folderId: Long): LiveData> fun getFolderImages(folderId: Long): List diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileListOption.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/FileListOption.kt similarity index 95% rename from owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileListOption.kt rename to owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/FileListOption.kt index 063306d122d..e8918efd341 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileListOption.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/FileListOption.kt @@ -20,7 +20,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see //www.gnu.org/licenses/>. */ -package com.owncloud.android.ui.activity +package com.owncloud.android.domain.files.model import android.os.Parcelable import kotlinx.parcelize.Parcelize diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt new file mode 100644 index 00000000000..bd9ed880998 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt @@ -0,0 +1,41 @@ +/** + * ownCloud Android client application + * + * Copyright (C) 2020 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.FileListOption +import com.owncloud.android.domain.files.model.OCFile + +class GetSearchFolderContentUseCase( + private val repository: FileRepository +) : BaseUseCaseWithResult, GetSearchFolderContentUseCase.Params>() { + + override fun run(params: Params) = repository.getSearchFolderContent( + fileListOption = params.fileListOption, + folderId = params.folderId, + search = params.search + ) + + data class Params( + val fileListOption: FileListOption, + val folderId: Long, + val search: String + ) + +}