Search in sources :

Example 21 with OwnCloudClient

use of com.owncloud.android.lib.common.OwnCloudClient in project android by nextcloud.

the class OCFileListFragment method onMessageEvent.

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(EncryptionEvent event) {
    final User user = accountManager.getUser();
    try {
        OwnCloudClient client = clientFactory.create(user);
        RemoteOperationResult remoteOperationResult = new ToggleEncryptionRemoteOperation(event.localId, event.remotePath, event.shouldBeEncrypted).execute(client);
        if (remoteOperationResult.isSuccess()) {
            mAdapter.setEncryptionAttributeForItemID(event.remoteId, event.shouldBeEncrypted);
            // check if keys are stored
            ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(requireContext().getContentResolver());
            String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
            String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
            if (publicKey.isEmpty() || privateKey.isEmpty()) {
                Log_OC.d(TAG, "no public key for " + user.getAccountName());
                FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
                int position = mAdapter.getItemPosition(storageManager.getFileByRemoteId(event.remoteId));
                SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
                dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
                dialog.show(getParentFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
            }
        } else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
            Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_folder_not_empty, Snackbar.LENGTH_LONG).show();
        } else {
            Snackbar.make(getRecyclerView(), R.string.common_error_unknown, Snackbar.LENGTH_LONG).show();
        }
    } catch (ClientFactory.CreationException e) {
        Log_OC.e(TAG, "Cannot create client", e);
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ClientFactory(com.nextcloud.client.network.ClientFactory) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) SetupEncryptionDialogFragment(com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment) ToggleEncryptionRemoteOperation(com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)21 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)15 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)12 Account (android.accounts.Account)9 IOException (java.io.IOException)6 Context (android.content.Context)5 OwnCloudCredentials (com.owncloud.android.lib.common.OwnCloudCredentials)5 AccountManager (android.accounts.AccountManager)4 AuthenticatorException (android.accounts.AuthenticatorException)4 OperationCanceledException (android.accounts.OperationCanceledException)4 User (com.nextcloud.client.account.User)4 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)4 OCFile (com.owncloud.android.datamodel.OCFile)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 Gson (com.google.gson.Gson)3 ClientFactory (com.nextcloud.client.network.ClientFactory)3 AccountUtils (com.owncloud.android.authentication.AccountUtils)3 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)3 PushConfigurationState (com.owncloud.android.datamodel.PushConfigurationState)3