Loading app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt 0 → 100644 +22 −0 Original line number Diff line number Diff line /* * 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 app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +7 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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( Loading app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +8 −6 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 ) ) Loading app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt +2 −1 Original line number Diff line number Diff line Loading @@ -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, Loading app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) } Loading Loading
app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt 0 → 100644 +22 −0 Original line number Diff line number Diff line /* * 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
app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +7 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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( Loading
app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +8 −6 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 ) ) Loading
app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt +2 −1 Original line number Diff line number Diff line Loading @@ -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, Loading
app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) } Loading