Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 837e4ffa authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Merge branch '4208-CUSTOM_state_for_trackers' into 'main'

4208 Add CUSTOM state for tracker control.

See merge request !90
parents 6495fe4a 0a8527b4
Loading
Loading
Loading
Loading
Loading
+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
+7 −2
Original line number Diff line number Diff line
@@ -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(
+8 −6
Original line number Diff line number Diff line
@@ -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
            )
        )

+2 −1
Original line number Diff line number Diff line
@@ -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,
+2 −2
Original line number Diff line number Diff line
@@ -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