Search in sources :

Example 1 with ToolbarActivity

use of com.owncloud.android.ui.activity.ToolbarActivity 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);
}
Also used : ToolbarActivity(com.owncloud.android.ui.activity.ToolbarActivity) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) SearchOperation(com.owncloud.android.lib.resources.files.SearchOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) GetRemoteSharesOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with ToolbarActivity

use of com.owncloud.android.ui.activity.ToolbarActivity in project android by nextcloud.

the class OCFileListFragment method handleSearchEvent.

private void handleSearchEvent(SearchEvent event) {
    if (SearchRemoteOperation.SearchType.PHOTO_SEARCH == event.getSearchType()) {
        return;
    }
    prepareCurrentSearch(event);
    searchFragment = true;
    setEmptyListLoadingMessage();
    mAdapter.setData(new ArrayList<>(), SearchType.NO_SEARCH, mContainerActivity.getStorageManager(), mFile, true);
    setFabVisible(false);
    Runnable switchViewsRunnable = () -> {
        if (isGridViewPreferred(mFile) && !isGridEnabled()) {
            switchToGridView();
        } else if (!isGridViewPreferred(mFile) && isGridEnabled()) {
            switchToListView();
        }
    };
    new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
    final User currentUser = accountManager.getUser();
    final RemoteOperation remoteOperation;
    if (currentSearchType != SearchType.SHARED_FILTER) {
        boolean searchOnlyFolders = false;
        if (getArguments() != null && getArguments().getBoolean(ARG_SEARCH_ONLY_FOLDER, false)) {
            searchOnlyFolders = true;
        }
        OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(currentUser.getAccountName());
        remoteOperation = new SearchRemoteOperation(event.getSearchQuery(), event.getSearchType(), searchOnlyFolders, ocCapability);
    } else {
        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.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ToolbarActivity(com.owncloud.android.ui.activity.ToolbarActivity) ToggleEncryptionRemoteOperation(com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation) RichWorkspaceDirectEditingRemoteOperation(com.nextcloud.android.lib.richWorkspace.RichWorkspaceDirectEditingRemoteOperation) GetSharesRemoteOperation(com.owncloud.android.lib.resources.shares.GetSharesRemoteOperation) ToggleFavoriteRemoteOperation(com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) User(com.nextcloud.client.account.User) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Handler(android.os.Handler) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) GetSharesRemoteOperation(com.owncloud.android.lib.resources.shares.GetSharesRemoteOperation) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Handler (android.os.Handler)2 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)2 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 ToolbarActivity (com.owncloud.android.ui.activity.ToolbarActivity)2 Account (android.accounts.Account)1 AsyncTask (android.os.AsyncTask)1 RichWorkspaceDirectEditingRemoteOperation (com.nextcloud.android.lib.richWorkspace.RichWorkspaceDirectEditingRemoteOperation)1 User (com.nextcloud.client.account.User)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 ToggleEncryptionRemoteOperation (com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation)1 SearchOperation (com.owncloud.android.lib.resources.files.SearchOperation)1 SearchRemoteOperation (com.owncloud.android.lib.resources.files.SearchRemoteOperation)1 ToggleFavoriteRemoteOperation (com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation)1 GetRemoteSharesOperation (com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation)1 GetSharesRemoteOperation (com.owncloud.android.lib.resources.shares.GetSharesRemoteOperation)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Subscribe (org.greenrobot.eventbus.Subscribe)1