Skip to content

Commit

Permalink
Add NFC design icon
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Sep 10, 2024
1 parent 4e43df4 commit 92aaa3e
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ee.ria.DigiDoc.android.signature.update;

import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static ee.ria.DigiDoc.android.signature.update.SignatureUpdateErrorDialog.Type.DOCUMENTS_ADD;
import static ee.ria.DigiDoc.android.signature.update.SignatureUpdateErrorDialog.Type.DOCUMENT_REMOVE;
Expand All @@ -12,8 +13,11 @@
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -39,6 +43,7 @@
import ee.ria.DigiDoc.common.exception.SignatureUpdateDetailError;
import ee.ria.DigiDoc.common.exception.SignatureUpdateError;
import ee.ria.DigiDoc.idcard.CodeVerificationException;
import ee.ria.DigiDoc.idcard.NFC;
import ee.ria.DigiDoc.sign.CertificateRevokedException;
import ee.ria.DigiDoc.sign.OcspInvalidTimeSlotException;
import ee.ria.DigiDoc.sign.TooManyRequestsException;
Expand All @@ -65,6 +70,11 @@ public final class SignatureUpdateErrorDialog extends ErrorDialog implements Dia

private String type;

private View dialogLayout;
private TextView errorDialogHeader;
private ImageView nfcDialogIcon;
private TextView nfcDialogText;
private TextView dialogText;
private View view;
private View.OnLayoutChangeListener layoutChangeListener;

Expand All @@ -77,6 +87,14 @@ public final class SignatureUpdateErrorDialog extends ErrorDialog implements Dia
SignatureUpdateSignatureAddDialog signatureAddDialog,
View view) {
super(context, R.style.UniformDialog);
LayoutInflater inflater = LayoutInflater.from(context);
dialogLayout = inflater.inflate(R.layout.signature_update_error_dialog, this.getListView());

errorDialogHeader = dialogLayout.findViewById(R.id.errorDialogHeader);
nfcDialogText = dialogLayout.findViewById(R.id.nfcDialogText);
nfcDialogIcon = dialogLayout.findViewById(R.id.nfcDialogIcon);
dialogText = dialogLayout.findViewById(R.id.dialogText);

this.documentsAddIntentSubject = documentsAddIntentSubject;
this.documentRemoveIntentSubject = documentRemoveIntentSubject;
this.signatureAddIntentSubject = signatureAddIntentSubject;
Expand All @@ -85,6 +103,7 @@ public final class SignatureUpdateErrorDialog extends ErrorDialog implements Dia
this.signatureAddDialog = signatureAddDialog;
this.view = view;
setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), (dialog, which) -> {});
setView(dialogLayout);
setOnDismissListener(this);
}

Expand All @@ -99,6 +118,11 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem
SignatureUpdateError updateError = null;
SignatureUpdateDetailError detailError = null;

errorDialogHeader.setVisibility(VISIBLE);
nfcDialogIcon.setVisibility(VISIBLE);
nfcDialogText.setVisibility(VISIBLE);
dialogText.setVisibility(VISIBLE);

