Search in sources :

Example 1 with ToggleFavoriteRemoteOperation

use of com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation in project android by nextcloud.

the class OCFileListFragment method onMessageEvent.

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FavoriteEvent event) {
    try {
        User user = accountManager.getUser();
        OwnCloudClient client = clientFactory.create(user);
        ToggleFavoriteRemoteOperation toggleFavoriteOperation = new ToggleFavoriteRemoteOperation(event.shouldFavorite, event.remotePath);
        RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(client);
        if (remoteOperationResult.isSuccess()) {
            boolean removeFromList = currentSearchType == SearchType.FAVORITE_SEARCH && !event.shouldFavorite;
            mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite, removeFromList);
        }
    } catch (ClientFactory.CreationException e) {
        Log_OC.e(TAG, "Error processing event", e);
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ClientFactory(com.nextcloud.client.network.ClientFactory) ToggleFavoriteRemoteOperation(com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with ToggleFavoriteRemoteOperation

use of com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation in project android by nextcloud.

the class FileDetailFragment method onMessageEvent.

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(FavoriteEvent event) {
    try {
        User user = accountManager.getUser();
        OwnCloudClient client = clientFactory.create(user);
        ToggleFavoriteRemoteOperation toggleFavoriteOperation = new ToggleFavoriteRemoteOperation(event.shouldFavorite, event.remotePath);
        RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(client);
        if (remoteOperationResult.isSuccess()) {
            getFile().setFavorite(event.shouldFavorite);
            OCFile file = storageManager.getFileByEncryptedRemotePath(event.remotePath);
            file.setFavorite(event.shouldFavorite);
            storageManager.saveFile(file);
        }
    } catch (ClientFactory.CreationException e) {
        Log_OC.e(TAG, "Error processing event", e);
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ClientFactory(com.nextcloud.client.network.ClientFactory) ToggleFavoriteRemoteOperation(com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

User (com.nextcloud.client.account.User)2 ClientFactory (com.nextcloud.client.network.ClientFactory)2 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 ToggleFavoriteRemoteOperation (com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation)2 Subscribe (org.greenrobot.eventbus.Subscribe)2 OCFile (com.owncloud.android.datamodel.OCFile)1