|
@@ -77,7 +77,6 @@ import com.owncloud.android.ui.activity.FileActivity;
|
|
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
|
|
import com.owncloud.android.ui.activity.FolderPickerActivity;
|
|
|
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
|
|
|
-import com.owncloud.android.ui.activity.ToolbarActivity;
|
|
|
import com.owncloud.android.ui.activity.UploadFilesActivity;
|
|
|
import com.owncloud.android.ui.adapter.OCFileListAdapter;
|
|
|
import com.owncloud.android.ui.dialog.ChooseRichDocumentsTemplateDialogFragment;
|
|
@@ -114,6 +113,7 @@ import org.greenrobot.eventbus.Subscribe;
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.lang.ref.WeakReference;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
@@ -1510,6 +1510,87 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
handleSearchEvent(event);
|
|
|
}
|
|
|
|
|
|
+ private static class SearchAsyncTask extends AsyncTask<Void, Void, Boolean> {
|
|
|
+
|
|
|
+ private final WeakReference<FileFragment.ContainerActivity> activityReference;
|
|
|
+ private final WeakReference<OCFileListFragment> fragmentReference;
|
|
|
+ private final RemoteOperation remoteOperation;
|
|
|
+ private final User currentUser;
|
|
|
+ private final SearchEvent event;
|
|
|
+
|
|
|
+ private SearchAsyncTask(final FileFragment.ContainerActivity containerActivity, final OCFileListFragment fragment, final RemoteOperation remoteOperation, final User currentUser, final SearchEvent event) {
|
|
|
+ this.activityReference = new WeakReference<>(containerActivity);
|
|
|
+ this.fragmentReference = new WeakReference<>(fragment);
|
|
|
+ this.remoteOperation = remoteOperation;
|
|
|
+ this.currentUser = currentUser;
|
|
|
+ this.event = event;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPreExecute() {
|
|
|
+ final OCFileListFragment fragment = fragmentReference.get();
|
|
|
+ if (fragment != null) {
|
|
|
+ new Handler(Looper.getMainLooper()).post(() -> {
|
|
|
+ fragment.setLoading(true);
|
|
|
+ fragment.setEmptyListLoadingMessage();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Boolean doInBackground(Void... voids) {
|
|
|
+ final OCFileListFragment fragment = fragmentReference.get();
|
|
|
+ if (fragment == null || isCancelled() || fragment.getContext() == null) {
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ fragment.setTitle();
|
|
|
+ RemoteOperationResult remoteOperationResult = remoteOperation.execute(
|
|
|
+ currentUser.toPlatformAccount(), fragment.getContext());
|
|
|
+
|
|
|
+ FileDataStorageManager storageManager = getFileDataStorageManager();
|
|
|
+
|
|
|
+ if (remoteOperationResult.isSuccess() && remoteOperationResult.getResultData() != null
|
|
|
+ && !isCancelled() && fragment.searchFragment) {
|
|
|
+ fragment.searchEvent = event;
|
|
|
+
|
|
|
+ if (remoteOperationResult.getResultData() == null || ((List) remoteOperationResult.getResultData()).isEmpty()) {
|
|
|
+ fragment.setEmptyView(event);
|
|
|
+ } else {
|
|
|
+ fragment.mAdapter.setData(((RemoteOperationResult<List>) remoteOperationResult).getResultData(),
|
|
|
+ fragment.currentSearchType,
|
|
|
+ storageManager,
|
|
|
+ fragment.mFile,
|
|
|
+ true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return remoteOperationResult.isSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private FileDataStorageManager getFileDataStorageManager() {
|
|
|
+ FileDataStorageManager storageManager = null;
|
|
|
+ final FileFragment.ContainerActivity containerActivity = activityReference.get();
|
|
|
+ if (containerActivity != null && containerActivity.getStorageManager() != null) {
|
|
|
+ storageManager = containerActivity.getStorageManager();
|
|
|
+ }
|
|
|
+ return storageManager;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPostExecute(Boolean bool) {
|
|
|
+ final OCFileListFragment fragment = fragmentReference.get();
|
|
|
+ if (fragment != null) {
|
|
|
+ fragment.setLoading(false);
|
|
|
+ if (!isCancelled()) {
|
|
|
+ fragment.mAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void handleSearchEvent(SearchEvent event) {
|
|
|
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH == event.getSearchType()) {
|
|
|
return;
|
|
@@ -1556,56 +1637,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
remoteOperation = new GetSharesRemoteOperation();
|
|
|
}
|
|
|
|
|
|
- remoteOperationAsyncTask = new AsyncTask<Void, Void, Boolean>() {
|
|
|
- @Override
|
|
|
- protected Boolean doInBackground(Void... voids) {
|
|
|
- setTitle();
|
|
|
- if (getContext() != null && !isCancelled()) {
|
|
|
- RemoteOperationResult remoteOperationResult = remoteOperation.execute(
|
|
|
- currentUser.toPlatformAccount(), getContext());
|
|
|
-
|
|
|
- FileDataStorageManager storageManager = null;
|
|
|
- if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) {
|
|
|
- storageManager = mContainerActivity.getStorageManager();
|
|
|
- }
|
|
|
-
|
|
|
- if (remoteOperationResult.isSuccess() && remoteOperationResult.getResultData() != null
|
|
|
- && !isCancelled() && searchFragment) {
|
|
|
- searchEvent = event;
|
|
|
-
|
|
|
- if (remoteOperationResult.getResultData() == null || ((List) remoteOperationResult.getResultData()).isEmpty()) {
|
|
|
- setEmptyView(event);
|
|
|
- } else {
|
|
|
- mAdapter.setData(((RemoteOperationResult<List>) remoteOperationResult).getResultData(),
|
|
|
- currentSearchType,
|
|
|
- storageManager,
|
|
|
- mFile,
|
|
|
- true);
|
|
|
- }
|
|
|
-
|
|
|
- final ToolbarActivity fileDisplayActivity = (ToolbarActivity) getActivity();
|
|
|
- if (fileDisplayActivity != null) {
|
|
|
- fileDisplayActivity.runOnUiThread(() -> {
|
|
|
- if (fileDisplayActivity != null) {
|
|
|
- setLoading(false);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return remoteOperationResult.isSuccess();
|
|
|
- } else {
|
|
|
- return Boolean.FALSE;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- protected void onPostExecute(Boolean bool) {
|
|
|
- if (!isCancelled()) {
|
|
|
- mAdapter.notifyDataSetChanged();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
+ remoteOperationAsyncTask = new SearchAsyncTask(mContainerActivity, this, remoteOperation, currentUser, event);
|
|
|
|
|
|
remoteOperationAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
}
|