if (documentsAddError != null) {
type = DOCUMENTS_ADD;
if (documentsAddError instanceof EmptyFileException) {
Expand Down Expand Up @@ -142,7 +166,8 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem
getTextFromTranslation(R.string.signature_update_signature_error_message_additional_information) + "</a>",
Html.FROM_HTML_MODE_LEGACY));
} else {
setTitle(R.string.signature_update_signature_add_error_title);
errorDialogHeader.setVisibility(VISIBLE);
errorDialogHeader.setText(R.string.signature_update_signature_add_error_title);
if (((DetailMessageSource) signatureAddError).getDetailMessage() != null &&
!((DetailMessageSource) signatureAddError).getDetailMessage().isEmpty()) {
String errorMessage = getContext().getString(R.string.signature_update_signature_error_message_details) +
Expand All @@ -153,6 +178,8 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem
detailError = new DetailMessageException(signatureAddError.getMessage());
}
}
} else if (signatureAddError instanceof NFC.NFCException) {
updateError = new NFC.NFCException(signatureAddError.getMessage());
} else if (signatureAddError instanceof TooManyRequestsException) {
detailError = new TooManyRequestsException(
Html.fromHtml(UrlMessage.withURL(
Expand All @@ -175,7 +202,8 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem
} else if (signatureAddError.getMessage() != null && signatureAddError.getMessage().startsWith("Failed to create ssl connection with host")) {
updateError = new SSLHandshakeException();
} else {
setTitle(R.string.signature_update_signature_add_error);
errorDialogHeader.setVisibility(VISIBLE);
errorDialogHeader.setText(R.string.signature_update_signature_add_error);
updateError = new GeneralSignatureUpdateException(signatureAddError.getMessage());
}
} else if (signatureRemoveError != null) {
Expand All @@ -185,14 +213,27 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem
}

if (updateError != null) {
String message = updateError.getMessage(getContext());
setMessage(message);
if (updateError instanceof NFC.NFCException) {
nfcDialogText.setVisibility(View.VISIBLE);
nfcDialogText.setText(updateError.getMessage(getContext()));
dialogText.setVisibility(View.GONE);
errorDialogHeader.setVisibility(View.GONE);
} else {
nfcDialogText.setVisibility(View.GONE);
nfcDialogIcon.setVisibility(View.GONE);
dialogText.setVisibility(View.VISIBLE);
dialogText.setText(updateError.getMessage(getContext()));
}
} else if (detailError != null) {
nfcDialogText.setVisibility(View.GONE);
nfcDialogIcon.setVisibility(View.GONE);
dialogText.setVisibility(View.VISIBLE);

Spanned detailMessage = detailError.getDetailMessage(getContext());
if (detailMessage == null) {
setMessage(detailError.getMessage(getContext()));
if (detailMessage != null) {
dialogText.setText(detailMessage);
} else {
setMessage(detailMessage);
dialogText.setText(detailError.getMessage(getContext()));
}
} else {
dismiss();
Expand All @@ -209,7 +250,7 @@ private String getTextFromTranslation(int textId) {

@Override
public void onDismiss(DialogInterface dialog) {
setTitle(null);
errorDialogHeader.setText(null);
removeListeners();
if (TextUtils.equals(type, DOCUMENTS_ADD)) {
documentsAddIntentSubject.onNext(DocumentsAddIntent.clear());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;

import ee.ria.DigiDoc.R;
import ee.ria.DigiDoc.android.accessibility.AccessibilityUtils;
Expand All @@ -19,15 +25,28 @@

public final class NFCDialog extends AlertDialog implements DialogInterface.OnClickListener {

private TextView messageView;
private ImageView iconView;

private final Subject<Integer> buttonClicksSubject = PublishSubject.create();

private final int action;
private final Context context;

public NFCDialog(@NonNull Context context, @StringRes int message, int action) {
super(context);
this.context = context;
SecureUtil.markAsSecure(context, getWindow());

setMessage(context.getString(message));
LayoutInflater inflater = LayoutInflater.from(context);
View dialogLayout = inflater.inflate(R.layout.nfc_dialog, this.getListView());

messageView = dialogLayout.findViewById(R.id.nfcDialogText);
iconView = dialogLayout.findViewById(R.id.nfcDialogIcon);

messageView.setText(context.getString(message));
setView(dialogLayout);

setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), this);

this.action = action;
Expand All @@ -43,15 +62,17 @@ public void showStatus(NFCResponse response) {
}
if (response.message() != null) {
if (response.status() == SessionStatusResponse.ProcessStatus.TECHNICAL_ERROR) {
setMessage(getContext().getString(R.string.signature_update_nfc_technical_error) + ":\n" + response.message());
messageView.setText(getContext().getString(R.string.signature_update_nfc_technical_error) + ":\n" + response.message());
iconView.setColorFilter(ContextCompat.getColor(context, R.color.error), PorterDuff.Mode.SRC_IN);
} else {
setMessage(response.message());
messageView.setText(response.message());
iconView.setColorFilter(ContextCompat.getColor(context, R.color.accent), PorterDuff.Mode.SRC_IN);
}
} else {
if (AccessibilityUtils.isTalkBackEnabled()) {
AccessibilityUtils.interrupt(getContext());
}
setMessage(getContext().getString(R.string.signature_update_nfc_hold));
messageView.setText(getContext().getString(R.string.signature_update_nfc_hold));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void subscribe(ObservableEmitter<NFCResponse> emitter) {
if (response != null) {
if (response.status() != SessionStatusResponse.ProcessStatus.OK) {
Timber.log(Log.ERROR, String.format("NFC status: %s", response.status()));
emitter.onError(new NFC.NFCException(response.message()));
emitter.onError(NFCResponse.createException(response.message()));
emitter.onComplete();
} else {
emitter.onNext(response);
emitter.onComplete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.auto.value.AutoValue;

import ee.ria.DigiDoc.android.signature.update.SignatureAddResponse;
import ee.ria.DigiDoc.idcard.NFC;
import ee.ria.DigiDoc.sign.SignedContainer;
import ee.ria.DigiDoc.smartid.dto.response.SessionStatusResponse;

Expand Down Expand Up @@ -46,4 +47,8 @@ private static NFCResponse create(@Nullable SignedContainer container,
public static NFCResponse createWithStatus(SessionStatusResponse.ProcessStatus status, String message) {
return create(null, status, message);
}

public static NFC.NFCException createException(String message) {
return new NFC.NFCException(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textview.MaterialTextView;
Expand Down Expand Up @@ -80,8 +81,8 @@ public NFCView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
handleNFCSupportLayout();

if (AccessibilityUtils.isTalkBackEnabled()) {
AccessibilityUtils.setSingleCharactersContentDescription(canView, "Card number");
AccessibilityUtils.setSingleCharactersContentDescription(pinView, "PIN code");
AccessibilityUtils.setSingleCharactersContentDescription(canView, getResources().getString(R.string.signature_update_nfc_can));
AccessibilityUtils.setSingleCharactersContentDescription(pinView, getResources().getString(R.string.signature_update_nfc_pin2));
AccessibilityUtils.setEditTextCursorToEnd(canView);
AccessibilityUtils.setEditTextCursorToEnd(pinView);
AccessibilityUtils.setTextViewContentDescription(context, true, null, canLabel.getText().toString(), canView);
Expand Down Expand Up @@ -149,14 +150,16 @@ private void checkInputsValidity() {
}

private void checkCANCodeValidity() {
canLayout.setError(null);
setDefaultCANNumberDescription();

Editable canCodeView = canView.getText();
if (canCodeView != null && !canCodeView.toString().isEmpty() &&
!isCANLengthValid(canCodeView.toString())
) {
canLayout.setError(getResources().getString(
R.string.nfc_sign_can_invalid_length,
Integer.toString(CAN_LENGTH)));
canLayout.setErrorTextColor(ContextCompat.getColorStateList(getContext(), R.color.error));
}
}

Expand Down Expand Up @@ -191,10 +194,17 @@ private void setAccessibilityDescription() {
AccessibilityUtils.setEditTextCursorToEnd(canView);
}

private void setDefaultCANNumberDescription() {
canLayout.setError(getResources().getString(R.string.nfc_sign_can_location));
canLayout.setErrorTextColor(ContextCompat.getColorStateList(getContext(), R.color.material_color_black));
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();

setDefaultCANNumberDescription();

// Better support for Voice Assist to not delete wrong characters
accessibilityTouchExplorationStateChangeListener = AccessibilityUtils.addAccessibilityStateChanged(enabled -> {
boolean isTalkBackEnabled = AccessibilityUtils.isTalkBackEnabled();
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/drawable/ic_icon_nfc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="124dp"
android:height="120dp"
android:viewportWidth="124"
android:viewportHeight="120">
<path
android:pathData="M122.2,60C122.2,92.27 95.29,118.5 62,118.5C28.71,118.5 1.8,92.27 1.8,60C1.8,27.73 28.71,1.5 62,1.5C95.29,1.5 122.2,27.73 122.2,60Z"
android:strokeWidth="3"
android:fillColor="#00000000"
android:strokeColor="#3576B6"/>
<group>
<clip-path
android:pathData="M38.3,24h48v48h-48z"/>
<path
android:pathData="M78.95,68.95L54.15,44.15C53.88,44.72 53.67,45.33 53.52,45.97C53.37,46.63 53.3,47.3 53.3,48C53.3,49.37 53.56,50.62 54.1,51.75C54.63,52.88 55.36,53.87 56.3,54.7L54.15,56.85C52.98,55.75 52.05,54.44 51.35,52.92C50.65,51.41 50.3,49.77 50.3,48C50.3,46.9 50.44,45.84 50.72,44.83C51.01,43.81 51.41,42.85 51.95,41.95L48.3,38.3C47.36,39.7 46.63,41.22 46.1,42.85C45.56,44.48 45.3,46.2 45.3,48C45.3,50.47 45.77,52.75 46.72,54.85C47.67,56.95 48.98,58.78 50.65,60.35L48.5,62.5C46.6,60.67 45.09,58.51 43.97,56.03C42.86,53.54 42.3,50.87 42.3,48C42.3,45.77 42.64,43.65 43.32,41.65C44.01,39.65 44.95,37.82 46.15,36.15L41.35,31.35L43.5,29.2L81.1,66.8L78.95,68.95ZM78.45,59.85L76.25,57.65C77.21,56.28 77.96,54.78 78.5,53.15C79.03,51.52 79.3,49.8 79.3,48C79.3,43.27 77.65,39.25 74.35,35.95C71.05,32.65 67.03,31 62.3,31C60.5,31 58.78,31.26 57.15,31.77C55.51,32.29 54,33.03 52.6,34L50.45,31.85C52.15,30.65 53.99,29.71 55.97,29.02C57.96,28.34 60.06,28 62.3,28C65.06,28 67.66,28.52 70.1,29.58C72.53,30.63 74.65,32.05 76.45,33.85C78.25,35.65 79.67,37.77 80.72,40.2C81.77,42.63 82.3,45.23 82.3,48C82.3,50.2 81.96,52.3 81.27,54.3C80.59,56.3 79.65,58.15 78.45,59.85ZM72.65,54.05L70.45,51.85C70.71,51.28 70.92,50.67 71.07,50.03C71.22,49.38 71.3,48.7 71.3,48C71.3,45.5 70.42,43.38 68.67,41.63C66.92,39.88 64.8,39 62.3,39C61.6,39 60.92,39.08 60.27,39.22C59.62,39.38 59.01,39.58 58.45,39.85L56.25,37.65C57.11,37.12 58.06,36.71 59.1,36.42C60.13,36.14 61.2,36 62.3,36C65.63,36 68.46,37.17 70.8,39.5C73.13,41.83 74.3,44.67 74.3,48C74.3,49.1 74.16,50.17 73.87,51.2C73.59,52.23 73.18,53.18 72.65,54.05Z"
android:fillColor="#3576B6"/>
</group>
<path
android:pathData="M57.92,77.05V87H55.87L51.87,80.33V87H49.82V77.05H51.87L55.88,83.73V77.05H57.92ZM61.76,77.05V87H59.71V77.05H61.76ZM65.72,81.3V82.9H61.2V81.3H65.72ZM66.2,77.05V78.65H61.2V77.05H66.2ZM73.16,83.7H75.2C75.16,84.37 74.98,84.96 74.65,85.48C74.33,86 73.87,86.41 73.29,86.7C72.71,86.99 72.01,87.14 71.2,87.14C70.56,87.14 69.99,87.03 69.48,86.81C68.98,86.59 68.54,86.27 68.18,85.85C67.83,85.44 67.56,84.94 67.37,84.35C67.18,83.76 67.09,83.1 67.09,82.37V81.68C67.09,80.95 67.19,80.29 67.38,79.71C67.57,79.11 67.85,78.61 68.21,78.2C68.58,77.78 69.01,77.46 69.52,77.24C70.02,77.01 70.59,76.9 71.21,76.9C72.04,76.9 72.74,77.05 73.31,77.35C73.88,77.66 74.33,78.07 74.64,78.6C74.96,79.13 75.15,79.73 75.22,80.4H73.17C73.14,80 73.06,79.66 72.93,79.38C72.79,79.1 72.58,78.89 72.31,78.75C72.03,78.6 71.67,78.53 71.21,78.53C70.87,78.53 70.57,78.59 70.32,78.72C70.06,78.85 69.85,79.04 69.67,79.3C69.5,79.56 69.37,79.89 69.28,80.29C69.2,80.68 69.16,81.14 69.16,81.67V82.37C69.16,82.89 69.2,83.34 69.28,83.73C69.35,84.12 69.47,84.45 69.63,84.72C69.8,84.98 70.01,85.18 70.26,85.32C70.52,85.45 70.83,85.52 71.2,85.52C71.63,85.52 71.98,85.45 72.26,85.31C72.54,85.17 72.75,84.97 72.89,84.7C73.04,84.43 73.13,84.1 73.16,83.7Z"
android:fillColor="#3576B6"/>
</vector>
Loading

0 comments on commit 92aaa3e

Please sign in to comment.