Search in sources :

Example 1 with GetRemoteActivitiesOperation

use of com.owncloud.android.lib.resources.activities.GetRemoteActivitiesOperation in project android by nextcloud.

the class ActivitiesListActivity method fetchAndSetData.

/**
 * @param pageUrl String
 */
private void fetchAndSetData(String pageUrl) {
    final Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
    final Context context = MainApp.getAppContext();
    Thread t = new Thread(() -> {
        OwnCloudAccount ocAccount;
        try {
            ocAccount = new OwnCloudAccount(currentAccount, context);
            ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, MainApp.getAppContext());
            ownCloudClient.setOwnCloudVersion(AccountUtils.getServerVersion(currentAccount));
            isLoadingActivities = true;
            runOnUiThread(() -> setIndeterminate(isLoadingActivities));
            GetRemoteActivitiesOperation getRemoteNotificationOperation = new GetRemoteActivitiesOperation();
            if (pageUrl != null) {
                getRemoteNotificationOperation.setNextUrl(pageUrl);
            }
            Log_OC.d(TAG, "BEFORE getRemoteActivitiesOperation.execute");
            final RemoteOperationResult result = getRemoteNotificationOperation.execute(ownCloudClient);
            if (result.isSuccess() && result.getData() != null) {
                final ArrayList<Object> data = result.getData();
                final ArrayList<Object> activities = (ArrayList) data.get(0);
                nextPageUrl = (String) data.get(1);
                runOnUiThread(() -> {
                    populateList(activities, ownCloudClient, pageUrl == null);
                    if (activities.size() > 0) {
                        swipeEmptyListRefreshLayout.setVisibility(View.GONE);
                        swipeListRefreshLayout.setVisibility(View.VISIBLE);
                    } else {
                        setEmptyContent(noResultsHeadline, noResultsMessage);
                        swipeListRefreshLayout.setVisibility(View.GONE);
                        swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
                    }
                    isLoadingActivities = false;
                    setIndeterminate(isLoadingActivities);
                });
            } else {
                Log_OC.d(TAG, result.getLogMessage());
                // show error
                String logMessage = result.getLogMessage();
                if (result.getHttpCode() == 304) {
                    logMessage = noResultsMessage;
                }
                final String finalLogMessage = logMessage;
                runOnUiThread(() -> {
                    setEmptyContent(noResultsHeadline, finalLogMessage);
                    isLoadingActivities = false;
                    setIndeterminate(isLoadingActivities);
                });
            }
            hideRefreshLayoutLoader();
        } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
            Log_OC.e(TAG, "Account not found", e);
        } catch (IOException e) {
            Log_OC.e(TAG, "IO error", e);
        } catch (OperationCanceledException e) {
            Log_OC.e(TAG, "Operation has been canceled", e);
        } catch (AuthenticatorException e) {
            Log_OC.e(TAG, "Authentication Exception", e);
        }
    });
    t.start();
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) GetRemoteActivitiesOperation(com.owncloud.android.lib.resources.activities.GetRemoteActivitiesOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OperationCanceledException(android.accounts.OperationCanceledException) ArrayList(java.util.ArrayList) AccountUtils(com.owncloud.android.authentication.AccountUtils) AuthenticatorException(android.accounts.AuthenticatorException) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) BindString(butterknife.BindString) IOException(java.io.IOException) RichObject(com.owncloud.android.lib.resources.activities.models.RichObject)

Aggregations

Account (android.accounts.Account)1 AuthenticatorException (android.accounts.AuthenticatorException)1 OperationCanceledException (android.accounts.OperationCanceledException)1 Context (android.content.Context)1 BindString (butterknife.BindString)1 AccountUtils (com.owncloud.android.authentication.AccountUtils)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 GetRemoteActivitiesOperation (com.owncloud.android.lib.resources.activities.GetRemoteActivitiesOperation)1 RichObject (com.owncloud.android.lib.resources.activities.models.RichObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1