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 ++----- 3 files changed, 27 insertions(+), 16 deletions(-) (limited to 'app/src/main/java/foundation/e') 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, -- cgit v1.2.1