diff options
author | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-09-17 18:24:52 +0200 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-09-20 08:11:51 +0200 |
commit | 0a8527b4947ce40b9864305139afedc59f00ad87 (patch) | |
tree | b07b005028af5a682d9b08c5d28c6af74295dd2e /app/src/main | |
parent | 6495fe4a88b59648892bf85f8a02eb37d6a01974 (diff) |
4208 Add CUSTOM state for tracker control.
Diffstat (limited to 'app/src/main')
8 files changed, 53 insertions, 18 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt new file mode 100644 index 0000000..ae70ba3 --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package foundation.e.privacycentralapp.domain.entities + +enum class TrackerMode { + DENIED, CUSTOM, VULNERABLE +}
\ No newline at end of file diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt index 7377568..a9c608e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -22,6 +22,7 @@ import foundation.e.privacycentralapp.data.repositories.LocalStateRepository import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode import foundation.e.privacycentralapp.domain.entities.LocationMode import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState +import foundation.e.privacycentralapp.domain.entities.TrackerMode import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @@ -64,11 +65,15 @@ class GetQuickPrivacyStateUseCase( } } - val isTrackersDenied: Flow<Boolean> = combine( + val trackerMode: Flow<TrackerMode> = combine( localStateRepository.quickPrivacyEnabledFlow, localStateRepository.areAllTrackersBlocked ) { isQuickPrivacyEnabled, isAllTrackersBlocked -> - isQuickPrivacyEnabled && isAllTrackersBlocked + when { + isQuickPrivacyEnabled && isAllTrackersBlocked -> TrackerMode.DENIED + isQuickPrivacyEnabled && !isAllTrackersBlocked -> TrackerMode.CUSTOM + else -> TrackerMode.VULNERABLE + } } val isLocationHidden: Flow<Boolean> = combine( diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index adb54bb..4d38ec8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -42,6 +42,7 @@ import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar import foundation.e.privacycentralapp.databinding.FragmentDashboardBinding import foundation.e.privacycentralapp.domain.entities.LocationMode import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState +import foundation.e.privacycentralapp.domain.entities.TrackerMode import foundation.e.privacycentralapp.features.dashboard.DashboardViewModel.Action import foundation.e.privacycentralapp.features.dashboard.DashboardViewModel.SingleEvent import foundation.e.privacycentralapp.features.internetprivacy.InternetPrivacyFragment @@ -199,15 +200,16 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { binding.togglePrivacyCentral.isChecked = state.quickPrivacyState.isEnabled() - binding.stateTrackers.text = getString( - if (state.isTrackersDenied) R.string.dashboard_state_trackers_on - else R.string.dashboard_state_trackers_off - ) + binding.stateTrackers.text = getString(when(state.trackerMode) { + TrackerMode.DENIED -> R.string.dashboard_state_trackers_on + TrackerMode.VULNERABLE -> R.string.dashboard_state_trackers_off + TrackerMode.CUSTOM -> R.string.dashboard_state_trackers_custom + }) binding.stateTrackers.setTextColor( getColor( requireContext(), - if (state.isTrackersDenied) R.color.green_valid - else R.color.red_off + if (state.trackerMode == TrackerMode.VULNERABLE) R.color.red_off + else R.color.green_valid ) ) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt index 65aa444..fb00f07 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt @@ -19,10 +19,11 @@ package foundation.e.privacycentralapp.features.dashboard import foundation.e.privacycentralapp.domain.entities.LocationMode import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState +import foundation.e.privacycentralapp.domain.entities.TrackerMode data class DashboardState( val quickPrivacyState: QuickPrivacyState = QuickPrivacyState.DISABLED, - val isTrackersDenied: Boolean = false, + val trackerMode: TrackerMode = TrackerMode.VULNERABLE, val isLocationHidden: Boolean = false, val isIpHidden: Boolean? = false, val locationMode: LocationMode = LocationMode.REAL_LOCATION, diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt index e3a9722..0ddceb1 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt @@ -63,8 +63,8 @@ class DashboardViewModel( trackersStatisticsUseCase.listenUpdates().flatMapLatest { fetchStatistics() }, - getPrivacyStateUseCase.isTrackersDenied.map { - _state.update { s -> s.copy(isTrackersDenied = it) } + getPrivacyStateUseCase.trackerMode.map { + _state.update { s -> s.copy(trackerMode = it) } }, getPrivacyStateUseCase.isLocationHidden.map { _state.update { s -> s.copy(isLocationHidden = it) } diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt index 62e279f..e886cd8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt @@ -35,7 +35,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.flow @@ -84,14 +83,14 @@ class Widget : AppWidgetProvider() { return combine( getPrivacyStateUseCase.quickPrivacyState, - getPrivacyStateUseCase.isTrackersDenied, + getPrivacyStateUseCase.trackerMode, getPrivacyStateUseCase.isLocationHidden, getPrivacyStateUseCase.isIpHidden, - ) { quickPrivacyState, isTrackersDenied, isLocationHidden, isIpHidden -> + ) { quickPrivacyState, trackerMode, isLocationHidden, isIpHidden -> State( quickPrivacyState = quickPrivacyState, - isTrackersDenied = isTrackersDenied, + trackerMode = trackerMode, isLocationHidden = isLocationHidden, isIpHidden = isIpHidden ) diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt index fc865c6..27589a8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt @@ -31,12 +31,13 @@ import foundation.e.privacycentralapp.Widget import foundation.e.privacycentralapp.Widget.Companion.isDarkText import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.common.extensions.dpToPxF +import foundation.e.privacycentralapp.domain.entities.TrackerMode import foundation.e.privacycentralapp.main.MainActivity import foundation.e.privacycentralapp.widget.WidgetCommandReceiver.Companion.ACTION_TOGGLE_PRIVACY data class State( val quickPrivacyState: QuickPrivacyState = QuickPrivacyState.DISABLED, - val isTrackersDenied: Boolean = false, + val trackerMode: TrackerMode = TrackerMode.VULNERABLE, val isLocationHidden: Boolean = false, val isIpHidden: Boolean? = false, val dayStatistics: List<Pair<Int, Int>> = emptyList(), @@ -92,8 +93,11 @@ fun render( setTextViewText( R.id.state_trackers, context.getString( - if (state.isTrackersDenied) R.string.widget_state_trackers_on - else R.string.widget_state_trackers_off + when(state.trackerMode) { + TrackerMode.DENIED -> R.string.widget_state_trackers_on + TrackerMode.VULNERABLE -> R.string.widget_state_trackers_off + TrackerMode.CUSTOM -> R.string.widget_state_trackers_custom + } ) ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc075d3..8bcd998 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,6 +18,7 @@ <string name="dashboard_state_trackers_label">Trackers:</string> <string name="dashboard_state_trackers_off">Vulnerable</string> <string name="dashboard_state_trackers_on">Denied</string> + <string name="dashboard_state_trackers_custom">Custom</string> <string name="dashboard_state_geolocation_label">Location:</string> <string name="dashboard_state_geolocation_off">Exposed</string> <string name="dashboard_state_geolocation_on">Fake</string> @@ -122,6 +123,7 @@ <string name="widget_state_trackers_label" translatable="false">@string/dashboard_state_trackers_label</string> <string name="widget_state_trackers_off" translatable="false">@string/dashboard_state_trackers_off</string> <string name="widget_state_trackers_on" translatable="false">@string/dashboard_state_trackers_on</string> + <string name="widget_state_trackers_custom" translatable="false">@string/dashboard_state_trackers_custom</string> <string name="widget_state_geolocation_label" translatable="false">@string/dashboard_state_geolocation_label</string> <string name="widget_state_geolocation_off" translatable="false">@string/dashboard_state_geolocation_off</string> <string name="widget_state_geolocation_on" translatable="false">@string/dashboard_state_geolocation_on</string> |