use of com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation in project android by nextcloud.
the class OCFileListFragment method onMessageEvent.
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(final SearchEvent event) {
searchFragment = true;
setEmptyListLoadingMessage();
mAdapter.setData(new ArrayList<>(), SearchType.NO_SEARCH, mContainerActivity.getStorageManager(), mFile);
setFabEnabled(false);
if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR)) {
unsetAllMenuItems(false);
} else if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_DRAWER)) {
unsetAllMenuItems(true);
}
if (bottomNavigationView != null && searchEvent != null) {
switch(currentSearchType) {
case FAVORITE_SEARCH:
DisplayUtils.setBottomBarItem(bottomNavigationView, R.id.nav_bar_favorites);
break;
case PHOTO_SEARCH:
DisplayUtils.setBottomBarItem(bottomNavigationView, R.id.nav_bar_photos);
break;
default:
DisplayUtils.setBottomBarItem(bottomNavigationView, -1);
break;
}
}
Runnable switchViewsRunnable = new Runnable() {
@Override
public void run() {
if (isGridViewPreferred(mFile) && !isGridEnabled()) {
switchToGridView();
} else if (!isGridViewPreferred(mFile) && isGridEnabled()) {
switchToListView();
}
}
};
if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
switchToGridView();
}
});
} else if (currentSearchType.equals(SearchType.NO_SEARCH) || currentSearchType.equals(SearchType.REGULAR_FILTER)) {
new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
} else {
new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
}
final RemoteOperation remoteOperation;
if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
boolean searchOnlyFolders = false;
if (getArguments() != null && getArguments().getBoolean(ARG_SEARCH_ONLY_FOLDER, false)) {
searchOnlyFolders = true;
}
remoteOperation = new SearchOperation(event.getSearchQuery(), event.getSearchType(), searchOnlyFolders);
} else {
remoteOperation = new GetRemoteSharesOperation();
}
final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
remoteOperationAsyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
if (getContext() != null && !isCancelled()) {
RemoteOperationResult remoteOperationResult = remoteOperation.execute(currentAccount, getContext());
FileDataStorageManager storageManager = null;
if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) {
storageManager = mContainerActivity.getStorageManager();
}
if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null && !isCancelled() && searchFragment) {
if (remoteOperationResult.getData() == null || remoteOperationResult.getData().size() == 0) {
setEmptyView(event);
} else {
mAdapter.setData(remoteOperationResult.getData(), currentSearchType, storageManager, mFile);
}
final ToolbarActivity fileDisplayActivity = (ToolbarActivity) getActivity();
if (fileDisplayActivity != null) {
fileDisplayActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (fileDisplayActivity != null) {
fileDisplayActivity.setIndeterminate(false);
}
}
});
}
}
return remoteOperationResult.isSuccess();
} else {
return false;
}
}
@Override
protected void onPostExecute(Object o) {
if (!isCancelled()) {
mAdapter.notifyDataSetChanged();
}
}
};
remoteOperationAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, true);
}
Aggregations