diff options
Diffstat (limited to 'app/src/main/java/foundation')
3 files changed, 65 insertions, 14 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt index 16cd4a0..e43e5aa 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt @@ -17,6 +17,7 @@ package foundation.e.privacycentralapp.features.trackers.apptrackers +import android.net.Uri import android.util.Log import foundation.e.flowmvi.Actor import foundation.e.flowmvi.Reducer @@ -68,12 +69,14 @@ class AppTrackersFeature( sealed class SingleEvent { data class ErrorEvent(val error: Any) : SingleEvent() object NewStatisticsAvailableSingleEvent : SingleEvent() + data class OpenUrlEvent(val url: Uri): SingleEvent() } sealed class Action { data class InitAction(val packageName: String) : Action() data class BlockAllToggleAction(val isBlocked: Boolean) : Action() data class ToggleTrackerAction(val tracker: Tracker, val isBlocked: Boolean) : Action() + data class ClickTracker(val tracker: Tracker): Action() object FetchStatistics : Action() } @@ -87,9 +90,12 @@ class AppTrackersFeature( object NewStatisticsAvailablesEffect : Effect() data class QuickPrivacyUpdatedEffect(val enabled: Boolean) : Effect() object QuickPrivacyDisabledWarningEffect : Effect() + data class OpenUrlEffect(val url: Uri): Effect() } companion object { + + private const val exodusBaseUrl = "https://reports.exodus-privacy.eu.org/fr/trackers/" fun create( initialState: State = State(), coroutineScope: CoroutineScope, @@ -179,6 +185,15 @@ class AppTrackersFeature( } ?: run { flowOf(Effect.ErrorEffect("No appDesc.")) } } else flowOf(Effect.NoEffect) } + is Action.ClickTracker -> { + flowOf(action.tracker.getExodusId()?.let { + try { + Effect.OpenUrlEffect(Uri.parse(exodusBaseUrl + it)) + } catch (e: Exception) { + Effect.ErrorEffect("Invalid Url") + } + } ?: Effect.NoEffect) + } is Action.FetchStatistics -> flowOf( state.appDesc?.uid?.let { Effect.AvailableTrackersListEffect( @@ -196,9 +211,17 @@ class AppTrackersFeature( SingleEvent.ErrorEvent(R.string.apptrackers_error_quickprivacy_disabled) is Effect.NewStatisticsAvailablesEffect -> SingleEvent.NewStatisticsAvailableSingleEvent + is Effect.OpenUrlEffect -> + SingleEvent.OpenUrlEvent(effect.url) else -> null } } ) } } + +fun Tracker.getExodusId(): String? { + return if (id.startsWith("exodus_")) { + id.substringAfter("exodus_") + } else null +} 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 440edf7..a823df3 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 @@ -17,6 +17,8 @@ package foundation.e.privacycentralapp.features.trackers.apptrackers +import android.content.ActivityNotFoundException +import android.content.Intent import android.os.Bundle import android.view.View import android.widget.Toast @@ -76,6 +78,12 @@ class AppTrackersFragment : is SingleEvent.NewStatisticsAvailableSingleEvent -> { viewModel.submitAction(Action.FetchStatistics) } + is SingleEvent.OpenUrlEvent -> + try { + startActivity(Intent(Intent.ACTION_VIEW, event.url)) + } catch (e: ActivityNotFoundException) { + displayToast("No application to see webpages") + } } } } @@ -104,14 +112,13 @@ class AppTrackersFragment : binding.trackers.apply { layoutManager = LinearLayoutManager(requireContext()) setHasFixedSize(true) - adapter = ToggleTrackersAdapter(R.layout.apptrackers_item_tracker_toggle) { tracker, isBlocked -> - viewModel.submitAction( - Action.ToggleTrackerAction( - tracker, - isBlocked - ) - ) - } + adapter = ToggleTrackersAdapter( + R.layout.apptrackers_item_tracker_toggle, + onToggleSwitch = { tracker, isBlocked -> + viewModel.submitAction(Action.ToggleTrackerAction(tracker, isBlocked)) + }, + onClickTitle = { viewModel.submitAction(Action.ClickTracker(it)) } + ) } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt index 580a60c..134ff4f 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt @@ -22,16 +22,23 @@ import android.view.View import android.view.ViewGroup import android.widget.Switch import android.widget.TextView +import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import foundation.e.privacycentralapp.R import foundation.e.privacymodules.trackers.Tracker +import android.text.style.UnderlineSpan + +import android.text.SpannableString + + + class ToggleTrackersAdapter( private val itemsLayout: Int, - private val listener: (Tracker, Boolean) -> Unit -) : - RecyclerView.Adapter<ToggleTrackersAdapter.ViewHolder>() { + private val onToggleSwitch: (Tracker, Boolean) -> Unit, + private val onClickTitle: (Tracker) -> Unit +) : RecyclerView.Adapter<ToggleTrackersAdapter.ViewHolder>() { var isEnabled = true @@ -42,7 +49,17 @@ class ToggleTrackersAdapter( val toggleOverlay: View = view.findViewById(R.id.toggle_clicker) fun bind(item: Pair<Tracker, Boolean>, isEnabled: Boolean) { - title.text = item.first.label + val text = item.first.label + if (item.first.website != null) { + title.setTextColor(ContextCompat.getColor(title.context, R.color.accent)) + val spannable = SpannableString(text) + spannable.setSpan(UnderlineSpan(), 0, spannable.length, 0) + title.text = spannable + } else { + title.setTextColor(ContextCompat.getColor(title.context, R.color.black)) + title.text = text + } + toggle.isChecked = item.second toggle.isEnabled = isEnabled toggleOverlay.isVisible = !isEnabled @@ -62,10 +79,14 @@ class ToggleTrackersAdapter( .inflate(itemsLayout, parent, false) val holder = ViewHolder(view) holder.toggle.setOnClickListener { - listener(dataSet[holder.adapterPosition].first, holder.toggle.isChecked) + onToggleSwitch(dataSet[holder.adapterPosition].first, holder.toggle.isChecked) } holder.toggleOverlay.setOnClickListener { - listener(dataSet[holder.adapterPosition].first, false) + onToggleSwitch(dataSet[holder.adapterPosition].first, false) + } + + holder.title.setOnClickListener { + onClickTitle(dataSet[holder.adapterPosition].first) } return holder |