From 479fd873455f29cc815a865b6e82e3d0a2bda5f1 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 8 Jan 2025 13:51:30 +0100 Subject: [PATCH] fix Signed-off-by: alperozturk --- .../ui/fragment/OCFileListFragment.java | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 7e4be1179a03..c2cd275613b0 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -132,7 +132,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.RejectedExecutionException; import javax.inject.Inject; @@ -1892,38 +1891,45 @@ protected RemoteOperation getSearchRemoteOperation(final User currentUser, final ocCapability); } - @Subscribe(threadMode = ThreadMode.BACKGROUND) + @Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(EncryptionEvent event) { - final User user = accountManager.getUser(); + new Thread(() -> {{ + final User user = accountManager.getUser(); - // check if keys are stored - String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY); - String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY); + // check if keys are stored + String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY); + String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY); - FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); - OCFile file = storageManager.getFileByRemoteId(event.getRemoteId()); + FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); + OCFile file = storageManager.getFileByRemoteId(event.getRemoteId()); - if (publicKey.isEmpty() || privateKey.isEmpty()) { - Log_OC.d(TAG, "no public key for " + user.getAccountName()); + if (publicKey.isEmpty() || privateKey.isEmpty()) { + Log_OC.d(TAG, "no public key for " + user.getAccountName()); - int position = -1; - if (file != null) { - position = mAdapter.getItemPosition(file); + int position; + if (file != null) { + position = mAdapter.getItemPosition(file); + } else { + position = -1; + } + + requireActivity().runOnUiThread(() -> { + SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position); + dialog.setTargetFragment(OCFileListFragment.this, SETUP_ENCRYPTION_REQUEST_CODE); + dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG); + }); + } else { + // TODO E2E: if encryption fails, to not set it as encrypted! + encryptFolder(file, + event.getLocalId(), + event.getRemoteId(), + event.getRemotePath(), + event.getShouldBeEncrypted(), + publicKey, + privateKey, + storageManager); } - SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position); - dialog.setTargetFragment(this, SETUP_ENCRYPTION_REQUEST_CODE); - dialog.show(getParentFragmentManager(), SETUP_ENCRYPTION_DIALOG_TAG); - } else { - // TODO E2E: if encryption fails, to not set it as encrypted! - encryptFolder(file, - event.getLocalId(), - event.getRemoteId(), - event.getRemotePath(), - event.getShouldBeEncrypted(), - publicKey, - privateKey, - storageManager); - } + }}).start(); } private void encryptFolder(OCFile folder, @@ -1985,15 +1991,15 @@ private void encryptFolder(OCFile folder, throw new IllegalArgumentException("Unknown E2E version"); } - mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted); + requireActivity().runOnUiThread(() -> mAdapter.setEncryptionAttributeForItemID(remoteId, shouldBeEncrypted)); } else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) { - Snackbar.make(getRecyclerView(), - R.string.end_to_end_encryption_folder_not_empty, - Snackbar.LENGTH_LONG).show(); + requireActivity().runOnUiThread(() -> 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(); + requireActivity().runOnUiThread(() -> Snackbar.make(getRecyclerView(), + R.string.common_error_unknown, + Snackbar.LENGTH_LONG).show()); } } catch (Throwable e) {