From c3addf38912638a1a05c33f1c2fb4c65be50e225 Mon Sep 17 00:00:00 2001
From: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
Date: Tue, 15 Sep 2020 19:13:10 +0200
Subject: [PATCH] Improve Explanation for usage of location services
 (EXPOSUREAPP-2384) (#1137)

* updates location text and activated autolink

* updated string

* own layout for location to set the url

* added fallback if label isn't found in string

Co-authored-by: chris-cwa <chris.cwa.sap@gmail.com>
---
 .../information/InformationLegalFragment.kt   |  2 -
 .../LocationTracingStatusCardBodyTextView.kt  | 34 +++++++
 .../java/de/rki/coronawarnapp/util/Views.kt   | 43 ++++++++
 .../res/layout/fragment_settings_tracing.xml  |  3 +-
 .../include_tracing_status_card_location.xml  | 97 +++++++++++++++++++
 .../src/main/res/values-de/strings.xml        |  4 +-
 .../src/main/res/values/strings.xml           |  2 +
 7 files changed, 180 insertions(+), 5 deletions(-)
 create mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/LocationTracingStatusCardBodyTextView.kt
 create mode 100644 Corona-Warn-App/src/main/res/layout/include_tracing_status_card_location.xml

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt
index a2407b577..62a42f82f 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/information/InformationLegalFragment.kt
@@ -44,8 +44,6 @@ class InformationLegalFragment : Fragment() {
     private fun setUpContactFormLinks() {
         binding.informationLegalContactForm.informationLegalContactForm
             .convertToHyperlink(getString(R.string.information_legal_subtitle_contact_url))
-        binding.informationLegalContactForm.informationLegalContactForm
-            .movementMethod = LinkMovementMethod.getInstance()
         binding.informationLegalContactForm.informationLegalContactFormNonEnDe
             .movementMethod = LinkMovementMethod.getInstance()
     }
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/LocationTracingStatusCardBodyTextView.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/LocationTracingStatusCardBodyTextView.kt
new file mode 100644
index 000000000..cf71bbc22
--- /dev/null
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/view/LocationTracingStatusCardBodyTextView.kt
@@ -0,0 +1,34 @@
+package de.rki.coronawarnapp.ui.view
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatTextView
+import de.rki.coronawarnapp.R
+import de.rki.coronawarnapp.util.setUrl
+
+class LocationTracingStatusCardBodyTextView : AppCompatTextView {
+
+    constructor(context: Context?) : super(context) {
+        setUrl()
+    }
+
+    constructor(context: Context?, attrs: AttributeSet) : super(context, attrs) {
+        setUrl()
+    }
+
+    constructor(
+        context: Context?,
+        attrs: AttributeSet,
+        defStyleAttr: Int
+    ) : super(context, attrs, defStyleAttr) {
+        setUrl()
+    }
+
+    private fun setUrl() {
+        setUrl(
+            R.string.settings_tracing_status_location_body,
+            "FAQ",
+            context.getString(R.string.settings_tracing_status_location_body_url)
+        )
+    }
+}
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Views.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Views.kt
index 39caae195..0b70bf717 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Views.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/Views.kt
@@ -2,12 +2,55 @@ package de.rki.coronawarnapp.util
 
 import android.text.SpannableString
 import android.text.Spanned
+import android.text.method.LinkMovementMethod
 import android.text.style.URLSpan
 import android.widget.TextView
+import androidx.annotation.StringRes
 
 fun TextView.convertToHyperlink(url: String) {
     setText(
         SpannableString(text).apply { setSpan(URLSpan(url), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) },
         TextView.BufferType.SPANNABLE
     )
+    movementMethod = LinkMovementMethod.getInstance()
+}
+
+fun TextView.setUrlText(@StringRes textRes: Int, url: String) {
+    context.getString(textRes, url).also {
+        val indexOf = it.indexOf(url)
+        setText(
+            SpannableString(it).apply {
+                setSpan(
+                    URLSpan(url),
+                    indexOf,
+                    indexOf + url.length,
+                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
+                )
+            },
+            TextView.BufferType.SPANNABLE
+        )
+        movementMethod = LinkMovementMethod.getInstance()
+    }
+}
+
+fun TextView.setUrl(@StringRes textRes: Int, label: String, url: String) {
+    context.getString(textRes).also {
+        val indexOf = it.indexOf(label)
+        if (indexOf > 0) {
+            setText(
+                SpannableString(it).apply {
+                    setSpan(
+                        URLSpan(url),
+                        indexOf,
+                        indexOf + label.length,
+                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
+                    )
+                },
+                TextView.BufferType.SPANNABLE
+            )
+            movementMethod = LinkMovementMethod.getInstance()
+        } else {
+            text = it
+        }
+    }
 }
diff --git a/Corona-Warn-App/src/main/res/layout/fragment_settings_tracing.xml b/Corona-Warn-App/src/main/res/layout/fragment_settings_tracing.xml
index bb55bbd00..c4f43ce62 100644
--- a/Corona-Warn-App/src/main/res/layout/fragment_settings_tracing.xml
+++ b/Corona-Warn-App/src/main/res/layout/fragment_settings_tracing.xml
@@ -87,11 +87,10 @@
 
                     <include
                         android:id="@+id/settings_tracing_status_location"
-                        layout="@layout/include_tracing_status_card"
+                        layout="@layout/include_tracing_status_card_location"
                         android:layout_width="@dimen/match_constraint"
                         android:layout_height="wrap_content"
                         android:visibility="@{FormatterSettingsHelper.formatTracingStatusVisibilityLocation(tracingViewModel.isTracingEnabled(), settingsViewModel.isBluetoothEnabled(), settingsViewModel.isLocationEnabled())}"
-                        app:body="@{@string/settings_tracing_status_location_body}"
                         app:buttonText="@{@string/settings_tracing_status_location_button}"
                         app:headline="@{@string/settings_tracing_status_location_headline}"
                         app:icon="@{@drawable/ic_location}"
diff --git a/Corona-Warn-App/src/main/res/layout/include_tracing_status_card_location.xml b/Corona-Warn-App/src/main/res/layout/include_tracing_status_card_location.xml
new file mode 100644
index 000000000..e7a794e02
--- /dev/null
+++ b/Corona-Warn-App/src/main/res/layout/include_tracing_status_card_location.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <data>
+
+        <import type="de.rki.coronawarnapp.util.formatter.FormatterHelper" />
+
+        <import type="de.rki.coronawarnapp.util.formatter.FormatterAccessibilityHelper" />
+
+        <import type="android.view.View" />
+
+        <variable
+            name="tracingViewModel"
+            type="de.rki.coronawarnapp.ui.viewmodel.TracingViewModel" />
+
+        <variable
+            name="icon"
+            type="android.graphics.drawable.Drawable" />
+
+        <variable
+            name="headline"
+            type="String" />
+
+        <variable
+            name="buttonText"
+            type="String" />
+
+
+    </data>
+
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/tracing_status_card"
+        style="@style/cardTracing"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:focusable="true">
+
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/tracing_status_card_header"
+            android:layout_width="@dimen/match_constraint"
+            android:layout_height="wrap_content"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent">
+
+            <TextView
+                android:id="@+id/tracing_status_card_header_headline"
+                style="@style/headline6"
+                android:accessibilityHeading="true"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_marginEnd="@dimen/spacing_small"
+                android:text="@{headline}"
+                android:contentDescription="@{headline}"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toStartOf="@+id/tracing_status_card_header_icon"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent" />
+
+            <ImageView
+                android:id="@+id/tracing_status_card_header_icon"
+                android:layout_width="@dimen/icon_size_main_card_end"
+                android:layout_height="@dimen/icon_size_main_card_end"
+                android:importantForAccessibility="no"
+                android:focusable="false"
+                android:src="@{icon}"
+                android:visibility="@{FormatterHelper.formatVisibilityIcon(icon)}"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toEndOf="@+id/tracing_status_card_header_headline"
+                app:layout_constraintTop_toTopOf="parent" />
+        </androidx.constraintlayout.widget.ConstraintLayout>
+
+        <de.rki.coronawarnapp.ui.view.LocationTracingStatusCardBodyTextView
+            android:id="@+id/tracing_status_card_body"
+            style="@style/subtitle"
+            android:layout_width="@dimen/match_constraint"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/spacing_small"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tracing_status_card_header" />
+
+        <Button
+            android:id="@+id/tracing_status_card_button"
+            style="@style/buttonPrimary"
+            android:layout_width="@dimen/match_constraint"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/spacing_normal"
+            android:text="@{buttonText}"
+            android:visibility="@{FormatterHelper.formatVisibilityText(buttonText)}"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/tracing_status_card_body" />
+    </androidx.constraintlayout.widget.ConstraintLayout>
+</layout>
\ No newline at end of file
diff --git a/Corona-Warn-App/src/main/res/values-de/strings.xml b/Corona-Warn-App/src/main/res/values-de/strings.xml
index a0e7482d0..567febe89 100644
--- a/Corona-Warn-App/src/main/res/values-de/strings.xml
+++ b/Corona-Warn-App/src/main/res/values-de/strings.xml
@@ -541,7 +541,9 @@
     <!--XHED : settings(tracing) - headline on card about the current status and what to do -->
     <string name="settings_tracing_status_location_headline">"Standort-Verwendung erlauben"</string>
     <!-- XTXT: settings(tracing) - explains user what to do on card if location is disabled -->
-    <string name="settings_tracing_status_location_body">"Auf Ihren Standort wird nicht zugegriffen. Die Standort-Erlaubnis wird benötigt, da Google bzw. Android diese für die Verwendung von Bluetooth voraussetzt."</string>
+    <string name="settings_tracing_status_location_body">"Aktivieren Sie die Standort-Dienste. Für die Abstandsberechnung benötigt Bluetooth Low Energy aktivierte Standort-Dienste, greift dabei aber nicht auf Ihren Standort zu. Weitere Informationen finden Sie in der FAQ."</string>
+    <!-- XTXT: settings(tracing) - explains user what to do on card if location is disabled: URL -->
+    <string name="settings_tracing_status_location_body_url">https://www.coronawarn.app/de/faq/#android_location</string>
     <!-- XBUT: settings(tracing) - go to operating system settings button on card - location -->
     <string name="settings_tracing_status_location_button">"Geräte-Einstellungen öffnen"</string>
     <!--XHED : settings(tracing) - headline on card about the current status and what to do -->
diff --git a/Corona-Warn-App/src/main/res/values/strings.xml b/Corona-Warn-App/src/main/res/values/strings.xml
index 205c93f09..c9c97e9bc 100644
--- a/Corona-Warn-App/src/main/res/values/strings.xml
+++ b/Corona-Warn-App/src/main/res/values/strings.xml
@@ -544,6 +544,8 @@
     <string name="settings_tracing_status_location_headline">"Allow location access"</string>
     <!-- XTXT: settings(tracing) - explains user what to do on card if location is disabled -->
     <string name="settings_tracing_status_location_body">"Your location cannot be accessed. Google and/or Android requires access to your device\'s location to use Bluetooth."</string>
+    <!-- XTXT: settings(tracing) - explains user what to do on card if location is disabled: URL -->
+    <string name="settings_tracing_status_location_body_url"/>
     <!-- XBUT: settings(tracing) - go to operating system settings button on card - location -->
     <string name="settings_tracing_status_location_button">"Open Device Settings"</string>
     <!--XHED : settings(tracing) - headline on card about the current status and what to do -->
-- 
GitLab