|
51 | 51 | import com.owncloud.android.datamodel.FileDataStorageManager; |
52 | 52 | import com.owncloud.android.datamodel.OCFile; |
53 | 53 | import com.owncloud.android.datamodel.SharesType; |
| 54 | +import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile; |
54 | 55 | import com.owncloud.android.lib.common.OwnCloudAccount; |
| 56 | +import com.owncloud.android.lib.common.OwnCloudClient; |
55 | 57 | import com.owncloud.android.lib.common.operations.RemoteOperationResult; |
56 | 58 | import com.owncloud.android.lib.common.utils.Log_OC; |
57 | 59 | import com.owncloud.android.lib.resources.shares.OCShare; |
58 | 60 | import com.owncloud.android.lib.resources.shares.ShareType; |
59 | 61 | import com.owncloud.android.lib.resources.status.NextcloudVersion; |
60 | 62 | import com.owncloud.android.lib.resources.status.OCCapability; |
| 63 | +import com.owncloud.android.operations.RefreshFolderOperation; |
61 | 64 | import com.owncloud.android.providers.UsersAndGroupsSearchConfig; |
62 | 65 | import com.owncloud.android.ui.activity.FileActivity; |
63 | 66 | import com.owncloud.android.ui.activity.FileDisplayActivity; |
@@ -325,20 +328,22 @@ private void setupView() { |
325 | 328 | binding.internalShareDescription.setVisibility(View.VISIBLE); |
326 | 329 | binding.externalSharesHeadline.setText(getResources().getString(R.string.create_end_to_end_encrypted_share_title)); |
327 | 330 |
|
328 | | - if (file.getE2eCounter() == -1) { |
329 | | - // V1 cannot share |
330 | | - binding.searchContainer.setVisibility(View.GONE); |
331 | | - binding.createLink.setVisibility(View.GONE); |
332 | | - } else { |
333 | | - binding.createLink.setText(R.string.add_new_secure_file_drop); |
334 | | - binding.searchView.setQueryHint(getResources().getString(R.string.secure_share_search)); |
335 | | - |
336 | | - if (file.isSharedViaLink()) { |
337 | | - binding.searchView.setQueryHint(getResources().getString(R.string.share_not_allowed_when_file_drop)); |
338 | | - binding.searchView.setInputType(InputType.TYPE_NULL); |
339 | | - disableSearchView(binding.searchView); |
340 | | - } |
341 | | - } |
| 331 | + fetchE2EECounter(() -> { |
| 332 | + if (file.getE2eCounter() == -1) { |
| 333 | + // V1 cannot share |
| 334 | + binding.searchContainer.setVisibility(View.GONE); |
| 335 | + binding.createLink.setVisibility(View.GONE); |
| 336 | + } else { |
| 337 | + binding.createLink.setText(R.string.add_new_secure_file_drop); |
| 338 | + binding.searchView.setQueryHint(getResources().getString(R.string.secure_share_search)); |
| 339 | + |
| 340 | + if (file.isSharedViaLink()) { |
| 341 | + binding.searchView.setQueryHint(getResources().getString(R.string.share_not_allowed_when_file_drop)); |
| 342 | + binding.searchView.setInputType(InputType.TYPE_NULL); |
| 343 | + disableSearchView(binding.searchView); |
| 344 | + } |
| 345 | + } |
| 346 | + }); |
342 | 347 | } else { |
343 | 348 | binding.createLink.setText(R.string.create_link); |
344 | 349 | binding.searchView.setQueryHint(getResources().getString(R.string.share_search_internal)); |
@@ -367,6 +372,23 @@ private void setupView() { |
367 | 372 | ); |
368 | 373 | } |
369 | 374 |
|
| 375 | + private void fetchE2EECounter(Runnable onComplete) { |
| 376 | + new Thread(() -> { |
| 377 | + try { |
| 378 | + OwnCloudClient client = clientFactory.create(user); |
| 379 | + Object metadata = RefreshFolderOperation.getDecryptedFolderMetadata(true, file, client, user, requireContext()); |
| 380 | + if (metadata instanceof DecryptedFolderMetadataFile decryptedMetadata) { |
| 381 | + file.setE2eCounter(decryptedMetadata.getMetadata().getCounter()); |
| 382 | + fileDataStorageManager.saveFile(file); |
| 383 | + } |
| 384 | + } catch (Exception e) { |
| 385 | + Log_OC.e(TAG, "Error refreshing E2E counter: " + e.getMessage()); |
| 386 | + } |
| 387 | + |
| 388 | + requireActivity().runOnUiThread(onComplete); |
| 389 | + }).start(); |
| 390 | + } |
| 391 | + |
370 | 392 | private void checkShareViaUser() { |
371 | 393 | if (!MDMConfig.INSTANCE.shareViaUser(requireContext())) { |
372 | 394 | binding.searchContainer.setVisibility(View.GONE); |
@@ -617,17 +639,9 @@ public void refreshSharesFromDB() { |
617 | 639 | } |
618 | 640 |
|
619 | 641 | private void addExternalAndPublicShares(List<OCShare> externalShares) { |
620 | | - final var publicShares = fileDataStorageManager.getSharesByPathAndType( |
621 | | - file.getRemotePath(), ShareType.PUBLIC_LINK, ""); |
| 642 | + final var publicShares = fileDataStorageManager.getSharesByPathAndType(file.getRemotePath(), ShareType.PUBLIC_LINK, ""); |
622 | 643 | externalShareeListAdapter.removeAll(); |
623 | 644 | final var shares = OCShareExtensionsKt.mergeDistinctByToken(externalShares, publicShares); |
624 | | - |
625 | | - if (file.isEncrypted()) { |
626 | | - OCShare placeholder = new OCShare(); |
627 | | - placeholder.setShareType(ShareType.NEW_PUBLIC_LINK); |
628 | | - shares.add(placeholder); |
629 | | - } |
630 | | - |
631 | 645 | externalShareeListAdapter.addShares(shares); |
632 | 646 | } |
633 | 647 |
|
|
0 commit comments