From 8df472e884187811146ed9bc680b767b1f184a7a Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:58:51 +0300 Subject: [PATCH] Show CAN info message --- .../main/settings/SettingsDataStore.java | 13 +- .../update/SignatureUpdateErrorDialog.java | 6 +- .../android/signature/update/nfc/NFCView.java | 27 ++++ .../utils/widget/ConfirmationDialog.java | 3 +- .../utils/widget/NotificationDialog.java | 149 ++++++++++++++++++ app/src/main/res/values-et/strings.xml | 5 +- app/src/main/res/values-ru/strings.xml | 5 +- app/src/main/res/values/donottranslate.xml | 3 + app/src/main/res/values/ids.xml | 3 + app/src/main/res/values/strings.xml | 7 +- .../ee/ria/DigiDoc/sign/utils/UrlMessage.java | 18 ++- 11 files changed, 224 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/ee/ria/DigiDoc/android/utils/widget/NotificationDialog.java diff --git a/app/src/main/java/ee/ria/DigiDoc/android/main/settings/SettingsDataStore.java b/app/src/main/java/ee/ria/DigiDoc/android/main/settings/SettingsDataStore.java index 657c72d41..05472b607 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/main/settings/SettingsDataStore.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/main/settings/SettingsDataStore.java @@ -11,8 +11,6 @@ import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; -import java.io.IOException; -import java.security.GeneralSecurityException; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -131,6 +129,17 @@ public void setCan(String can) { Timber.log(Log.ERROR, "Unable to save CAN"); } + public void setShowCanMessage(boolean showCanMessage) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean(resources.getString(R.string.nfc_show_can_message), showCanMessage); + editor.apply(); + } + + public boolean getShowCanMessage() { + return preferences.getBoolean(resources.getString(R.string.nfc_show_can_message), + true); + } + public boolean getIsRoleAskingEnabled() { return preferences.getBoolean(resources.getString(R.string.main_settings_ask_role_and_address_key), false); diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateErrorDialog.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateErrorDialog.java index a78a5af15..a1f8e3c8f 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateErrorDialog.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateErrorDialog.java @@ -185,13 +185,15 @@ void show(@Nullable Throwable documentsAddError, @Nullable Throwable documentRem Html.fromHtml(UrlMessage.withURL( getContext(), R.string.signature_update_signature_error_message_too_many_requests, - R.string.signature_update_signature_error_message_additional_information + R.string.signature_update_signature_error_message_additional_information, + false ), Html.FROM_HTML_MODE_LEGACY)); } else if (signatureAddError instanceof OcspInvalidTimeSlotException) { detailError = new OcspInvalidTimeSlotException(Html.fromHtml(UrlMessage.withURL( getContext(), R.string.signature_update_signature_error_message_invalid_time_slot, - R.string.signature_update_signature_error_message_additional_information + R.string.signature_update_signature_error_message_additional_information, + false ), Html.FROM_HTML_MODE_LEGACY)); } else if (signatureAddError instanceof CertificateRevokedException) { updateError = new CertificateRevokedException( diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCView.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCView.java index 34fa1c09c..28920a7fd 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCView.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCView.java @@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets; import ee.ria.DigiDoc.R; +import ee.ria.DigiDoc.android.Activity; import ee.ria.DigiDoc.android.ApplicationApp; import ee.ria.DigiDoc.android.Constants; import ee.ria.DigiDoc.android.accessibility.AccessibilityUtils; @@ -39,6 +40,7 @@ import ee.ria.DigiDoc.android.signature.update.SignatureUpdateViewModel; import ee.ria.DigiDoc.android.utils.ErrorMessageUtil; import ee.ria.DigiDoc.android.utils.navigator.Navigator; +import ee.ria.DigiDoc.android.utils.widget.NotificationDialog; import ee.ria.DigiDoc.common.PinConstants; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.subjects.PublishSubject; @@ -59,6 +61,8 @@ public class NFCView extends LinearLayout implements SignatureAddView { + String messageWithUrl = context.getString(R.string.signature_update_nfc_can_info); + String url = UrlMessage.extractLink(messageWithUrl); + if (!url.isEmpty()) { + Intent uriIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(context, uriIntent, null); + } + }); + } else { + messageView.setOnClickListener(null); + } + + layout.addView(messageView); + + dontShowAgainCheckbox = new AppCompatCheckBox(context); + dontShowAgainCheckbox.setId(android.R.id.checkbox); + dontShowAgainCheckbox.setText(R.string.dont_show_again_message); + layout.addView(dontShowAgainCheckbox); + + Button centerButton = new Button(context); + centerButton.setText(context.getString(android.R.string.ok)); + centerButton.setTextColor(Color.WHITE); + LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ); + + buttonLayoutParams.setMargins(15, 50, 15, 25); + buttonLayoutParams.gravity = Gravity.CENTER_HORIZONTAL; + centerButton.setLayoutParams(buttonLayoutParams); + + centerButton.setOnClickListener(v -> onClick(this, DialogInterface.BUTTON_POSITIVE)); + + layout.addView(centerButton); + + setView(layout); + } + else { + setMessage(context.getString(message)); + setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), this); + } + + this.action = action; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public void onClick(DialogInterface dialog, int which) { + if (action == R.id.nfcCanNotificationDialog) { + if (context instanceof Activity) { + Activity activity = (Activity) context; + + boolean isChecked = dontShowAgainCheckbox.isChecked(); + activity.getSettingsDataStore().setShowCanMessage(!isChecked); + } + } + dismiss(); + } + + @Override + public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { + if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { + String confirmationDialogDescription = getContext().getResources().getString(R.string.confirmation_dialog); + event.getText().add(confirmationDialogDescription + ","); + return true; + } + return super.dispatchPopulateAccessibilityEvent(event); + } +} diff --git a/app/src/main/res/values-et/strings.xml b/app/src/main/res/values-et/strings.xml index 313f79991..32f78682f 100644 --- a/app/src/main/res/values-et/strings.xml +++ b/app/src/main/res/values-et/strings.xml @@ -111,9 +111,11 @@ Aktiveeri ühekordne logifaili genereerimine Salvesta logifail Logimise aktiveerimiseks taaskäivita RIA DigiDoc. https://www.id.ee/artikkel/logifaili-genereerimine-digidoc4-kliendis/ - Loe täpsemalt siit Taaskäivita rakendus? + Loe täpsemalt siit + Ära rohkem näita + Allkirjastamiseks või kontrollimiseks vali fail Vali fail allkirjastamiseks või kontrollimiseks @@ -310,6 +312,7 @@ Midagi läks valesti. Palun proovi uuesti Hoia ID-kaarti telefoni lähedal ID-kaardiga kontaktivaba ühenduse loomine + NFC allkirjastamisel kasutatakse CAN numbrit. Mitmekordsel CANi valesti sisestamisel võib NFC lukustuda. https://www.id.ee/artikkel/digiallkirjastamine-ria-digidoc-mobiilirakenduses/ Hoiatused diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 360ccc833..5a5a4d428 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -110,9 +110,11 @@ Активировать одноразовое создание лог-файла Сохранить лог-файл Перезапустите RIA DigiDoc, чтобы активировать ведение журнала. https://www.id.ee/ru/artikkel/generirovanie-log-fajla-v-kliente-digidoc4/ - Подробнее читайте здесь Перезапустить приложение? + Подробнее читайте здесь + Больше не показывать + Выберите файл для подписания или проверки Выберите файл для подписания или проверки @@ -312,6 +314,7 @@ Что-то пошло не так. Пожалуйста, попробуйте еще раз Удерживайте ID-карту рядом с телефоном Создание бесконтактного соединения с ID-картой + При подписании через NFC используется номер CAN. NFC может заблокироваться, если CAN введен неправильно несколько раз. https://www.id.ee/ru/artikkel/czifrovoe-podpisanie-v-mobilnom-prilozhenii-ria-digidoc/ Предупреждения diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index b2f6b0c61..73273e6cf 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -173,4 +173,7 @@ SHA-256 SHA-1 + + nfcShowCanMessage + diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index dc0675763..c47e3d759 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -519,4 +519,7 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac8473296..0ec389baa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,9 +110,11 @@ Enable one-time log generation Save log Restart RIA DigiDoc to activate logging. https://www.id.ee/en/article/log-file-generation-in-digidoc4-client/ - Read more here Restart now? + Read more here + Don\'t show again + Choose a file to sign or validate Choose a file to sign or validate @@ -305,11 +307,12 @@ Enter your ID-card access number (CAN) and PIN2 code to sign with ID-card ID-card access number (CAN) PIN2 code - This device does not support contactless connection or NFC is turned off + This device does not support contactless connection or NFC is turned off NFC connection lost Technical error Hold your phone near the ID-card Authenticating with ID-card + NFC signing uses the CAN number. NFC may lock up if CAN is entered incorrectly multiple times. https://www.id.ee/en/article/digital-signing-in-ria-digidoc-mobile-application/ Warnings diff --git a/sign-lib/src/main/java/ee/ria/DigiDoc/sign/utils/UrlMessage.java b/sign-lib/src/main/java/ee/ria/DigiDoc/sign/utils/UrlMessage.java index 58c17a662..587f8a6db 100644 --- a/sign-lib/src/main/java/ee/ria/DigiDoc/sign/utils/UrlMessage.java +++ b/sign-lib/src/main/java/ee/ria/DigiDoc/sign/utils/UrlMessage.java @@ -12,18 +12,26 @@ public class UrlMessage { - public static String withURL(Context context, @StringRes int messageTranslation, @StringRes int urlMessageTranslation) { + public static String withURL(Context context, @StringRes int messageTranslation, @StringRes int urlMessageTranslation, boolean linkOnNewLine) { String message = getTextFromTranslation(context, messageTranslation); + String urlText = getTextFromTranslation(context, urlMessageTranslation); Matcher urlMatcher = Patterns.WEB_URL.matcher(message); if (urlMatcher.find()) { - return message.replace(urlMatcher.group(),"") + " " + - getTextFromTranslation(context, urlMessageTranslation) + ""; + String url = urlMatcher.group(); + String result = "" + message.replace(url, "") + ""; + if (linkOnNewLine) { + result += "
"; + } + result += " " + urlText + ""; + + return result; } return message; } + public static String withURLAndQuestion(Context context, @StringRes int messageTranslation, - @StringRes int urlMessageTranslation, + @StringRes int urlMessageTranslation, @StringRes int continueQuestion) { String message = getTextFromTranslation(context, messageTranslation); Matcher urlMatcher = Patterns.WEB_URL.matcher(message); @@ -44,7 +52,7 @@ private static String getTextFromTranslation(Context context, int textId) { return resources.getString(textId); } - private static String extractLink(String text) { + public static String extractLink(String text) { Matcher m = Patterns.WEB_URL.matcher(text); while (m.find()) { return m.group();