From f7a120e3fc6f0bb96e75aa36f1818ecc1371d8c1 Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Tue, 11 Jan 2022 09:35:25 +0100 Subject: [PATCH 1/6] Create use case to return list of files filtered --- .../dependecyinjection/UseCaseModule.kt | 2 ++ .../dependecyinjection/ViewModelModule.kt | 2 +- .../files/filelist/MainFileListViewModel.kt | 21 +++++++++++ .../files/datasources/LocalFileDataSource.kt | 1 + .../implementation/OCLocalFileDataSource.kt | 5 +++ .../owncloud/android/data/files/db/FileDao.kt | 12 +++++++ .../data/files/repository/OCFileRepository.kt | 3 ++ .../android/domain/files/FileRepository.kt | 1 + .../GetFilteredFolderContentUseCase.kt | 35 +++++++++++++++++++ 9 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt 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..5878d426591 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.GetFilteredFolderContentUseCase 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 { GetFilteredFolderContentUseCase(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 21a89956871..9db66854f68 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()) } + viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get()) } } 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 976a8ceec9c..45ed46facf7 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 @@ -30,6 +30,7 @@ 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.GetFilteredFolderContentUseCase import com.owncloud.android.domain.files.usecases.GetFolderContentAsLiveDataUseCase import com.owncloud.android.domain.files.usecases.RefreshFolderFromServerAsyncUseCase import com.owncloud.android.domain.utils.Event @@ -43,6 +44,7 @@ class MainFileListViewModel( private val getFolderContentAsLiveDataUseCase: GetFolderContentAsLiveDataUseCase, private val getFilesSharedByLinkUseCase: GetFilesSharedByLinkUseCase, private val getFilesAvailableOfflineUseCase: GetFilesAvailableOfflineUseCase, + private val getFilteredFolderContentUseCase: GetFilteredFolderContentUseCase, private val refreshFolderFromServerAsyncUseCase: RefreshFolderFromServerAsyncUseCase, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val contextProvider: ContextProvider, @@ -62,6 +64,10 @@ class MainFileListViewModel( val getFilesAvailableOfflineData: LiveData>>> get() = _getFilesAvailableOfflineData + private val _getFilteredFilesData = MutableLiveData>>>() + val getFilteredFilesData: LiveData>>> + get() = _getFilteredFilesData + private fun getFilesList(folderId: Long) { val filesListLiveData: LiveData> = getFolderContentAsLiveDataUseCase.execute(GetFolderContentAsLiveDataUseCase.Params(folderId = folderId)) @@ -93,6 +99,17 @@ class MainFileListViewModel( } } + private fun getFilteredFilesList(folderId: Long, searchText: String) { + viewModelScope.launch(coroutinesDispatcherProvider.io) { + getFilteredFolderContentUseCase.execute(GetFilteredFolderContentUseCase.Params(folderId = folderId, search = searchText)).let { + when (it) { + is UseCaseResult.Error -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Error(it.getThrowableOrNull()))) + is UseCaseResult.Success -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Success(it.getDataOrNull()))) + } + } + } + } + private fun refreshFilesList(remotePath: String) { viewModelScope.launch(coroutinesDispatcherProvider.io) { _getFilesListStatusLiveData.postValue(Event(UIResult.Loading())) @@ -109,6 +126,10 @@ class MainFileListViewModel( getFilesList(directory.id!!) } + fun listFilteredCurrentDirectory(searchText: String) { + getFilteredFilesList(file.id!!, searchText) + } + fun refreshDirectory() { refreshFilesList(file.remotePath) } 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..2c25ae335a2 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,7 @@ interface LocalFileDataSource { fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? fun getFolderContent(folderId: Long): List + fun getFilteredFolderContent(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..49b693a87a8 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,11 @@ class OCLocalFileDataSource( it.toModel() } + override fun getFilteredFolderContent(folderId: Long, search: String): List = + fileDao.getFilteredFolderContent(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..d98b7215cd0 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,12 @@ abstract class FileDao { remotePath: String ): OCFileEntity? + @Query(SELECT_FILTERED_FOLDER_CONTENT) + abstract fun getFilteredFolderContent( + folderId: Long, + search: String + ): List + @Query(SELECT_FOLDER_CONTENT) abstract fun getFolderContent( folderId: Long @@ -240,6 +246,12 @@ 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_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..2b903f0db4a 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 @@ -111,6 +111,9 @@ class OCFileRepository( override fun getFileByRemotePath(remotePath: String, owner: String): OCFile? = localFileDataSource.getFileByRemotePath(remotePath, owner) + override fun getFilteredFolderContent(folderId: Long, search: String): List = + localFileDataSource.getFilteredFolderContent(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..76d1d83d3d7 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 @@ -28,6 +28,7 @@ interface FileRepository { fun copyFile(listOfFilesToCopy: List, targetFolder: OCFile) fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? + fun getFilteredFolderContent(folderId: Long, search: String): List fun getFolderContent(folderId: Long): List fun getFolderContentAsLiveData(folderId: Long): LiveData> fun getFolderImages(folderId: Long): List diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt new file mode 100644 index 00000000000..6f3a185a0c4 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt @@ -0,0 +1,35 @@ +/** + * 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.OCFile + +class GetFilteredFolderContentUseCase( + private val repository: FileRepository +) : BaseUseCaseWithResult, GetFilteredFolderContentUseCase.Params>() { + + override fun run(params: Params) = repository.getFilteredFolderContent(params.folderId, params.search) + + data class Params( + val folderId: Long, + val search: String + ) + +} From 853eb7125f6aec88d9a9a64c45c06879cb285e25 Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Tue, 11 Jan 2022 14:35:30 +0100 Subject: [PATCH 2/6] Add filter observer --- .../presentation/ui/files/filelist/MainFileListFragment.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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 716994fb135..e12d6a2370a 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 @@ -155,6 +155,13 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor updateFileListData(files = data ?: emptyList()) } }) + + // Observe the action of retrieving the list of filtered files from DB. + mainFileListViewModel.getFilteredFilesData.observe(viewLifecycleOwner, Event.EventObserver { + it.onSuccess { data -> + updateFileListData(files = data ?: emptyList()) + } + }) } fun listDirectory(directory: OCFile) { From 2b88a1d222b09850b3955b50679551ca4914f10b Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Tue, 11 Jan 2022 16:11:31 +0100 Subject: [PATCH 3/6] Enable search view behavior --- .../ui/files/filelist/MainFileListFragment.kt | 14 +++++++++++++- .../android/ui/activity/FileDisplayActivity.kt | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) 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 e12d6a2370a..14441f94cdb 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.LinearLayoutManager @@ -57,7 +58,7 @@ 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() @@ -365,5 +366,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.listFilteredCurrentDirectory(it) } + return true + } + + fun setSearchListener(searchView: SearchView) { + searchView.setOnQueryTextListener(this) + } } 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..7c928568868 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 @@ -351,6 +351,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 +1146,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) } From 58e0a0e52e9dbe877accb1f968a44dc3fa6e16f8 Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Tue, 11 Jan 2022 16:21:13 +0100 Subject: [PATCH 4/6] Rename methods --- .../android/dependecyinjection/UseCaseModule.kt | 4 ++-- .../ui/files/filelist/MainFileListFragment.kt | 2 +- .../ui/files/filelist/MainFileListViewModel.kt | 12 ++++++------ .../data/files/datasources/LocalFileDataSource.kt | 2 +- .../implementation/OCLocalFileDataSource.kt | 4 ++-- .../com/owncloud/android/data/files/db/FileDao.kt | 2 +- .../data/files/repository/OCFileRepository.kt | 4 ++-- .../owncloud/android/domain/files/FileRepository.kt | 2 +- ...ntUseCase.kt => GetSearchFolderContentUseCase.kt} | 6 +++--- 9 files changed, 19 insertions(+), 19 deletions(-) rename owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/{GetFilteredFolderContentUseCase.kt => GetSearchFolderContentUseCase.kt} (81%) 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 5878d426591..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,7 +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.GetFilteredFolderContentUseCase +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 @@ -104,7 +104,7 @@ val useCaseModule = module { factory { SaveFileOrFolderUseCase(get()) } factory { GetFilesSharedByLinkUseCase(get()) } factory { GetFilesAvailableOfflineUseCase(get()) } - factory { GetFilteredFolderContentUseCase(get()) } + factory { GetSearchFolderContentUseCase(get()) } // Sharing factory { CreatePrivateShareAsyncUseCase(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 14441f94cdb..61277850308 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 @@ -370,7 +370,7 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor override fun onQueryTextSubmit(query: String?): Boolean = false override fun onQueryTextChange(newText: String?): Boolean { - newText?.let { mainFileListViewModel.listFilteredCurrentDirectory(it) } + newText?.let { mainFileListViewModel.listSearchCurrentDirectory(it) } return true } 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 45ed46facf7..f88e833ba0d 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 @@ -30,7 +30,7 @@ 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.GetFilteredFolderContentUseCase +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 @@ -44,7 +44,7 @@ class MainFileListViewModel( private val getFolderContentAsLiveDataUseCase: GetFolderContentAsLiveDataUseCase, private val getFilesSharedByLinkUseCase: GetFilesSharedByLinkUseCase, private val getFilesAvailableOfflineUseCase: GetFilesAvailableOfflineUseCase, - private val getFilteredFolderContentUseCase: GetFilteredFolderContentUseCase, + private val getSearchFolderContentUseCase: GetSearchFolderContentUseCase, private val refreshFolderFromServerAsyncUseCase: RefreshFolderFromServerAsyncUseCase, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val contextProvider: ContextProvider, @@ -99,9 +99,9 @@ class MainFileListViewModel( } } - private fun getFilteredFilesList(folderId: Long, searchText: String) { + private fun getSearchFilesList(folderId: Long, searchText: String) { viewModelScope.launch(coroutinesDispatcherProvider.io) { - getFilteredFolderContentUseCase.execute(GetFilteredFolderContentUseCase.Params(folderId = folderId, search = searchText)).let { + getSearchFolderContentUseCase.execute(GetSearchFolderContentUseCase.Params(folderId = folderId, search = searchText)).let { when (it) { is UseCaseResult.Error -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Error(it.getThrowableOrNull()))) is UseCaseResult.Success -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Success(it.getDataOrNull()))) @@ -126,8 +126,8 @@ class MainFileListViewModel( getFilesList(directory.id!!) } - fun listFilteredCurrentDirectory(searchText: String) { - getFilteredFilesList(file.id!!, searchText) + fun listSearchCurrentDirectory(searchText: String) { + getSearchFilesList(file.id!!, searchText) } fun refreshDirectory() { 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 2c25ae335a2..96c2a11d484 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,7 +28,7 @@ interface LocalFileDataSource { fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? fun getFolderContent(folderId: Long): List - fun getFilteredFolderContent(folderId: Long, search: String): List + fun getSearchFolderContent(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 49b693a87a8..19cc052dabb 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,8 +69,8 @@ class OCLocalFileDataSource( it.toModel() } - override fun getFilteredFolderContent(folderId: Long, search: String): List = - fileDao.getFilteredFolderContent(folderId = folderId, search = search).map { + override fun getSearchFolderContent(folderId: Long, search: String): List = + fileDao.getSearchFolderContent(folderId = folderId, search = search).map { it.toModel() } 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 d98b7215cd0..73a3eb22e72 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 @@ -42,7 +42,7 @@ abstract class FileDao { ): OCFileEntity? @Query(SELECT_FILTERED_FOLDER_CONTENT) - abstract fun getFilteredFolderContent( + abstract fun getSearchFolderContent( folderId: Long, search: String ): List 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 2b903f0db4a..25986181738 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 @@ -111,8 +111,8 @@ class OCFileRepository( override fun getFileByRemotePath(remotePath: String, owner: String): OCFile? = localFileDataSource.getFileByRemotePath(remotePath, owner) - override fun getFilteredFolderContent(folderId: Long, search: String): List = - localFileDataSource.getFilteredFolderContent(folderId, search) + override fun getSearchFolderContent(folderId: Long, search: String): List = + localFileDataSource.getSearchFolderContent(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 76d1d83d3d7..b945eb74caa 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 @@ -28,7 +28,7 @@ interface FileRepository { fun copyFile(listOfFilesToCopy: List, targetFolder: OCFile) fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? - fun getFilteredFolderContent(folderId: Long, search: String): List + fun getSearchFolderContent(folderId: Long, search: String): List fun getFolderContent(folderId: Long): List fun getFolderContentAsLiveData(folderId: Long): LiveData> fun getFolderImages(folderId: Long): List diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt similarity index 81% rename from owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt rename to owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt index 6f3a185a0c4..9cdc74a9416 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetFilteredFolderContentUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/GetSearchFolderContentUseCase.kt @@ -21,11 +21,11 @@ import com.owncloud.android.domain.BaseUseCaseWithResult import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.domain.files.model.OCFile -class GetFilteredFolderContentUseCase( +class GetSearchFolderContentUseCase( private val repository: FileRepository -) : BaseUseCaseWithResult, GetFilteredFolderContentUseCase.Params>() { +) : BaseUseCaseWithResult, GetSearchFolderContentUseCase.Params>() { - override fun run(params: Params) = repository.getFilteredFolderContent(params.folderId, params.search) + override fun run(params: Params) = repository.getSearchFolderContent(params.folderId, params.search) data class Params( val folderId: Long, From 67e1765b81c5292db070cf8069694b66982b463e Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Wed, 12 Jan 2022 09:13:50 +0100 Subject: [PATCH 5/6] Split searches betwenn all files, available offline and shared by link --- .../ui/files/filelist/MainFileListFragment.kt | 17 +++++++----- .../files/filelist/MainFileListViewModel.kt | 23 +++++++++------- .../android/ui/activity/DrawerActivity.kt | 1 + .../android/ui/activity/FileActivity.java | 1 + .../ui/activity/FileDisplayActivity.kt | 1 + .../ui/activity/FolderPickerActivity.java | 1 + .../ui/fragment/OCFileListFragment.java | 2 +- .../ui/preview/PreviewImageActivity.kt | 2 +- .../files/datasources/LocalFileDataSource.kt | 2 ++ .../implementation/OCLocalFileDataSource.kt | 10 +++++++ .../owncloud/android/data/files/db/FileDao.kt | 27 +++++++++++++++++++ .../data/files/repository/OCFileRepository.kt | 9 +++++-- .../android/domain/files/FileRepository.kt | 3 ++- .../domain/files/model}/FileListOption.kt | 2 +- .../usecases/GetSearchFolderContentUseCase.kt | 8 +++++- 15 files changed, 86 insertions(+), 23 deletions(-) rename {owncloudApp/src/main/java/com/owncloud/android/ui/activity => owncloudDomain/src/main/java/com/owncloud/android/domain/files/model}/FileListOption.kt (95%) 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 61277850308..16a8b272366 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 @@ -52,7 +52,7 @@ 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.FileStorageUtils import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.java.KoinJavaComponent.get @@ -73,6 +73,8 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor private var miniFabClicked = false + private var fileListOption: FileListOption? = FileListOption.ALL_FILES + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -86,16 +88,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() { @@ -157,8 +159,8 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor } }) - // Observe the action of retrieving the list of filtered files from DB. - mainFileListViewModel.getFilteredFilesData.observe(viewLifecycleOwner, Event.EventObserver { + // 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()) } @@ -226,6 +228,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() @@ -370,7 +373,7 @@ class MainFileListFragment : Fragment(), SortDialogListener, SortOptionsView.Sor override fun onQueryTextSubmit(query: String?): Boolean = false override fun onQueryTextChange(newText: String?): Boolean { - newText?.let { mainFileListViewModel.listSearchCurrentDirectory(it) } + newText?.let { mainFileListViewModel.listSearchCurrentDirectory(fileListOption!!, it) } return true } 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 f88e833ba0d..f5e1929eee7 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 @@ -37,6 +37,7 @@ 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 @@ -64,9 +65,9 @@ class MainFileListViewModel( val getFilesAvailableOfflineData: LiveData>>> get() = _getFilesAvailableOfflineData - private val _getFilteredFilesData = MutableLiveData>>>() - val getFilteredFilesData: LiveData>>> - get() = _getFilteredFilesData + private val _getSearchedFilesData = MutableLiveData>>>() + val getSearchedFilesData: LiveData>>> + get() = _getSearchedFilesData private fun getFilesList(folderId: Long) { val filesListLiveData: LiveData> = @@ -99,12 +100,16 @@ class MainFileListViewModel( } } - private fun getSearchFilesList(folderId: Long, searchText: String) { + private fun getSearchFilesList(fileListOption: FileListOption, folderId: Long, searchText: String) { viewModelScope.launch(coroutinesDispatcherProvider.io) { - getSearchFolderContentUseCase.execute(GetSearchFolderContentUseCase.Params(folderId = folderId, search = searchText)).let { + getSearchFolderContentUseCase.execute(GetSearchFolderContentUseCase.Params( + fileListOption = fileListOption, + folderId = folderId, + search = searchText) + ).let { when (it) { - is UseCaseResult.Error -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Error(it.getThrowableOrNull()))) - is UseCaseResult.Success -> _getFilesAvailableOfflineData.postValue(Event(UIResult.Success(it.getDataOrNull()))) + is UseCaseResult.Error -> _getSearchedFilesData.postValue(Event(UIResult.Error(it.getThrowableOrNull()))) + is UseCaseResult.Success -> _getSearchedFilesData.postValue(Event(UIResult.Success(it.getDataOrNull()))) } } } @@ -126,8 +131,8 @@ class MainFileListViewModel( getFilesList(directory.id!!) } - fun listSearchCurrentDirectory(searchText: String) { - getSearchFilesList(file.id!!, searchText) + fun listSearchCurrentDirectory(fileListOption: FileListOption, searchText: String) { + getSearchFilesList(fileListOption, file.id!!, searchText) } fun refreshDirectory() { 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 7c928568868..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 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 96c2a11d484..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 @@ -29,6 +29,8 @@ interface LocalFileDataSource { 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 19cc052dabb..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 @@ -74,6 +74,16 @@ class OCLocalFileDataSource( 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 73a3eb22e72..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 @@ -47,6 +47,18 @@ abstract class FileDao { 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 @@ -252,6 +264,21 @@ abstract class FileDao { "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 25986181738..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,8 +112,12 @@ class OCFileRepository( override fun getFileByRemotePath(remotePath: String, owner: String): OCFile? = localFileDataSource.getFileByRemotePath(remotePath, owner) - override fun getSearchFolderContent(folderId: Long, search: String): List = - localFileDataSource.getSearchFolderContent(folderId, search) + 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 b945eb74caa..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,7 +29,7 @@ interface FileRepository { fun copyFile(listOfFilesToCopy: List, targetFolder: OCFile) fun getFileById(fileId: Long): OCFile? fun getFileByRemotePath(remotePath: String, owner: String): OCFile? - fun getSearchFolderContent(folderId: Long, search: String): List + 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 index 9cdc74a9416..bd9ed880998 100644 --- 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 @@ -19,15 +19,21 @@ 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(params.folderId, params.search) + 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 ) From 1a3e5217a63f0004f17c65f25275a3a997b843ac Mon Sep 17 00:00:00 2001 From: Jose Antonio Barros Date: Wed, 12 Jan 2022 11:29:52 +0100 Subject: [PATCH 6/6] Remove unused import --- .../presentation/ui/files/filelist/MainFileListViewModel.kt | 1 - 1 file changed, 1 deletion(-) 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 e7cc0639659..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,7 +25,6 @@ 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