diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-12-21 07:51:06 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-12-21 07:51:06 +0000 |
commit | 224da0609f609494a9f9b9da65f1cd86d6198e05 (patch) | |
tree | a89be6d79df5bb8b96693763f526b54387d19700 /app/src/main/java/foundation | |
parent | cfa3e314f19b81d12694ca797f448b3966442958 (diff) |
6124: learn more button for trackers info
Diffstat (limited to 'app/src/main/java/foundation')
3 files changed, 64 insertions, 1 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 8adf256..83359e1 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,18 @@ 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.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 +85,35 @@ 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(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 + ) + + with(binding.trackersInfo) { + linksClickable = true + isClickable = true + movementMethod = LinkMovementMethod.getInstance() + text = spannable + } + setToolTipForAsterisk( textView = binding.trackersAppsListTitle, textId = R.string.trackers_applist_title, @@ -110,6 +148,17 @@ class TrackersFragment : addToBackStack("apptrackers") } } + is TrackersViewModel.SingleEvent.OpenUrl -> { + try { + startActivity(Intent(Intent.ACTION_VIEW, event.url)) + } catch (e: ActivityNotFoundException) { + 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/TrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt index 07828f8..2cdfabc 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/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt index 6aeac8e..f15119e 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( |