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 0000000000000000000000000000000000000000..ae70ba37fd6b79ce002bb7263a67adc0064c0fc2 --- /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 . + */ + +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 7377568a131999dddcc025c29c2e20413612bbba..a9c608ebee447a64969a83ac7118b41f252f90ab 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 = combine( + val trackerMode: Flow = combine( localStateRepository.quickPrivacyEnabledFlow, localStateRepository.areAllTrackersBlocked ) { isQuickPrivacyEnabled, isAllTrackersBlocked -> - isQuickPrivacyEnabled && isAllTrackersBlocked + when { + isQuickPrivacyEnabled && isAllTrackersBlocked -> TrackerMode.DENIED + isQuickPrivacyEnabled && !isAllTrackersBlocked -> TrackerMode.CUSTOM + else -> TrackerMode.VULNERABLE + } } val isLocationHidden: Flow = 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 adb54bbd9bf82fe57ae96d1db71cbfbf3efd28b2..4d38ec8a193646d92b28077e7479a22cb796a0ec 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 65aa44460cce5a446a33ffd5172ac09d5a9411ef..fb00f07062676a04dad2a0a3a52f70d072fc897d 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 e3a97226ac289a27b5b06424c1e9558afec6773e..0ddceb152098a3bcc4e0227c8c9ad2f31da5099f 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 62e279f4980fc0e9ef9f1107025f127b5ec418df..e886cd88cf7400b2c807229a1a7299da223ca198 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 fc865c663043b084c237df50e948ce408e29273e..27589a8e766977e3a3069036a938cf3b7ffe2f11 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> = 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 dc075d3e3670135d772ac675e519e78185a99ef1..8bcd9982e03e650d58d4672bddd4aff2e1e69b9b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,6 +18,7 @@ Trackers: Vulnerable Denied + Custom Location: Exposed Fake @@ -122,6 +123,7 @@ @string/dashboard_state_trackers_label @string/dashboard_state_trackers_off @string/dashboard_state_trackers_on + @string/dashboard_state_trackers_custom @string/dashboard_state_geolocation_label @string/dashboard_state_geolocation_off @string/dashboard_state_geolocation_on