use of com.owncloud.android.lib.resources.files.ToggleFavoriteOperation in project android by nextcloud.
the class OCFileListFragment method onMessageEvent.
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FavoriteEvent event) {
Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
OwnCloudAccount ocAccount = null;
AccountManager mAccountMgr = AccountManager.get(getActivity());
try {
ocAccount = new OwnCloudAccount(currentAccount, MainApp.getAppContext());
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, MainApp.getAppContext());
String userId = mAccountMgr.getUserData(currentAccount, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
if (TextUtils.isEmpty(userId)) {
userId = mClient.getCredentials().getUsername();
}
ToggleFavoriteOperation toggleFavoriteOperation = new ToggleFavoriteOperation(event.shouldFavorite, event.remotePath, userId);
RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(mClient);
if (remoteOperationResult.isSuccess()) {
mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite);
}
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.e(TAG, "Account not found", e);
} catch (AuthenticatorException e) {
Log_OC.e(TAG, "Authentication failed", e);
} catch (IOException e) {
Log_OC.e(TAG, "IO error", e);
} catch (OperationCanceledException e) {
Log_OC.e(TAG, "Operation has been canceled", e);
}
}
Aggregations