Skip to content

Commit

Permalink
Merge pull request #529 from martenrebane/MOPPAND-1328
Browse files Browse the repository at this point in the history
Fix showing crypto container download button
  • Loading branch information
kristelmerilain authored Jul 8, 2024
2 parents 23282cf + 80c94d0 commit 8a1473c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -118,7 +117,7 @@ void dataForRecipients(@State String searchState,
Throwable searchError,
ImmutableList<Certificate> recipients) {
ImmutableList.Builder<Item> builder = ImmutableList.builder();
if (searchResults != null && searchResults.size() > 0) {
if (searchResults != null && !searchResults.isEmpty()) {
List<Certificate> certificates = new ArrayList<>();
for (Certificate searchResult : searchResults) {
certificates.add(searchResult);
Expand All @@ -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) {
Expand Down Expand Up @@ -241,26 +240,19 @@ static abstract class CreateViewHolder<T extends Item> 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);
};
}
}

Expand Down Expand Up @@ -300,12 +292,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);
Expand All @@ -315,8 +305,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;
}
}
Expand Down Expand Up @@ -442,7 +431,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);
Expand Down Expand Up @@ -699,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,19 +124,20 @@ 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);
isFromSignatureView = args.getBoolean(KEY_IS_FROM_SIGNATURE_VIEW);
}

private Observable<Intent.InitialIntent> initialIntent() {
return Observable.just(Intent.InitialIntent.create(containerFile, intent, isFromSignatureView));
return Observable.just(Intent.InitialIntent.create(isFromSignatureView ? containerFromSigning : containerFile, intent, isFromSignatureView));
}

private Observable<Intent.NameUpdateIntent> nameUpdateIntent() {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,6 +154,8 @@ final class Processor implements ObservableTransformer<Intent, Result> {
.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));
Expand Down Expand Up @@ -208,7 +209,7 @@ final class Processor implements ObservableTransformer<Intent, Result> {
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 {
Expand Down Expand Up @@ -281,8 +282,10 @@ final class Processor implements ObservableTransformer<Intent, Result> {
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
}
Expand Down Expand Up @@ -558,7 +561,6 @@ final class Processor implements ObservableTransformer<Intent, Result> {
});
}

@SuppressWarnings("unchecked")
@Override
public ObservableSource<Result> apply(Observable<Intent> upstream) {
return upstream.publish(shared -> Observable.mergeArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ final class Processor implements ObservableTransformer<Action, Result> {
});

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);
}
Expand Down

0 comments on commit 8a1473c

Please sign in to comment.