mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
3a39b041de
commit
96ea22525e
11 changed files with 192 additions and 90 deletions
|
@ -25,10 +25,13 @@ import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||||
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
||||||
import com.nextcloud.client.TestActivity
|
import com.nextcloud.client.TestActivity
|
||||||
import com.owncloud.android.AbstractIT
|
import com.owncloud.android.AbstractIT
|
||||||
|
import com.owncloud.android.datamodel.OCFile
|
||||||
import com.owncloud.android.lib.common.SearchResult
|
import com.owncloud.android.lib.common.SearchResult
|
||||||
|
import com.owncloud.android.lib.common.SearchResultEntry
|
||||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class UnifiedSearchFragmentIT : AbstractIT() {
|
class UnifiedSearchFragmentIT : AbstractIT() {
|
||||||
@get:Rule
|
@get:Rule
|
||||||
|
@ -47,20 +50,20 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
||||||
sut.onSearchResultChanged(
|
sut.onSearchResultChanged(
|
||||||
mutableListOf(
|
mutableListOf(
|
||||||
SearchResult(
|
SearchResult(
|
||||||
"files",
|
"Files",
|
||||||
false,
|
false,
|
||||||
listOf(ex
|
listOf(
|
||||||
SearchResultEntry ("thumbnailUrl",
|
SearchResultEntry("thumbnailUrl",
|
||||||
"Test",
|
"Test",
|
||||||
"in /Files/",
|
"in /Files/",
|
||||||
"resourceUrl",
|
"resourceUrl",
|
||||||
"icon",
|
"icon",
|
||||||
false
|
false
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
longSleep()
|
longSleep()
|
||||||
|
@ -74,6 +77,13 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
||||||
val localRepository = UnifiedSearchLocalRepository()
|
val localRepository = UnifiedSearchLocalRepository()
|
||||||
testViewModel.setRepository(localRepository)
|
testViewModel.setRepository(localRepository)
|
||||||
|
|
||||||
|
val ocFile = OCFile("/folder/test1.txt").apply {
|
||||||
|
storagePath = "/sdcard/1.txt"
|
||||||
|
storageManager.saveFile(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
File(ocFile.storagePath).createNewFile()
|
||||||
|
|
||||||
activity.addFragment(sut)
|
activity.addFragment(sut)
|
||||||
|
|
||||||
shortSleep()
|
shortSleep()
|
||||||
|
|
|
@ -43,9 +43,16 @@ class UnifiedSearchLocalRepository : IUnifiedSearchRepository {
|
||||||
("thumbnailUrl",
|
("thumbnailUrl",
|
||||||
"Test",
|
"Test",
|
||||||
"in Files",
|
"in Files",
|
||||||
"resourceUrl",
|
"http://localhost/nc/index.php/apps/files/?dir=/Files&scrollto=Test",
|
||||||
"icon",
|
"icon",
|
||||||
false))))
|
false),
|
||||||
|
SearchResultEntry
|
||||||
|
("thumbnailUrl",
|
||||||
|
"Test1",
|
||||||
|
"in Folder",
|
||||||
|
"http://localhost/nc/index.php/apps/files/?dir=/folder&scrollto=test1.txt",
|
||||||
|
"icon",
|
||||||
|
false))))
|
||||||
vm.onSearchResult(result)
|
vm.onSearchResult(result)
|
||||||
Log_OC.d(this, "loadMore")
|
Log_OC.d(this, "loadMore")
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,4 +231,9 @@ class AppModule {
|
||||||
LocalBroadcastManager localBroadcastManager(Context context) {
|
LocalBroadcastManager localBroadcastManager(Context context) {
|
||||||
return LocalBroadcastManager.getInstance(context);
|
return LocalBroadcastManager.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
FileDataStorageManager storageManager(CurrentAccountProvider currentAccountProvider, Context context) {
|
||||||
|
return new FileDataStorageManager(currentAccountProvider.getCurrentAccount(), context.getContentResolver());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,8 @@ public class FileDataStorageManager {
|
||||||
return ocFile;
|
return ocFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OCFile getFileByLocalPath(String path) {
|
public @Nullable
|
||||||
|
OCFile getFileByLocalPath(String path) {
|
||||||
Cursor cursor = getFileCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
|
Cursor cursor = getFileCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
|
||||||
OCFile ocFile = null;
|
OCFile ocFile = null;
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,31 @@
|
||||||
package com.owncloud.android.ui.adapter
|
package com.owncloud.android.ui.adapter
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
|
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
|
||||||
import com.owncloud.android.databinding.UnifiedSearchItemBinding
|
import com.owncloud.android.databinding.UnifiedSearchItemBinding
|
||||||
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||||
import com.owncloud.android.lib.common.SearchResultEntry
|
import com.owncloud.android.lib.common.SearchResultEntry
|
||||||
|
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
|
||||||
|
|
||||||
class UnifiedSearchItemViewHolder(val binding: UnifiedSearchItemBinding, val context: Context) :
|
class UnifiedSearchItemViewHolder(val binding: UnifiedSearchItemBinding,
|
||||||
|
val context: Context,
|
||||||
|
val storageManager: FileDataStorageManager,
|
||||||
|
val listInterface: UnifiedSearchListInterface) :
|
||||||
SectionedViewHolder(binding.root) {
|
SectionedViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(entry: SearchResultEntry) {
|
fun bind(entry: SearchResultEntry) {
|
||||||
binding.title.text = entry.title
|
binding.title.text = entry.title
|
||||||
binding.subline.text = entry.subline
|
binding.subline.text = entry.subline
|
||||||
|
|
||||||
|
val ocFile = storageManager.getFileByDecryptedRemotePath(entry.remotePath())
|
||||||
|
|
||||||
|
if (ocFile?.isDown == true) {
|
||||||
|
binding.localFileIndicator.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
binding.localFileIndicator.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.unifiedSearchItemLayout.setOnClickListener { listInterface.onSearchResultClicked(entry) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ import com.owncloud.android.operations.RemoteOperationFailedException;
|
||||||
import com.owncloud.android.ui.TextDrawable;
|
import com.owncloud.android.ui.TextDrawable;
|
||||||
import com.owncloud.android.ui.fragment.ExtendedListFragment;
|
import com.owncloud.android.ui.fragment.ExtendedListFragment;
|
||||||
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
|
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
|
||||||
|
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface;
|
||||||
import com.owncloud.android.utils.BitmapUtils;
|
import com.owncloud.android.utils.BitmapUtils;
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.FileSortOrder;
|
import com.owncloud.android.utils.FileSortOrder;
|
||||||
|
@ -122,7 +123,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
|
|
||||||
private List<SearchResult> list = new ArrayList<>();
|
private List<SearchResult> list = new ArrayList<>();
|
||||||
|
|
||||||
private FileDataStorageManager mStorageManager;
|
private FileDataStorageManager storageManager;
|
||||||
private User user;
|
private User user;
|
||||||
private OCFileListFragmentInterface ocFileListFragmentInterface;
|
private OCFileListFragmentInterface ocFileListFragmentInterface;
|
||||||
|
|
||||||
|
@ -140,8 +141,11 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
private boolean showShareAvatar = false;
|
private boolean showShareAvatar = false;
|
||||||
private OCFile highlightedItem;
|
private OCFile highlightedItem;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
private UnifiedSearchListInterface listInterface;
|
||||||
|
|
||||||
public UnifiedSearchListAdapter(Context context) {
|
public UnifiedSearchListAdapter(FileDataStorageManager storageManager,
|
||||||
|
UnifiedSearchListInterface listInterface,
|
||||||
|
Context context) {
|
||||||
// this.ocFileListFragmentInterface = ocFileListFragmentInterface;
|
// this.ocFileListFragmentInterface = ocFileListFragmentInterface;
|
||||||
// this.activity = activity;
|
// this.activity = activity;
|
||||||
// this.preferences = preferences;
|
// this.preferences = preferences;
|
||||||
|
@ -150,6 +154,8 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
// this.gridView = gridView;
|
// this.gridView = gridView;
|
||||||
checkedFiles = new HashSet<>();
|
checkedFiles = new HashSet<>();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.storageManager = storageManager;
|
||||||
|
this.listInterface = listInterface;
|
||||||
|
|
||||||
if (this.user != null) {
|
if (this.user != null) {
|
||||||
AccountManager platformAccountManager = AccountManager.get(this.activity);
|
AccountManager platformAccountManager = AccountManager.get(this.activity);
|
||||||
|
@ -177,7 +183,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
parent,
|
parent,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
return new UnifiedSearchItemViewHolder(binding, context);
|
return new UnifiedSearchItemViewHolder(binding, context, storageManager, listInterface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +302,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
if (mFiles.get(i).getRemoteId().equals(fileId)) {
|
if (mFiles.get(i).getRemoteId().equals(fileId)) {
|
||||||
OCFile file = mFiles.get(i);
|
OCFile file = mFiles.get(i);
|
||||||
file.setEncrypted(encrypted);
|
file.setEncrypted(encrypted);
|
||||||
mStorageManager.saveFile(file);
|
storageManager.saveFile(file);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -628,13 +634,13 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
) {
|
) {
|
||||||
this.onlyOnDevice = onlyOnDevice;
|
this.onlyOnDevice = onlyOnDevice;
|
||||||
|
|
||||||
if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) {
|
if (updatedStorageManager != null && !updatedStorageManager.equals(storageManager)) {
|
||||||
mStorageManager = updatedStorageManager;
|
storageManager = updatedStorageManager;
|
||||||
showShareAvatar = mStorageManager.getCapability(account.getAccountName()).getVersion().isShareesOnDavSupported();
|
showShareAvatar = storageManager.getCapability(account.getAccountName()).getVersion().isShareesOnDavSupported();
|
||||||
this.user = account;
|
this.user = account;
|
||||||
}
|
}
|
||||||
if (mStorageManager != null) {
|
if (storageManager != null) {
|
||||||
mFiles = mStorageManager.getFolderContent(directory, onlyOnDevice);
|
mFiles = storageManager.getFolderContent(directory, onlyOnDevice);
|
||||||
|
|
||||||
if (!preferences.isShowHiddenFilesEnabled()) {
|
if (!preferences.isShowHiddenFilesEnabled()) {
|
||||||
mFiles = filterHiddenFiles(mFiles);
|
mFiles = filterHiddenFiles(mFiles);
|
||||||
|
@ -662,13 +668,13 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
FileDataStorageManager storageManager,
|
FileDataStorageManager storageManager,
|
||||||
@Nullable OCFile folder,
|
@Nullable OCFile folder,
|
||||||
boolean clear) {
|
boolean clear) {
|
||||||
if (storageManager != null && mStorageManager == null) {
|
if (storageManager != null && this.storageManager == null) {
|
||||||
mStorageManager = storageManager;
|
this.storageManager = storageManager;
|
||||||
showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
|
showShareAvatar = this.storageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStorageManager == null) {
|
if (this.storageManager == null) {
|
||||||
mStorageManager = new FileDataStorageManager(user.toPlatformAccount(), activity.getContentResolver());
|
this.storageManager = new FileDataStorageManager(user.toPlatformAccount(), activity.getContentResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
|
@ -689,11 +695,11 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mStorageManager.deleteVirtuals(type);
|
this.storageManager.deleteVirtuals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// early exit
|
// early exit
|
||||||
if (objects.size() > 0 && mStorageManager != null) {
|
if (objects.size() > 0 && this.storageManager != null) {
|
||||||
if (searchType == ExtendedListFragment.SearchType.SHARED_FILTER) {
|
if (searchType == ExtendedListFragment.SearchType.SHARED_FILTER) {
|
||||||
parseShares(objects);
|
parseShares(objects);
|
||||||
} else {
|
} else {
|
||||||
|
@ -734,7 +740,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||||
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.toPlatformAccount());
|
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.toPlatformAccount());
|
||||||
file = mStorageManager.saveFileWithParent(file, activity);
|
file = storageManager.saveFileWithParent(file, activity);
|
||||||
|
|
||||||
ShareType newShareType = ocShare.getShareType();
|
ShareType newShareType = ocShare.getShareType();
|
||||||
if (newShareType == ShareType.PUBLIC_LINK) {
|
if (newShareType == ShareType.PUBLIC_LINK) {
|
||||||
|
@ -748,7 +754,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
file.setSharedWithSharee(true);
|
file.setSharedWithSharee(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mStorageManager.saveFile(file);
|
storageManager.saveFile(file);
|
||||||
|
|
||||||
if (!mFiles.contains(file)) {
|
if (!mFiles.contains(file)) {
|
||||||
mFiles.add(file);
|
mFiles.add(file);
|
||||||
|
@ -759,7 +765,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mStorageManager.saveShares(shares);
|
storageManager.saveShares(shares);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType searchType) {
|
private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType searchType) {
|
||||||
|
@ -797,10 +803,10 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ExtendedListFragment.SearchType.PHOTO_SEARCH == searchType) {
|
if (ExtendedListFragment.SearchType.PHOTO_SEARCH == searchType) {
|
||||||
mStorageManager.saveFile(ocFile);
|
storageManager.saveFile(ocFile);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ocFile = mStorageManager.saveFileWithParent(ocFile, activity);
|
ocFile = storageManager.saveFileWithParent(ocFile, activity);
|
||||||
|
|
||||||
// also sync folder content
|
// also sync folder content
|
||||||
if (ocFile.isFolder()) {
|
if (ocFile.isFolder()) {
|
||||||
|
@ -809,7 +815,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
currentSyncTime,
|
currentSyncTime,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
mStorageManager,
|
storageManager,
|
||||||
user.toPlatformAccount(),
|
user.toPlatformAccount(),
|
||||||
activity);
|
activity);
|
||||||
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
|
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
|
||||||
|
@ -831,7 +837,7 @@ public class UnifiedSearchListAdapter extends SectionedRecyclerViewAdapter<Secti
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
|
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
|
||||||
mStorageManager.saveVirtuals(contentValues);
|
storageManager.saveVirtuals(contentValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {
|
public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {
|
||||||
|
|
|
@ -22,10 +22,8 @@
|
||||||
package com.owncloud.android.ui.asynctasks;
|
package com.owncloud.android.ui.asynctasks;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.nextcloud.client.account.User;
|
import com.nextcloud.client.account.User;
|
||||||
import com.owncloud.android.MainApp;
|
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
@ -36,8 +34,6 @@ import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
|
||||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||||
import com.owncloud.android.ui.fragment.OCFileListFragment;
|
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
|
||||||
import com.owncloud.android.utils.FileStorageUtils;
|
import com.owncloud.android.utils.FileStorageUtils;
|
||||||
|
|
||||||
import static com.owncloud.android.lib.resources.files.SearchRemoteOperation.SearchType.FILE_ID_SEARCH;
|
import static com.owncloud.android.lib.resources.files.SearchRemoteOperation.SearchType.FILE_ID_SEARCH;
|
||||||
|
@ -124,18 +120,6 @@ public class FetchRemoteFileTask extends AsyncTask<Void, Void, String> {
|
||||||
protected void onPostExecute(String message) {
|
protected void onPostExecute(String message) {
|
||||||
super.onPostExecute(message);
|
super.onPostExecute(message);
|
||||||
|
|
||||||
fileDisplayActivity.dismissLoadingDialog();
|
fileDisplayActivity.showFile(message);
|
||||||
|
|
||||||
OCFileListFragment listOfFiles = fileDisplayActivity.getListOfFilesFragment();
|
|
||||||
if (listOfFiles != null) {
|
|
||||||
if (TextUtils.isEmpty(message)) {
|
|
||||||
OCFile temp = fileDisplayActivity.getFile();
|
|
||||||
fileDisplayActivity.setFile(fileDisplayActivity.getCurrentDir());
|
|
||||||
listOfFiles.listDirectory(fileDisplayActivity.getCurrentDir(), temp, MainApp.isOnlyOnDevice(), false);
|
|
||||||
fileDisplayActivity.updateActionBarTitleAndHomeButton(null);
|
|
||||||
} else {
|
|
||||||
DisplayUtils.showSnackMessage(listOfFiles.getView(), message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,19 @@ import androidx.annotation.VisibleForTesting
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import com.nextcloud.client.account.CurrentAccountProvider
|
||||||
|
import com.nextcloud.client.core.AsyncRunner
|
||||||
import com.nextcloud.client.di.Injectable
|
import com.nextcloud.client.di.Injectable
|
||||||
import com.nextcloud.client.di.ViewModelFactory
|
import com.nextcloud.client.di.ViewModelFactory
|
||||||
|
import com.nextcloud.client.network.ClientFactory
|
||||||
import com.owncloud.android.databinding.ListFragmentBinding
|
import com.owncloud.android.databinding.ListFragmentBinding
|
||||||
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||||
import com.owncloud.android.lib.common.SearchResult
|
import com.owncloud.android.lib.common.SearchResult
|
||||||
|
import com.owncloud.android.lib.common.SearchResultEntry
|
||||||
|
import com.owncloud.android.ui.activities.GetRemoteFileTask
|
||||||
|
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||||
import com.owncloud.android.ui.adapter.UnifiedSearchListAdapter
|
import com.owncloud.android.ui.adapter.UnifiedSearchListAdapter
|
||||||
|
import com.owncloud.android.ui.interfaces.UnifiedSearchListInterface
|
||||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -40,7 +48,7 @@ import javax.inject.Inject
|
||||||
* Starts query to all capable unified search providers and displays them Opens result in our app, redirect to other
|
* Starts query to all capable unified search providers and displays them Opens result in our app, redirect to other
|
||||||
* apps, if installed, or opens browser
|
* apps, if installed, or opens browser
|
||||||
*/
|
*/
|
||||||
class UnifiedSearchFragment : Fragment(), Injectable {
|
class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface {
|
||||||
private lateinit var adapter: UnifiedSearchListAdapter
|
private lateinit var adapter: UnifiedSearchListAdapter
|
||||||
private var _binding: ListFragmentBinding? = null
|
private var _binding: ListFragmentBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
@ -49,6 +57,18 @@ class UnifiedSearchFragment : Fragment(), Injectable {
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var vmFactory: ViewModelFactory
|
lateinit var vmFactory: ViewModelFactory
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var storageManager: FileDataStorageManager
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var runner: AsyncRunner
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var currentAccountProvider: CurrentAccountProvider
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var clientFactory: ClientFactory
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
vm = ViewModelProvider(this, vmFactory).get(UnifiedSearchViewModel::class.java)
|
vm = ViewModelProvider(this, vmFactory).get(UnifiedSearchViewModel::class.java)
|
||||||
|
@ -76,7 +96,7 @@ class UnifiedSearchFragment : Fragment(), Injectable {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val gridLayoutManager = GridLayoutManager(requireContext(), 1)
|
val gridLayoutManager = GridLayoutManager(requireContext(), 1)
|
||||||
adapter = UnifiedSearchListAdapter(requireContext())
|
adapter = UnifiedSearchListAdapter(storageManager, this, requireContext())
|
||||||
adapter.setLayoutManager(gridLayoutManager)
|
adapter.setLayoutManager(gridLayoutManager)
|
||||||
binding.listRoot.layoutManager = gridLayoutManager
|
binding.listRoot.layoutManager = gridLayoutManager
|
||||||
binding.listRoot.adapter = adapter
|
binding.listRoot.adapter = adapter
|
||||||
|
@ -92,6 +112,32 @@ class UnifiedSearchFragment : Fragment(), Injectable {
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showFile(result: GetRemoteFileTask.Result) {
|
||||||
|
activity.let {
|
||||||
|
if (activity is FileDisplayActivity) {
|
||||||
|
val fda = activity as FileDisplayActivity
|
||||||
|
fda.file = result.file
|
||||||
|
fda.showFile("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSearchResultClicked(searchResultEntry: SearchResultEntry) {
|
||||||
|
openFile(searchResultEntry.remotePath())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openFile(fileUrl: String) {
|
||||||
|
val user = currentAccountProvider.user
|
||||||
|
val task = GetRemoteFileTask(
|
||||||
|
requireContext(),
|
||||||
|
fileUrl,
|
||||||
|
clientFactory.create(currentAccountProvider.user),
|
||||||
|
FileDataStorageManager(user.toPlatformAccount(), requireContext().contentResolver),
|
||||||
|
user
|
||||||
|
)
|
||||||
|
runner.postQuickTask(task, onResult = this::showFile)
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun onSearchResultChanged(list: MutableList<SearchResult>) {
|
fun onSearchResultChanged(list: MutableList<SearchResult>) {
|
||||||
binding.emptyList.emptyListView.visibility = View.GONE
|
binding.emptyList.emptyListView.visibility = View.GONE
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Nextcloud Android client application
|
||||||
|
*
|
||||||
|
* @author Tobias Kaminsky
|
||||||
|
* Copyright (C) 2020 Tobias Kaminsky
|
||||||
|
* Copyright (C) 2020 Nextcloud GmbH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.owncloud.android.ui.interfaces
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.SearchResultEntry
|
||||||
|
|
||||||
|
interface UnifiedSearchListInterface {
|
||||||
|
|
||||||
|
fun onSearchResultClicked(searchResultEntry: SearchResultEntry)
|
||||||
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package com.owncloud.android.ui.unifiedsearch
|
package com.owncloud.android.ui.unifiedsearch
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
@ -27,8 +28,10 @@ import com.nextcloud.client.account.CurrentAccountProvider
|
||||||
import com.nextcloud.client.core.AsyncRunner
|
import com.nextcloud.client.core.AsyncRunner
|
||||||
import com.nextcloud.client.network.ClientFactory
|
import com.nextcloud.client.network.ClientFactory
|
||||||
import com.owncloud.android.R
|
import com.owncloud.android.R
|
||||||
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||||
import com.owncloud.android.lib.common.SearchResult
|
import com.owncloud.android.lib.common.SearchResult
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC
|
import com.owncloud.android.lib.common.utils.Log_OC
|
||||||
|
import com.owncloud.android.ui.activities.GetRemoteFileTask
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
|
@ -38,6 +41,7 @@ class UnifiedSearchViewModel() : ViewModel() {
|
||||||
lateinit var runner: AsyncRunner
|
lateinit var runner: AsyncRunner
|
||||||
lateinit var clientFactory: ClientFactory
|
lateinit var clientFactory: ClientFactory
|
||||||
lateinit var resources: Resources
|
lateinit var resources: Resources
|
||||||
|
lateinit var context: Context
|
||||||
|
|
||||||
private lateinit var repository: IUnifiedSearchRepository
|
private lateinit var repository: IUnifiedSearchRepository
|
||||||
private var loadingStarted: Boolean = false
|
private var loadingStarted: Boolean = false
|
||||||
|
@ -53,11 +57,13 @@ class UnifiedSearchViewModel() : ViewModel() {
|
||||||
currentAccountProvider: CurrentAccountProvider,
|
currentAccountProvider: CurrentAccountProvider,
|
||||||
runner: AsyncRunner,
|
runner: AsyncRunner,
|
||||||
clientFactory: ClientFactory,
|
clientFactory: ClientFactory,
|
||||||
resources: Resources) : this() {
|
resources: Resources,
|
||||||
|
context: Context) : this() {
|
||||||
this.currentAccountProvider = currentAccountProvider
|
this.currentAccountProvider = currentAccountProvider
|
||||||
this.runner = runner
|
this.runner = runner
|
||||||
this.clientFactory = clientFactory
|
this.clientFactory = clientFactory
|
||||||
this.resources = resources
|
this.resources = resources
|
||||||
|
this.context = context
|
||||||
|
|
||||||
repository = UnifiedSearchRemoteRepository(
|
repository = UnifiedSearchRemoteRepository(
|
||||||
clientFactory,
|
clientFactory,
|
||||||
|
@ -90,20 +96,20 @@ class UnifiedSearchViewModel() : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// fun openFile(fileUrl: String) {
|
fun openFile(fileUrl: String) {
|
||||||
// if (isLoading.value == false) {
|
if (isLoading.value == false) {
|
||||||
// (isLoading as MutableLiveData).value = true
|
isLoading.value = true
|
||||||
// val user = currentUser.user
|
val user = currentAccountProvider.user
|
||||||
// val task = GetRemoteFileTask(
|
val task = GetRemoteFileTask(
|
||||||
// context,
|
context,
|
||||||
// fileUrl,
|
fileUrl,
|
||||||
// clientFactory.create(currentUser.user),
|
clientFactory.create(currentAccountProvider.user),
|
||||||
// FileDataStorageManager(user.toPlatformAccount(), contentResolver),
|
FileDataStorageManager(user.toPlatformAccount(), context.contentResolver),
|
||||||
// user
|
user
|
||||||
// )
|
)
|
||||||
// runner.postQuickTask(task, onResult = this::onFileRequestResult)
|
runner.postQuickTask(task, onResult = this::onFileRequestResult)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
open fun clearError() {
|
open fun clearError() {
|
||||||
error.value = ""
|
error.value = ""
|
||||||
|
@ -144,12 +150,13 @@ class UnifiedSearchViewModel() : ViewModel() {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// private fun onFileRequestResult(result: GetRemoteFileTask.Result) {
|
private fun onFileRequestResult(result: GetRemoteFileTask.Result) {
|
||||||
// (isLoading as MutableLiveData).value = false
|
isLoading.value = false
|
||||||
// if (result.success) {
|
if (result.success) {
|
||||||
// (file as MutableLiveData).value = result.file
|
// unifiedSearchFragment.showFile(result.file)
|
||||||
// } else {
|
//(file as MutableLiveData).value = result.file
|
||||||
// (file as MutableLiveData).value = null
|
} else {
|
||||||
// }
|
error.value = "Error showing search result"
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/upload_list_item_layout"
|
android:id="@+id/unified_search_item_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/standard_list_item_size"
|
android:layout_height="@dimen/standard_list_item_size"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
|
@ -66,22 +66,12 @@
|
||||||
android:contentDescription="@string/downloader_download_succeeded_ticker"
|
android:contentDescription="@string/downloader_download_succeeded_ticker"
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
android:src="@drawable/ic_synced"
|
android:src="@drawable/ic_synced"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/thumbnail_layout"
|
app:layout_constraintBottom_toBottomOf="@+id/thumbnail_layout"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/thumbnail_layout"
|
app:layout_constraintEnd_toEndOf="@+id/thumbnail_layout"
|
||||||
app:layout_constraintStart_toEndOf="@+id/thumbnail_layout"
|
app:layout_constraintStart_toEndOf="@+id/thumbnail_layout"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/thumbnail_layout" />
|
app:layout_constraintTop_toBottomOf="@+id/thumbnail_layout" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/favorite_action"
|
|
||||||
android:layout_width="@dimen/list_item_favorite_action_layout_width"
|
|
||||||
android:layout_height="@dimen/list_item_favorite_action_layout_height"
|
|
||||||
android:contentDescription="@string/favorite"
|
|
||||||
android:src="@drawable/favorite"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/thumbnail_layout"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/thumbnail_layout"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/thumbnail_layout"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/thumbnail_layout" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
Loading…
Reference in a new issue