From f44d0f7c4a6db30e4bd29c07c56f2998c7874b51 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Sat, 17 Sep 2022 20:12:43 +0200 Subject: 256 : Add tooltip info about apps lists. --- .../e/privacycentralapp/common/TextViewHelpers.kt | 55 ++++++++++++++++++++++ .../internetprivacy/InternetPrivacyFragment.kt | 9 +++- .../features/trackers/TrackersFragment.kt | 7 +++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt new file mode 100644 index 0000000..a5c576c --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package foundation.e.privacycentralapp.common + +import android.content.Context +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ImageSpan +import android.widget.TextView +import androidx.annotation.StringRes +import androidx.appcompat.content.res.AppCompatResources +import androidx.appcompat.widget.TooltipCompat +import foundation.e.privacycentralapp.R + +fun setToolTipForAsterisk( + textView: TextView, + @StringRes textId: Int, + @StringRes tooltipTextId: Int) { + textView.text = asteriskAsInfoIconSpannable(textView.context, textId) + TooltipCompat.setTooltipText(textView, textView.context.getString(tooltipTextId)) + + textView.setOnClickListener { it.performLongClick() } +} + +private fun asteriskAsInfoIconSpannable(context: Context, @StringRes textId: Int): Spannable { + val spannable = SpannableString(context.getString(textId)) + val index = spannable.lastIndexOf("*") + if (index != -1) { + AppCompatResources.getDrawable(context, R.drawable.ic_info_16dp)?.let { + it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight) + spannable.setSpan( + ImageSpan(it), + index, + index + 1, + Spannable.SPAN_INCLUSIVE_INCLUSIVE + ) + } + } + return spannable +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt index ff8e78f..749fae4 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt @@ -33,10 +33,11 @@ import foundation.e.privacycentralapp.PrivacyCentralApplication import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.common.NavToolbarFragment import foundation.e.privacycentralapp.common.ToggleAppsAdapter +import foundation.e.privacycentralapp.common.extensions.toText import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar +import foundation.e.privacycentralapp.common.setToolTipForAsterisk import foundation.e.privacycentralapp.databinding.FragmentInternetActivityPolicyBinding import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode -import foundation.e.privacycentralapp.common.extensions.toText import kotlinx.coroutines.launch import java.util.Locale @@ -82,6 +83,12 @@ class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_ac viewModel.submitAction(InternetPrivacyViewModel.Action.UseHiddenIPAction) } + setToolTipForAsterisk( + textView = binding.ipscramblingSelectApps, + textId = R.string.ipscrambling_select_app, + tooltipTextId = R.string.ipscrambling_app_list_infos + ) + binding.ipscramblingSelectLocation.apply { adapter = ArrayAdapter( requireContext(), android.R.layout.simple_spinner_item, diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt index 4992230..491f625 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt @@ -36,6 +36,7 @@ import foundation.e.privacycentralapp.common.AppsAdapter import foundation.e.privacycentralapp.common.GraphHolder import foundation.e.privacycentralapp.common.NavToolbarFragment import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar +import foundation.e.privacycentralapp.common.setToolTipForAsterisk import foundation.e.privacycentralapp.databinding.FragmentTrackersBinding import foundation.e.privacycentralapp.databinding.TrackersItemGraphBinding import foundation.e.privacycentralapp.domain.entities.TrackersPeriodicStatistics @@ -82,6 +83,12 @@ class TrackersFragment : viewModel.submitAction(TrackersViewModel.Action.CloseQuickPrivacyDisabledMessage) } + setToolTipForAsterisk( + textView = binding.trackersAppsListTitle, + textId = R.string.trackers_applist_title, + tooltipTextId = R.string.trackers_applist_infos + ) + viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { render(viewModel.state.value) -- cgit v1.2.1 From 15fc60edf7b9dbda7be96dbafb316edc70a016b6 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Tue, 20 Sep 2022 09:13:54 +0200 Subject: Tint icon with text color to handle dark mode --- .../e/privacycentralapp/common/TextViewHelpers.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt index a5c576c..1cdc06f 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -18,6 +18,7 @@ package foundation.e.privacycentralapp.common import android.content.Context +import android.content.res.ColorStateList import android.text.Spannable import android.text.SpannableString import android.text.style.ImageSpan @@ -30,18 +31,24 @@ import foundation.e.privacycentralapp.R fun setToolTipForAsterisk( textView: TextView, @StringRes textId: Int, - @StringRes tooltipTextId: Int) { - textView.text = asteriskAsInfoIconSpannable(textView.context, textId) + @StringRes tooltipTextId: Int +) { + textView.text = asteriskAsInfoIconSpannable(textView.context, textId, textView.textColors) TooltipCompat.setTooltipText(textView, textView.context.getString(tooltipTextId)) textView.setOnClickListener { it.performLongClick() } } -private fun asteriskAsInfoIconSpannable(context: Context, @StringRes textId: Int): Spannable { +private fun asteriskAsInfoIconSpannable( + context: Context, + @StringRes textId: Int, + tint: ColorStateList +): Spannable { val spannable = SpannableString(context.getString(textId)) val index = spannable.lastIndexOf("*") if (index != -1) { AppCompatResources.getDrawable(context, R.drawable.ic_info_16dp)?.let { + it.setTintList(tint) it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight) spannable.setSpan( ImageSpan(it), -- cgit v1.2.1 From 227c31abea5fd56c7795f973c57729afbec3485b Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Fri, 23 Sep 2022 09:06:44 +0200 Subject: Fix vertical positionning of (i) icon. --- .../main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt index 1cdc06f..25a3633 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.res.ColorStateList import android.text.Spannable import android.text.SpannableString +import android.text.style.DynamicDrawableSpan import android.text.style.ImageSpan import android.widget.TextView import androidx.annotation.StringRes @@ -51,7 +52,7 @@ private fun asteriskAsInfoIconSpannable( it.setTintList(tint) it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight) spannable.setSpan( - ImageSpan(it), + ImageSpan(it, DynamicDrawableSpan.ALIGN_CENTER), index, index + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE -- cgit v1.2.1