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();
}
Aggregations