From e6ba99e31da49df559da60e8d012e40813ee14f0 Mon Sep 17 00:00:00 2001 From: jacquarg Date: Sun, 27 Feb 2022 12:00:20 +0100 Subject: Add trackers summary count on apptrackers, #4597 --- .../trackers/apptrackers/AppTrackersFeature.kt | 27 ++++++++++++++-------- .../trackers/apptrackers/AppTrackersFragment.kt | 8 +++++++ .../trackers/apptrackers/ToggleTrackersAdapter.kt | 8 ++----- app/src/main/res/layout/apptrackers_fragment.xml | 7 ++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 35 insertions(+), 16 deletions(-) (limited to 'app/src') 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 e43e5aa..b35fbca 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 @@ -64,19 +64,24 @@ class AppTrackersFeature( return null } } + + fun getTrackersCount() = trackers?.size ?: 0 + fun getBlockedTrackersCount(): Int = if (isBlockingActivated) + getTrackersCount() - (whitelist?.size ?: 0) + else 0 } sealed class SingleEvent { data class ErrorEvent(val error: Any) : SingleEvent() object NewStatisticsAvailableSingleEvent : SingleEvent() - data class OpenUrlEvent(val url: Uri): 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() + data class ClickTracker(val tracker: Tracker) : Action() object FetchStatistics : Action() } @@ -90,7 +95,7 @@ class AppTrackersFeature( object NewStatisticsAvailablesEffect : Effect() data class QuickPrivacyUpdatedEffect(val enabled: Boolean) : Effect() object QuickPrivacyDisabledWarningEffect : Effect() - data class OpenUrlEffect(val url: Uri): Effect() + data class OpenUrlEffect(val url: Uri) : Effect() } companion object { @@ -186,13 +191,15 @@ class AppTrackersFeature( } 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) + 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 { 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 a823df3..8e2dc3b 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 @@ -128,6 +128,14 @@ class AppTrackersFragment : } override fun render(state: State) { + + binding.trackersCountSummary.text = if (state.getTrackersCount() == 0) "" + else getString( + R.string.apptrackers_trackers_count_summary, + state.getBlockedTrackersCount(), + state.getTrackersCount() + ) + binding.blockAllToggle.isChecked = state.isBlockingActivated binding.trackersListTitle.isVisible = state.isBlockingActivated 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 134ff4f..82f2d2c 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 @@ -17,6 +17,8 @@ package foundation.e.privacycentralapp.features.trackers.apptrackers +import android.text.SpannableString +import android.text.style.UnderlineSpan import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -27,12 +29,6 @@ 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, diff --git a/app/src/main/res/layout/apptrackers_fragment.xml b/app/src/main/res/layout/apptrackers_fragment.xml index 13f58e3..17d992e 100644 --- a/app/src/main/res/layout/apptrackers_fragment.xml +++ b/app/src/main/res/layout/apptrackers_fragment.xml @@ -41,6 +41,13 @@ android:layout_width="match_parent" android:orientation="vertical" > + No trackers were detected yet. If new trackers are detected they will be updated here. No trackers were detected yet. All future trackers will be blocked. Enable Quick Privacy to be able to activate/deactivate trackers. + %1$d blocked trackers out of %2$d detected trackers Quick protection enables these settings when turned on -- cgit v1.2.1