From 097159b6dc02409c996b200e2461513eb0fd669b Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Sat, 3 Dec 2022 21:14:11 +0100 Subject: [PATCH 1/2] 6124: learn more button for trackers info --- .../features/trackers/TrackersFragment.kt | 44 +++++++++++++++++++ .../features/trackers/TrackersViewModel.kt | 10 +++++ app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) 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 8adf2560..1e7f9b7b 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 @@ -17,9 +17,19 @@ package foundation.e.privacycentralapp.features.trackers +import android.content.ActivityNotFoundException +import android.content.Intent import android.os.Bundle +import android.text.Spannable +import android.text.SpannableString +import android.text.SpannableStringBuilder +import android.text.method.LinkMovementMethod +import android.text.style.ClickableSpan +import android.text.style.ForegroundColorSpan +import android.text.style.UnderlineSpan import android.view.View import android.widget.Toast +import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.commit import androidx.fragment.app.replace @@ -76,6 +86,33 @@ class TrackersFragment : } } + val infoText = getString(R.string.trackers_info) + val moreText = getString(R.string.trackers_info_more) + + + val spannable = SpannableString("$infoText $moreText") + val startIndex = infoText.length + 1 + val endIndex = spannable.length + spannable.setSpan( + ForegroundColorSpan(R.color.accent), + startIndex, + endIndex, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE + ) + spannable.setSpan(UnderlineSpan(), startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE) + spannable.setSpan(object: ClickableSpan() { + override fun onClick(p0: View) { + viewModel.submitAction(TrackersViewModel.Action.ClickLearnMore) + } + }, startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE) + + with(binding.trackersInfo) { + linksClickable = true + isClickable = true + movementMethod = LinkMovementMethod.getInstance() + text = spannable + } + setToolTipForAsterisk( textView = binding.trackersAppsListTitle, textId = R.string.trackers_applist_title, @@ -110,6 +147,13 @@ class TrackersFragment : addToBackStack("apptrackers") } } + is TrackersViewModel.SingleEvent.OpenUrl -> { + try { + startActivity(Intent(Intent.ACTION_VIEW, event.url)) + } catch (e: ActivityNotFoundException) { + displayToast("No application to see webpages") + } + } } } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt index 07828f87..2cdfabcd 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt @@ -17,6 +17,7 @@ package foundation.e.privacycentralapp.features.trackers +import android.net.Uri import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import foundation.e.privacycentralapp.domain.entities.AppWithCounts @@ -38,6 +39,11 @@ class TrackersViewModel( private val trackersStatisticsUseCase: TrackersStatisticsUseCase ) : ViewModel() { + companion object { + private const val URL_LEARN_MORE_ABOUT_TRACKERS = + "https://doc.e.foundation/support-topics/advanced_privacy#trackers-blocker" + } + private val _state = MutableStateFlow(TrackersState()) val state = _state.asStateFlow() @@ -67,6 +73,8 @@ class TrackersViewModel( fun submitAction(action: Action) = viewModelScope.launch { when (action) { is Action.ClickAppAction -> actionClickApp(action) + is Action.ClickLearnMore -> + _singleEvents.emit(SingleEvent.OpenUrl(Uri.parse(URL_LEARN_MORE_ABOUT_TRACKERS))) } } @@ -79,9 +87,11 @@ class TrackersViewModel( sealed class SingleEvent { data class ErrorEvent(val error: String) : SingleEvent() data class OpenAppDetailsEvent(val appDesc: AppWithCounts) : SingleEvent() + data class OpenUrl(val url: Uri) : SingleEvent() } sealed class Action { data class ClickAppAction(val packageName: String) : Action() + object ClickLearnMore : Action() } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4d6e1f94..ad61307f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,6 +70,7 @@ Manage apps\' trackers Trackers are pieces of code hidden in apps. They collect your data and follow your activity 24/7. See which trackers are active and block them all for best protection. As it could cause some applications to malfunction, you can choose specifically which trackers you want to block. + Learn more %d trackers 24 hours past month diff --git a/build.gradle b/build.gradle index 2abc73d2..fc5247f2 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ buildscript { 'targetSdk' : 31, 'version' : [ 'major': 1, - 'minor': 4, + 'minor': 8, 'patch': 0, ], ] -- GitLab From 0e72f999657b2419fab517ea3888f0da37922686 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Tue, 20 Dec 2022 08:56:52 +0100 Subject: [PATCH 2/2] Move error message to string.xml, Lint. --- .../features/trackers/TrackersFragment.kt | 23 +++++++++++-------- .../apptrackers/AppTrackersFragment.kt | 6 ++++- app/src/main/res/values/strings.xml | 4 ++++ build.gradle | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) 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 1e7f9b7b..83359e18 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 @@ -22,7 +22,6 @@ import android.content.Intent import android.os.Bundle import android.text.Spannable import android.text.SpannableString -import android.text.SpannableStringBuilder import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan import android.text.style.ForegroundColorSpan @@ -89,22 +88,24 @@ class TrackersFragment : val infoText = getString(R.string.trackers_info) val moreText = getString(R.string.trackers_info_more) - val spannable = SpannableString("$infoText $moreText") val startIndex = infoText.length + 1 val endIndex = spannable.length spannable.setSpan( - ForegroundColorSpan(R.color.accent), + ForegroundColorSpan(ContextCompat.getColor(requireContext(), R.color.accent)), startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE ) spannable.setSpan(UnderlineSpan(), startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE) - spannable.setSpan(object: ClickableSpan() { - override fun onClick(p0: View) { - viewModel.submitAction(TrackersViewModel.Action.ClickLearnMore) - } - }, startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE) + spannable.setSpan( + object : ClickableSpan() { + override fun onClick(p0: View) { + viewModel.submitAction(TrackersViewModel.Action.ClickLearnMore) + } + }, + startIndex, endIndex, Spannable.SPAN_INCLUSIVE_EXCLUSIVE + ) with(binding.trackersInfo) { linksClickable = true @@ -151,7 +152,11 @@ class TrackersFragment : try { startActivity(Intent(Intent.ACTION_VIEW, event.url)) } catch (e: ActivityNotFoundException) { - displayToast("No application to see webpages") + Toast.makeText( + requireContext(), + R.string.error_no_activity_view_url, + Toast.LENGTH_SHORT + ).show() } } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt index 6aeac8ee..f15119e8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt @@ -108,7 +108,11 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { try { startActivity(Intent(Intent.ACTION_VIEW, event.url)) } catch (e: ActivityNotFoundException) { - displayToast("No application to see webpages") + Toast.makeText( + requireContext(), + R.string.error_no_activity_view_url, + Toast.LENGTH_SHORT + ).show() } is AppTrackersViewModel.SingleEvent.ToastTrackersControlDisabled -> Snackbar.make( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad61307f..17f5e3b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,10 @@ Blocked leaks Allowed leaks Tap on the bars for more information. + + No application to see webpages + + @string/app_name Your online privacy is protected diff --git a/build.gradle b/build.gradle index fc5247f2..e1359973 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ buildscript { 'targetSdk' : 31, 'version' : [ 'major': 1, - 'minor': 8, + 'minor': 7, 'patch': 0, ], ] -- GitLab