From aaaf269db680445149ab67f6da8a60d6cace4e9d Mon Sep 17 00:00:00 2001 From: Mike Wong Date: Tue, 23 Mar 2021 18:15:21 +0100 Subject: [PATCH 01/29] Display onset date when reporting as exposed --- .../admin/bag/dp3t/inform/InformFragment.java | 3 ++ .../bag/dp3t/inform/ThankYouFragment.java | 27 ++++++++++++++ .../bag/dp3t/reports/ReportsFragment.java | 17 +++++++++ .../admin/bag/dp3t/storage/SecureStorage.java | 9 +++++ .../ch/admin/bag/dp3t/util/StringUtil.java | 17 +++++++++ .../layout/card_what_to_do_self_isolation.xml | 36 +++++++++++++++++++ .../main/res/layout/fragment_thank_you.xml | 1 + app/src/main/res/values-bs/strings.xml | 9 +++++ app/src/main/res/values-de/strings.xml | 12 +++++++ app/src/main/res/values-es/strings.xml | 9 +++++ app/src/main/res/values-fr/strings.xml | 9 +++++ app/src/main/res/values-hr/strings.xml | 9 +++++ app/src/main/res/values-it/strings.xml | 9 +++++ app/src/main/res/values-pt/strings.xml | 9 +++++ app/src/main/res/values-rm/strings.xml | 9 +++++ app/src/main/res/values-sq/strings.xml | 9 +++++ app/src/main/res/values-sr/strings.xml | 9 +++++ app/src/main/res/values-ti/strings.xml | 9 +++++ app/src/main/res/values-tr/strings.xml | 9 +++++ app/src/main/res/values/strings.xml | 9 +++++ 20 files changed, 230 insertions(+) diff --git a/app/src/main/java/ch/admin/bag/dp3t/inform/InformFragment.java b/app/src/main/java/ch/admin/bag/dp3t/inform/InformFragment.java index d5a0f91aa..2fe786c95 100644 --- a/app/src/main/java/ch/admin/bag/dp3t/inform/InformFragment.java +++ b/app/src/main/java/ch/admin/bag/dp3t/inform/InformFragment.java @@ -183,6 +183,9 @@ public void onSuccess(Void response) { } secureStorage.clearInformTimeAndCodeAndToken(); + // Store the onset date of this report + secureStorage.setPositiveReportOnsetDate(onsetDate.getTime()); + // Ask if user wants to end isolation after 14 days long isolationEndDialogTimestamp = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(14); secureStorage.setIsolationEndDialogTimestamp(isolationEndDialogTimestamp); diff --git a/app/src/main/java/ch/admin/bag/dp3t/inform/ThankYouFragment.java b/app/src/main/java/ch/admin/bag/dp3t/inform/ThankYouFragment.java index 221f966e5..fe6e31745 100644 --- a/app/src/main/java/ch/admin/bag/dp3t/inform/ThankYouFragment.java +++ b/app/src/main/java/ch/admin/bag/dp3t/inform/ThankYouFragment.java @@ -10,15 +10,22 @@ package ch.admin.bag.dp3t.inform; import android.os.Bundle; +import android.text.Spannable; import android.view.View; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import ch.admin.bag.dp3t.R; +import ch.admin.bag.dp3t.storage.SecureStorage; +import ch.admin.bag.dp3t.util.DateUtils; +import ch.admin.bag.dp3t.util.StringUtil; public class ThankYouFragment extends Fragment { + private SecureStorage secureStorage; + public static ThankYouFragment newInstance() { return new ThankYouFragment(); } @@ -27,12 +34,32 @@ public ThankYouFragment() { super(R.layout.fragment_thank_you); } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + secureStorage = SecureStorage.getInstance(getContext()); + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ((InformActivity) requireActivity()).allowBackButton(false); + // Show the onset date in the thank you message + TextView thankYouTextView = view.findViewById(R.id.inform_thank_you_text); + long onsetDateInMillis = secureStorage.getPositiveReportOnsetDate(); + if (onsetDateInMillis > 0L) { + String formattedDate = DateUtils.getFormattedDateWrittenMonth(onsetDateInMillis); + String thankYouText = getString(R.string.inform_send_thankyou_text_onsetdate).replace("{ONSET_DATE}", formattedDate); + int start = thankYouText.indexOf(formattedDate); + int end = thankYouText.indexOf("\n", start); // Include the " - today" part of the line + Spannable formattedText = StringUtil.makePartiallyBold(thankYouText, start, end); + thankYouTextView.setText(formattedText); + } else { + thankYouTextView.setText(R.string.inform_send_thankyou_text); + } + view.findViewById(R.id.inform_thank_you_button_continue).setOnClickListener(v -> { getParentFragmentManager().beginTransaction() .setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit) diff --git a/app/src/main/java/ch/admin/bag/dp3t/reports/ReportsFragment.java b/app/src/main/java/ch/admin/bag/dp3t/reports/ReportsFragment.java index 4401217ec..40c4f4ad1 100644 --- a/app/src/main/java/ch/admin/bag/dp3t/reports/ReportsFragment.java +++ b/app/src/main/java/ch/admin/bag/dp3t/reports/ReportsFragment.java @@ -15,6 +15,7 @@ import android.content.res.Resources; import android.graphics.Rect; import android.os.Bundle; +import android.text.Spannable; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -37,8 +38,10 @@ import ch.admin.bag.dp3t.R; import ch.admin.bag.dp3t.home.model.TracingStatusInterface; import ch.admin.bag.dp3t.storage.SecureStorage; +import ch.admin.bag.dp3t.util.DateUtils; import ch.admin.bag.dp3t.util.NotificationUtil; import ch.admin.bag.dp3t.util.PhoneUtil; +import ch.admin.bag.dp3t.util.StringUtil; import ch.admin.bag.dp3t.util.UrlUtil; import ch.admin.bag.dp3t.viewmodel.TracingViewModel; @@ -129,12 +132,26 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat if (tracingStatusInterface.isReportedAsInfected()) { headerType = ReportsHeaderFragment.Type.POSITIVE_TESTED; infectedView.setVisibility(View.VISIBLE); + + // Show the onset date of the report + long onsetDateInMillis = secureStorage.getPositiveReportOnsetDate(); + if (onsetDateInMillis > 0L) { + infectedView.findViewById(R.id.card_encounters_faq_who_is_notified_container).setVisibility(View.VISIBLE); + String formattedDate = DateUtils.getFormattedDateWrittenMonth(onsetDateInMillis); + String faqText = getString(R.string.meldungen_positive_tested_faq2_text).replace("{ONSET_DATE}", formattedDate); + Spannable formattedText = StringUtil.makePartiallyBold(faqText, formattedDate); + ((TextView) infectedView.findViewById(R.id.card_encounters_faq_who_is_notified)).setText(formattedText); + } else { + infectedView.findViewById(R.id.card_encounters_faq_who_is_notified_container).setVisibility(View.GONE); + } + infectedView.findViewById(R.id.delete_reports).setOnClickListener(v -> { AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(), R.style.NextStep_AlertDialogStyle); builder.setMessage(R.string.delete_infection_dialog) .setPositiveButton(R.string.delete_infection_dialog_finish_button, (dialog, id) -> { tracingStatusInterface.resetInfectionStatus(getContext()); secureStorage.setIsolationEndDialogTimestamp(-1L); + secureStorage.setPositiveReportOnsetDate(-1L); getParentFragmentManager().popBackStack(); }) .setNegativeButton(R.string.cancel, (dialog, id) -> { diff --git a/app/src/main/java/ch/admin/bag/dp3t/storage/SecureStorage.java b/app/src/main/java/ch/admin/bag/dp3t/storage/SecureStorage.java index 175be21c8..9b98a4038 100644 --- a/app/src/main/java/ch/admin/bag/dp3t/storage/SecureStorage.java +++ b/app/src/main/java/ch/admin/bag/dp3t/storage/SecureStorage.java @@ -72,6 +72,7 @@ public class SecureStorage { private static final String KEY_ISOLATION_END_DIALOG_TIMESTAMP = "isolation_end_dialog_timestamp"; private static final String KEY_APP_VERSION_CODE = "app_version_code"; private static final String KEY_SCHEDULED_FAKE_WORKER_NAME = "scheduled_fake_worker_name"; + private static final String KEY_POSITIVE_REPORT_ONSET_DATE = "positive_report_onset_date"; private static SecureStorage instance; @@ -378,4 +379,12 @@ public String getScheduledFakeWorkerName() { return prefs.getString(KEY_SCHEDULED_FAKE_WORKER_NAME, null); } + public long getPositiveReportOnsetDate() { + return prefs.getLong(KEY_POSITIVE_REPORT_ONSET_DATE, -1L); + } + + public void setPositiveReportOnsetDate(long onsetDate) { + prefs.edit().putLong(KEY_POSITIVE_REPORT_ONSET_DATE, onsetDate).apply(); + } + } \ No newline at end of file diff --git a/app/src/main/java/ch/admin/bag/dp3t/util/StringUtil.java b/app/src/main/java/ch/admin/bag/dp3t/util/StringUtil.java index 69e41b1e6..2d6491f6d 100644 --- a/app/src/main/java/ch/admin/bag/dp3t/util/StringUtil.java +++ b/app/src/main/java/ch/admin/bag/dp3t/util/StringUtil.java @@ -11,6 +11,7 @@ package ch.admin.bag.dp3t.util; import android.graphics.Typeface; +import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; import android.text.style.StyleSpan; @@ -20,6 +21,22 @@ public class StringUtil { + /** + * Creates a spannable where the {@code boldString} is set to bold within the {@code fullString}. + * Be aware that this only applies to the first occurence. + * + * @param fullString The entire string + * @param boldString The partial string to be made bold + * @return A partially bold spannable + */ + public static Spannable makePartiallyBold(@NonNull String fullString, @NonNull String boldString) { + int start = fullString.indexOf(boldString); + if (start >= 0) { + return makePartiallyBold(fullString, start, start + boldString.length()); + } + return new SpannableString(fullString); + } + public static SpannableString makePartiallyBold(@NonNull String string, int start, int end) { SpannableString result = new SpannableString(string); result.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); diff --git a/app/src/main/res/layout/card_what_to_do_self_isolation.xml b/app/src/main/res/layout/card_what_to_do_self_isolation.xml index 98e1a74fb..80a44722c 100644 --- a/app/src/main/res/layout/card_what_to_do_self_isolation.xml +++ b/app/src/main/res/layout/card_what_to_do_self_isolation.xml @@ -147,6 +147,42 @@ + + + + + + + + + + + + +