From 77b6672da095dd5265e7f154223caad8c2322d8e Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:26:17 +0300 Subject: [PATCH 1/3] Fix showing crypto container download button --- .../crypto/create/CryptoCreateAdapter.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java index f8649a947..ce8e7290f 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java @@ -42,7 +42,6 @@ import ee.ria.DigiDoc.common.Certificate; import ee.ria.DigiDoc.common.FileUtil; import ee.ria.DigiDoc.common.TextUtil; -import ee.ria.DigiDoc.crypto.CryptoContainer; import ee.ria.DigiDoc.crypto.NoInternetConnectionException; import ee.ria.DigiDoc.crypto.PersonalCodeException; import io.reactivex.rxjava3.core.Observable; @@ -104,7 +103,7 @@ void dataForContainer(@Nullable String name, @Nullable File containerFile, Immut for (Certificate recipient : recipients) { builder.add(RecipientItem.create(recipient, recipientsRemoveEnabled, false, false)); } - if (recipients.size() == 0) { + if (recipients.isEmpty()) { builder.add(EmptyTextItem.create(R.string.crypto_create_recipients_empty)); } if (recipientsAddEnabled) { @@ -118,7 +117,7 @@ void dataForRecipients(@State String searchState, Throwable searchError, ImmutableList recipients) { ImmutableList.Builder builder = ImmutableList.builder(); - if (searchResults != null && searchResults.size() > 0) { + if (searchResults != null && !searchResults.isEmpty()) { List certificates = new ArrayList<>(); for (Certificate searchResult : searchResults) { certificates.add(searchResult); @@ -134,7 +133,7 @@ void dataForRecipients(@State String searchState, } else if (searchResults != null && !searchState.equals(State.ACTIVE)) { builder.add(EmptyTextItem.create(R.string.crypto_recipients_search_result_empty)); } - if (recipients.size() > 0) { + if (!recipients.isEmpty()) { builder.add(SubheadItem.create(R.string.crypto_recipients_selected_subhead)); } for (Certificate recipient : recipients) { @@ -300,12 +299,10 @@ void bind(CryptoCreateAdapter adapter, NameItem item) { saveButton.setVisibility(isContainerEncryptedOrDecrypted(adapter) ? View.VISIBLE : View.GONE); if (AccessibilityUtils.isTalkBackEnabled()) { updateButton.setContentDescription(itemView.getResources() - .getString(R.string.crypto_create_name_update_button) - ); + .getString(R.string.crypto_create_name_update_button)); } else { updateButton.setContentDescription(itemView.getResources() - .getString(R.string.signature_update_name_update_voice_button) - ); + .getString(R.string.signature_update_name_update_voice_button)); } clicks(updateButton).subscribe(adapter.nameUpdateClicksSubject); clicks(saveButton).subscribe(adapter.saveContainerClicksSubject); @@ -315,8 +312,7 @@ private boolean isContainerEncryptedOrDecrypted(CryptoCreateAdapter adapter) { for (CryptoCreateAdapter.Item cryptoItem : adapter.items) { if ((cryptoItem instanceof CryptoCreateAdapter.DataFileItem && !((CryptoCreateAdapter.DataFileItem) cryptoItem).removeButtonVisible() - ) || (cryptoItem instanceof NameItem && - CryptoContainer.isContainerFileName(((NameItem) cryptoItem).name()))) { + )) { return true; } } @@ -442,7 +438,7 @@ void bind(CryptoCreateAdapter adapter, DataFileItem item) { if (AccessibilityUtils.isAccessibilityEnabled()) { ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() { @Override - public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { + public void onInitializeAccessibilityNodeInfo(@NonNull View host, @NonNull AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); if (!item.removeButtonVisible() && info.getActionList().contains(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK)) { info.removeAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK); From 6ad3c2b22e501e2bb273ea684480d5a4274a3173 Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Thu, 20 Jun 2024 01:17:02 +0300 Subject: [PATCH 2/3] Fix showing crypto buttons and file name editing --- .../android/crypto/create/CryptoCreateAdapter.java | 2 +- .../android/crypto/create/CryptoCreateScreen.java | 9 ++++++--- .../ee/ria/DigiDoc/android/crypto/create/Processor.java | 4 +++- .../ee/ria/DigiDoc/android/crypto/create/Result.java | 1 + .../ria/DigiDoc/android/signature/update/Processor.java | 4 +--- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java index ce8e7290f..91197a357 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java @@ -73,7 +73,7 @@ void dataForContainer(@Nullable String name, @Nullable File containerFile, Immut boolean encryptSuccessMessageVisible, boolean decryptSuccessMessageVisible, RecyclerView listView) { - this.dataFilesViewEnabled = dataFilesViewEnabled; + this.dataFilesViewEnabled = dataFilesViewEnabled && dataFiles.isEmpty(); ImmutableList.Builder builder = ImmutableList.builder(); if (encryptSuccessMessageVisible) { diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateScreen.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateScreen.java index 1949c7983..f2bb5316d 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateScreen.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateScreen.java @@ -35,6 +35,8 @@ import com.google.common.collect.ImmutableList; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import ee.ria.DigiDoc.R; @@ -122,11 +124,12 @@ public static CryptoCreateScreen open(android.content.Intent intent) { @Nullable private Throwable decryptError; @Nullable private File dataFileRemoveConfirmation; @Nullable private File sivaConfirmation; + private final File containerFromSigning; @SuppressWarnings("WeakerAccess") public CryptoCreateScreen(Bundle args) { super(args); - containerFile = args.containsKey(KEY_CONTAINER_FILE) + containerFromSigning = args.containsKey(KEY_CONTAINER_FILE) ? getFile(args, KEY_CONTAINER_FILE) : null; intent = getIntent(args); @@ -134,7 +137,7 @@ public CryptoCreateScreen(Bundle args) { } private Observable initialIntent() { - return Observable.just(Intent.InitialIntent.create(containerFile, intent, isFromSignatureView)); + return Observable.just(Intent.InitialIntent.create(isFromSignatureView ? containerFromSigning : containerFile, intent, isFromSignatureView)); } private Observable nameUpdateIntent() { @@ -274,7 +277,7 @@ public void render(ViewState state) { setActivity(state.dataFilesAddState().equals(State.ACTIVE) || state.encryptState().equals(State.ACTIVE)); - nameUpdateDialog.render(state.nameUpdateShowing(), FileUtil.sanitizeString(state.name(), ""), state.nameUpdateError()); + nameUpdateDialog.render(state.nameUpdateShowing(), FileUtil.sanitizeString(state.newName() != null ? state.newName() : state.name(), ""), state.nameUpdateError()); int titleResId = state.encryptButtonVisible() ? R.string.crypto_create_title_encrypt : R.string.crypto_create_title_decrypt; diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java index 6ee693ae2..08728995b 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java @@ -155,6 +155,8 @@ final class Processor implements ObservableTransformer { .startWithItem(Result.InitialResult.activity()); } else if (androidIntent != null) { return parseIntent(androidIntent, application, fileSystem.getExternallyOpenedFilesDir(), configurationContext); + } else if (intent.isFromSignatureView()) { + return Observable.just(Result.InitialResult.success(CryptoContainer.open(intent.containerFile()))); } else { navigator.execute(Transaction.activityForResult(RC_CRYPTO_CREATE_INITIAL, createGetContentIntent(true), null)); @@ -208,7 +210,7 @@ final class Processor implements ObservableTransformer { return result; }) .onErrorReturn(throwable -> Result.NameUpdateResult.failure(newName, throwable)) - .startWithItem(Result.NameUpdateResult.progress(name)); + .startWithItem(Result.NameUpdateResult.progress(newName)); } else if (name != null) { return Observable.just(Result.NameUpdateResult.show(name)); } else { diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Result.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Result.java index 20865b49c..9b43a05d7 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Result.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Result.java @@ -114,6 +114,7 @@ abstract class NameUpdateResult implements Result { public ViewState reduce(ViewState state) { return state.buildWith() .nameUpdateShowing(name() != null) + .name(name()) .newName(newName()) .nameUpdateInProgress(inProgress()) .nameUpdateError(error()) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java index 22dfb9213..7c49f65aa 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java @@ -463,9 +463,7 @@ final class Processor implements ObservableTransformer { }); encrypt = upstream -> upstream - .doOnNext(action -> { - navigator.execute(Transaction.push(CryptoCreateScreen.open(action.containerFile(), false))); - }) + .doOnNext(action -> navigator.execute(Transaction.push(CryptoCreateScreen.open(action.containerFile(), true)))) .map(action -> Result.EncryptResult.success()) .onErrorReturn(Result.EncryptResult::failure); } From 80c94d03dabe4fc1dbe2eb8bcf154e32cc6b7eba Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:08:31 +0300 Subject: [PATCH 3/3] Fix crypto save button --- .../crypto/create/CryptoCreateAdapter.java | 40 ++++++++----------- .../android/crypto/create/Processor.java | 8 ++-- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java index 91197a357..bfc324c8c 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/CryptoCreateAdapter.java @@ -73,7 +73,7 @@ void dataForContainer(@Nullable String name, @Nullable File containerFile, Immut boolean encryptSuccessMessageVisible, boolean decryptSuccessMessageVisible, RecyclerView listView) { - this.dataFilesViewEnabled = dataFilesViewEnabled && dataFiles.isEmpty(); + this.dataFilesViewEnabled = dataFilesViewEnabled; ImmutableList.Builder builder = ImmutableList.builder(); if (encryptSuccessMessageVisible) { @@ -240,26 +240,19 @@ static abstract class CreateViewHolder extends RecyclerView.View abstract void bind(CryptoCreateAdapter adapter, T item); static CreateViewHolder create(@LayoutRes int viewType, View itemView) { - switch (viewType) { - case R.layout.crypto_create_list_item_success: - return new SuccessViewHolder(itemView); - case R.layout.crypto_create_list_item_name: - return new NameViewHolder(itemView); - case R.layout.crypto_list_item_subhead: - return new SubheadViewHolder(itemView); - case R.layout.crypto_create_list_item_add_button: - return new AddButtonViewHolder(itemView); - case R.layout.crypto_create_list_item_empty_text: - return new EmptyTextViewHolder(itemView); - case R.layout.crypto_create_list_item_data_file: - return new DataFileViewHolder(itemView); - case R.layout.crypto_list_item_recipient: - return new RecipientViewHolder(itemView); - case R.layout.crypto_list_item_add_all_button: - return new AddAllViewHolder(itemView); - default: - throw new IllegalArgumentException("Unknown view type " + viewType); - } + return switch (viewType) { + case R.layout.crypto_create_list_item_success -> new SuccessViewHolder(itemView); + case R.layout.crypto_create_list_item_name -> new NameViewHolder(itemView); + case R.layout.crypto_list_item_subhead -> new SubheadViewHolder(itemView); + case R.layout.crypto_create_list_item_add_button -> + new AddButtonViewHolder(itemView); + case R.layout.crypto_create_list_item_empty_text -> + new EmptyTextViewHolder(itemView); + case R.layout.crypto_create_list_item_data_file -> new DataFileViewHolder(itemView); + case R.layout.crypto_list_item_recipient -> new RecipientViewHolder(itemView); + case R.layout.crypto_list_item_add_all_button -> new AddAllViewHolder(itemView); + default -> throw new IllegalArgumentException("Unknown view type " + viewType); + }; } } @@ -695,9 +688,8 @@ public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { if (oldItem instanceof DataFileItem && newItem instanceof DataFileItem) { return ((DataFileItem) oldItem).dataFile() .equals(((DataFileItem) newItem).dataFile()); - } else if (oldItem instanceof RecipientItem && newItem instanceof RecipientItem) { - RecipientItem oldRecipientItem = (RecipientItem) oldItem; - RecipientItem newRecipientItem = (RecipientItem) newItem; + } else if (oldItem instanceof RecipientItem oldRecipientItem && + newItem instanceof RecipientItem newRecipientItem) { return oldRecipientItem.recipient().equals(newRecipientItem.recipient()) && oldRecipientItem.removeButtonVisible() == newRecipientItem.removeButtonVisible(); diff --git a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java index 08728995b..866c6d6d6 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/crypto/create/Processor.java @@ -63,7 +63,6 @@ import ee.ria.DigiDoc.crypto.Pin1InvalidException; import ee.ria.DigiDoc.crypto.RecipientRepository; import ee.ria.DigiDoc.idcard.Token; - import ee.ria.DigiDoc.sign.SignedContainer; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.core.Observable; @@ -283,8 +282,10 @@ final class Processor implements ObservableTransformer { return Observable .fromCallable(() -> { try { - //noinspection ResultOfMethodCallIgnored - intent.dataFile().delete(); + if (intent.dataFile() != null) { + //noinspection ResultOfMethodCallIgnored + intent.dataFile().delete(); + } } catch (Exception e) { // ignore because it's a cache file and is deleted anyway } @@ -560,7 +561,6 @@ final class Processor implements ObservableTransformer { }); } - @SuppressWarnings("unchecked") @Override public ObservableSource apply(Observable upstream) { return upstream.publish(shared -> Observable.mergeArray(