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

Commit 3ca4c651 authored by Guillaume Jacquart's avatar Guillaume Jacquart Committed by Alexandre Roux
Browse files

5311 main toggle wording, 5321 default settings

parent d639470b
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ class DependencyContainer(val app: Application) {

    // ViewModelFactories
    val dashBoardViewModelFactory by lazy {
        DashBoardViewModelFactory(getQuickPrivacyStateUseCase, ipScramblingStateUseCase, trackersStatisticsUseCase, trackersStateUseCase, fakeLocationStateUseCase)
        DashBoardViewModelFactory(getQuickPrivacyStateUseCase, trackersStatisticsUseCase)
    }

    val fakeLocationViewModelFactory by lazy {
@@ -138,10 +138,7 @@ class DependencyContainer(val app: Application) {
        Widget.startListening(
            context,
            getQuickPrivacyStateUseCase,
            ipScramblingStateUseCase,
            trackersStatisticsUseCase,
            trackersStateUseCase,
            fakeLocationStateUseCase
        )
    }
}
+25 −13
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
package foundation.e.privacycentralapp.data.repositories

import android.content.Context
import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
import foundation.e.privacycentralapp.domain.entities.LocationMode
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow

@@ -26,6 +28,7 @@ class LocalStateRepository(context: Context) {
        private const val SHARED_PREFS_FILE = "localState"
        private const val KEY_QUICK_PRIVACY = "quickPrivacy"
        private const val KEY_IP_SCRAMBLING = "ipScrambling"
        private const val KEY_FAKE_LOCATION = "fakeLocation"
        private const val KEY_FAKE_LATITUDE = "fakeLatitude"
        private const val KEY_FAKE_LONGITUDE = "fakeLongitude"
        private const val KEY_FIRST_BOOT = "firstBoot"
@@ -35,43 +38,52 @@ class LocalStateRepository(context: Context) {

    private val quickPrivacyEnabledMutableFlow =
        MutableStateFlow<Boolean>(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false))
    var isQuickPrivacyEnabled: Boolean
        get() = quickPrivacyEnabledMutableFlow.value
        set(value) {
    val isQuickPrivacyEnabled: Boolean get() = quickPrivacyEnabledMutableFlow.value

    fun setQuickPrivacyReturnIsFirstActivation(value: Boolean): Boolean {
        val isFirstActivation = value && !sharedPref.contains(KEY_QUICK_PRIVACY)
        set(KEY_QUICK_PRIVACY, value)
        quickPrivacyEnabledMutableFlow.value = value
        return isFirstActivation
    }

    var quickPrivacyEnabledFlow: Flow<Boolean> = quickPrivacyEnabledMutableFlow

    val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)

    var fakeLocation: Pair<Float, Float>?
        get() = if (sharedPref.contains(KEY_FAKE_LATITUDE) && sharedPref.contains(
                KEY_FAKE_LONGITUDE
            )
        )
        get() = if (sharedPref.getBoolean(KEY_FAKE_LOCATION, true))
            Pair(
                sharedPref.getFloat(KEY_FAKE_LATITUDE, 0f),
                sharedPref.getFloat(KEY_FAKE_LONGITUDE, 0f)
                // Initial default value is Quezon City
                sharedPref.getFloat(KEY_FAKE_LATITUDE, 14.6760f),
                sharedPref.getFloat(KEY_FAKE_LONGITUDE, 121.0437f)
            )
        else null

        set(value) {
            if (value == null) {
                sharedPref.edit()
                    .putBoolean(KEY_FAKE_LOCATION, false)
                    .remove(KEY_FAKE_LATITUDE)
                    .remove(KEY_FAKE_LONGITUDE)
                    .commit()
            } else {
                sharedPref.edit()
                    .putBoolean(KEY_FAKE_LOCATION, true)
                    .putFloat(KEY_FAKE_LATITUDE, value.first)
                    .putFloat(KEY_FAKE_LONGITUDE, value.second)
                    .commit()
            }
        }

    val locationMode: MutableStateFlow<LocationMode> = MutableStateFlow(LocationMode.REAL_LOCATION)

    var isIpScramblingEnabled: Boolean
        get() = sharedPref.getBoolean(KEY_IP_SCRAMBLING, false)
        get() = sharedPref.getBoolean(KEY_IP_SCRAMBLING, true)
        set(value) = set(KEY_IP_SCRAMBLING, value)

    val internetPrivacyMode: MutableStateFlow<InternetPrivacyMode> = MutableStateFlow(InternetPrivacyMode.REAL_IP)

    var firstBoot: Boolean
        get() = sharedPref.getBoolean(KEY_FIRST_BOOT, true)
        set(value) = set(KEY_FIRST_BOOT, value)
+24 −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 QuickPrivacyState {
    DISABLED, ENABLED, FULL_ENABLED;

    fun isEnabled(): Boolean = this != DISABLED
}
+6 −7
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import foundation.e.privacymodules.permissions.data.AppOpModes
import foundation.e.privacymodules.permissions.data.ApplicationDescription
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlin.random.Random
@@ -47,8 +46,8 @@ class FakeLocationStateUseCase(
    private val appContext: Context,
    private val coroutineScope: CoroutineScope
) {
    private val _locationMode = MutableStateFlow(LocationMode.REAL_LOCATION)
    val locationMode: StateFlow<LocationMode> = _locationMode
    // private val _locationMode = MutableStateFlow(LocationMode.REAL_LOCATION)
    // val locationMode: StateFlow<LocationMode> = _locationMode

    init {
        coroutineScope.launch {
@@ -63,14 +62,14 @@ class FakeLocationStateUseCase(

    fun getLocationMode(): Triple<LocationMode, Float?, Float?> {
        val fakeLocation = localStateRepository.fakeLocation
        return if (fakeLocation != null && _locationMode.value == LocationMode.SPECIFIC_LOCATION) {
        return if (fakeLocation != null && localStateRepository.locationMode.value == LocationMode.SPECIFIC_LOCATION) {
            Triple(
                LocationMode.SPECIFIC_LOCATION,
                fakeLocation.first,
                fakeLocation.second
            )
        } else {
            Triple(_locationMode.value, null, null)
            Triple(localStateRepository.locationMode.value, null, null)
        }
    }

@@ -97,11 +96,11 @@ class FakeLocationStateUseCase(
            }
            fakeLocationModule.startFakeLocation()
            fakeLocationModule.setFakeLocation(fakeLocation.first.toDouble(), fakeLocation.second.toDouble())
            _locationMode.value = if (fakeLocation in citiesRepository.citiesLocationsList) LocationMode.RANDOM_LOCATION
            localStateRepository.locationMode.value = if (fakeLocation in citiesRepository.citiesLocationsList) LocationMode.RANDOM_LOCATION
            else LocationMode.SPECIFIC_LOCATION
        } else {
            fakeLocationModule.stopFakeLocation()
            _locationMode.value = LocationMode.REAL_LOCATION
            localStateRepository.locationMode.value = LocationMode.REAL_LOCATION
        }
    }

+52 −3
Original line number Diff line number Diff line
@@ -18,14 +18,63 @@
package foundation.e.privacycentralapp.domain.usecases

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 kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine

class GetQuickPrivacyStateUseCase(private val localStateRepository: LocalStateRepository) {
    val quickPrivacyEnabledFlow = localStateRepository.quickPrivacyEnabledFlow
    val isQuickPrivacyEnabled get() = localStateRepository.isQuickPrivacyEnabled

    fun toggle(): Boolean {
    val quickPrivacyState = combine(
        localStateRepository.quickPrivacyEnabledFlow,
        localStateRepository.areAllTrackersBlocked,
        localStateRepository.locationMode,
        localStateRepository.internetPrivacyMode
    ) { isQuickPrivacyEnabled, isAllTrackersBlocked, locationMode, internetPrivacyMode ->
        when {
            !isQuickPrivacyEnabled -> QuickPrivacyState.DISABLED
            isAllTrackersBlocked &&
                locationMode != LocationMode.REAL_LOCATION &&
                internetPrivacyMode in listOf(
                InternetPrivacyMode.HIDE_IP,
                InternetPrivacyMode.HIDE_IP_LOADING
            ) -> QuickPrivacyState.FULL_ENABLED
            else -> QuickPrivacyState.ENABLED
        }
    }

    val isTrackersDenied = combine(
        localStateRepository.quickPrivacyEnabledFlow,
        localStateRepository.areAllTrackersBlocked
    ) { isQuickPrivacyEnabled, isAllTrackersBlocked ->
        isQuickPrivacyEnabled && isAllTrackersBlocked
    }

    val isLocationHidden = combine(
        localStateRepository.quickPrivacyEnabledFlow,
        localStateRepository.locationMode
    ) { isQuickPrivacyEnabled, locationMode ->
        isQuickPrivacyEnabled && locationMode != LocationMode.REAL_LOCATION
    }

    val locationMode: StateFlow<LocationMode> = localStateRepository.locationMode

    val isIpHidden = combine(
        localStateRepository.quickPrivacyEnabledFlow,
        localStateRepository.internetPrivacyMode
    ) { isQuickPrivacyEnabled, internetPrivacyMode ->
        when {
            !isQuickPrivacyEnabled || internetPrivacyMode == InternetPrivacyMode.REAL_IP -> false
            internetPrivacyMode == InternetPrivacyMode.HIDE_IP -> true
            else -> null
        }
    }

    fun toggleReturnIsFirstActivation(): Boolean {
        val newState = !localStateRepository.isQuickPrivacyEnabled
        localStateRepository.isQuickPrivacyEnabled = newState
        return newState
        return localStateRepository.setQuickPrivacyReturnIsFirstActivation(newState)
    }
}
Loading