diff options
author | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-04-12 18:55:02 +0200 |
---|---|---|
committer | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-04-12 18:55:02 +0200 |
commit | 14815678aaa5020e81f0cca9274f289e6ac7e2d5 (patch) | |
tree | d3843d84ed1da95f9f43a34bd1fc82c480b789cf /app/src | |
parent | b14d22413713fd865fafb8a53e44fd74017a6279 (diff) |
5248 hide whitelist app trackers and fix counts when privacy protection disabled.
Diffstat (limited to 'app/src')
6 files changed, 66 insertions, 41 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt index 72dffe9..4b19083 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt @@ -59,9 +59,8 @@ class AppListsRepository( return appDescriptions.value.second } - fun getVisibleAndHiddenApps(): List<ApplicationDescription> { - return appDescriptions.value.first + appDescriptions.value.second - } + fun getVisibleAndHiddenApps(): Flow<List<ApplicationDescription>> = getVisibleApps() + .map { it + getHiddenSystemApps() } fun getApplicationDescription(packageName: String): ApplicationDescription? { return appDescriptions.value.first.find { it.packageName == packageName } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt index 55887ed..6b4e098 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt @@ -28,6 +28,7 @@ import foundation.e.privacymodules.trackers.Tracker import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import java.time.ZonedDateTime import java.time.format.DateTimeFormatter @@ -142,7 +143,8 @@ class TrackersStatisticsUseCase( apps.map { app -> AppWithCounts( app, - blockTrackersPrivacyModule.isWhitelisted(app.uid), + !blockTrackersPrivacyModule.isBlockingEnabled() || + blockTrackersPrivacyModule.isWhitelisted(app.uid), appListsRepository.foldForHiddenSystemApp(app.uid) { trackersCounts.getOrDefault(it, 0) }, @@ -154,23 +156,20 @@ class TrackersStatisticsUseCase( } } - fun getNonBLockedTrackersCount(): Int { - return if (blockTrackersPrivacyModule.isBlockingEnabled()) { - val whiteListedTrackers = mutableSetOf<Tracker>() - - val whiteListedAppUids = blockTrackersPrivacyModule.getWhiteListedApp() - - appListsRepository.getVisibleAndHiddenApps().forEach { app -> - if (app.uid in whiteListedAppUids) { - whiteListedTrackers.addAll(getTrackers(app.uid)) - } else { - whiteListedTrackers.addAll(blockTrackersPrivacyModule.getWhiteList(app.uid)) + fun getNonBlockedTrackersCount(): Flow<Int> { + return if (blockTrackersPrivacyModule.isBlockingEnabled()) + appListsRepository.getVisibleAndHiddenApps().map { apps -> + val whiteListedTrackers = mutableSetOf<Tracker>() + val whiteListedAppUids = blockTrackersPrivacyModule.getWhiteListedApp() + apps.forEach { app -> + if (app.uid in whiteListedAppUids) { + whiteListedTrackers.addAll(getTrackers(app.uid)) + } else { + whiteListedTrackers.addAll(blockTrackersPrivacyModule.getWhiteList(app.uid)) + } } + whiteListedTrackers.size } - - whiteListedTrackers.size - } else { - trackTrackersPrivacyModule.getTrackersCount() - } + else flowOf(trackTrackersPrivacyModule.getTrackersCount()) } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt index e8302f4..ca45393 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt @@ -30,7 +30,6 @@ import foundation.e.privacycentralapp.domain.usecases.IpScramblingStateUseCase import foundation.e.privacycentralapp.domain.usecases.TrackersStateUseCase import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge @@ -161,20 +160,20 @@ class DashboardFeature( Effect.OpenInternetActivityPrivacyEffect ) Action.ShowTrackers -> flowOf(Effect.OpenTrackersEffect) - Action.FetchStatistics -> flow<Effect> { - emit( - trackersStatisticsUseCase.getDayStatistics() - .let { (dayStatistics, trackersCount) -> - Effect.TrackersStatisticsUpdatedEffect( - dayStatistics = dayStatistics.callsBlockedNLeaked, - dayLabels = dayStatistics.periods, - dayTrackersCount = dayStatistics.trackersCount, - trackersCount = trackersCount, - activeTrackersCount = trackersStatisticsUseCase.getNonBLockedTrackersCount() - ) - } - ) - } + Action.FetchStatistics -> + trackersStatisticsUseCase.getNonBlockedTrackersCount() + .map { nonBlockedTrackersCount -> + trackersStatisticsUseCase.getDayStatistics() + .let { (dayStatistics, trackersCount) -> + Effect.TrackersStatisticsUpdatedEffect( + dayStatistics = dayStatistics.callsBlockedNLeaked, + dayLabels = dayStatistics.periods, + dayTrackersCount = dayStatistics.trackersCount, + trackersCount = trackersCount, + activeTrackersCount = nonBlockedTrackersCount + ) + } + } } }, singleEventProducer = { _, _, effect -> 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 270dfcb..c1eef47 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 @@ -66,7 +66,7 @@ class AppTrackersFeature( } fun getTrackersCount() = trackers?.size ?: 0 - fun getBlockedTrackersCount(): Int = if (isBlockingActivated) + fun getBlockedTrackersCount(): Int = if (isQuickPrivacyEnabled && isBlockingActivated) getTrackersCount() - (whitelist?.size ?: 0) else 0 } @@ -160,7 +160,9 @@ class AppTrackersFeature( } ?: flowOf(Effect.ErrorEffect(R.string.apptrackers_error_no_app)) is Action.BlockAllToggleAction -> - state.appDesc?.uid?.let { appUid -> + if (!state.isQuickPrivacyEnabled) { + flowOf(Effect.QuickPrivacyDisabledWarningEffect) + } else state.appDesc?.uid?.let { appUid -> flow { trackersStateUseCase.toggleAppWhitelist(appUid, !action.isBlocked) 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 8e2dc3b..d6edee6 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 @@ -109,6 +109,10 @@ class AppTrackersFragment : viewModel.submitAction(Action.BlockAllToggleAction(binding.blockAllToggle.isChecked)) } + binding.blockAllToggleClicker.setOnClickListener { + viewModel.submitAction(Action.BlockAllToggleAction(false)) + } + binding.trackers.apply { layoutManager = LinearLayoutManager(requireContext()) setHasFixedSize(true) @@ -128,7 +132,6 @@ class AppTrackersFragment : } override fun render(state: State) { - binding.trackersCountSummary.text = if (state.getTrackersCount() == 0) "" else getString( R.string.apptrackers_trackers_count_summary, @@ -137,6 +140,8 @@ class AppTrackersFragment : ) binding.blockAllToggle.isChecked = state.isBlockingActivated + binding.blockAllToggle.isEnabled = state.isQuickPrivacyEnabled + binding.blockAllToggleClicker.isVisible = !state.isQuickPrivacyEnabled binding.trackersListTitle.isVisible = state.isBlockingActivated diff --git a/app/src/main/res/layout/apptrackers_fragment.xml b/app/src/main/res/layout/apptrackers_fragment.xml index b0b9e71..3eb9168 100644 --- a/app/src/main/res/layout/apptrackers_fragment.xml +++ b/app/src/main/res/layout/apptrackers_fragment.xml @@ -60,10 +60,31 @@ android:layout_weight="1" android:text="@string/apptrackers_block_all_toggle" /> - <Switch - android:id="@+id/block_all_toggle" + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content"> + + <Switch + android:id="@+id/block_all_toggle" + android:layout_width="wrap_content" + android:layout_height="24dp" + android:checked="true" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + /> + <View + android:id="@+id/block_all_toggle_clicker" + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:clickable="true" + /> + </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> <View android:layout_width="match_parent" |