aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/foundation/e/privacycentralapp/domain
diff options
context:
space:
mode:
authorAlexandre Roux <alexandre.roux.danzi@lostpod.me>2022-04-25 15:16:25 +0000
committerAlexandre Roux <alexandre.roux.danzi@lostpod.me>2022-04-25 15:16:25 +0000
commitf3c01e7bbf130c7f304b6bf50510c3800b8586f6 (patch)
treed9bee5a2fbcbe43bc0bbc121b4fd7dcc259ef8a3 /app/src/main/java/foundation/e/privacycentralapp/domain
parent27dbc4ea2c3357481f93c765008a3d66a1d51a22 (diff)
parent3ca4c651aff84c551101337984bf1d457d892a1a (diff)
downloadadvanced-privacy-f3c01e7bbf130c7f304b6bf50510c3800b8586f6.tar.gz
Merge branch '5311_main_toggle_wording' into 'main'
5311 main toggle wording, 5321 default settings See merge request e/privacy-central/privacycentralapp!43
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/domain')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/entities/QuickPrivacyState.kt24
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt13
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt55
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt8
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt12
5 files changed, 89 insertions, 23 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/QuickPrivacyState.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/QuickPrivacyState.kt
new file mode 100644
index 0000000..3257402
--- /dev/null
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/QuickPrivacyState.kt
@@ -0,0 +1,24 @@
+/*
+ * 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
+}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt
index 32affe0..c07657a 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt
@@ -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
}
}
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 db6f312..fd9430c 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
@@ -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)
}
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt
index 6cc8e4a..a701eec 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt
@@ -71,6 +71,10 @@ class IpScramblingStateUseCase(
applySettings(it, localStateRepository.isIpScramblingEnabled)
}
}
+
+ coroutineScope.launch {
+ internetPrivacyMode.collect { localStateRepository.internetPrivacyMode.value = it }
+ }
}
fun toggle(hideIp: Boolean) {
@@ -119,7 +123,7 @@ class IpScramblingStateUseCase(
private fun applySettings(isQuickPrivacyEnabled: Boolean, isIpScramblingEnabled: Boolean) {
when {
- isQuickPrivacyEnabled && isIpScramblingEnabled -> when (internetPrivacyMode.value) {
+ isQuickPrivacyEnabled && isIpScramblingEnabled -> when (localStateRepository.internetPrivacyMode.value) {
InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING -> {
val intent = ipScramblerModule.prepareAndroidVpn()
if (intent != null) {
@@ -129,7 +133,7 @@ class IpScramblingStateUseCase(
}
else -> {}
}
- else -> when (internetPrivacyMode.value) {
+ else -> when (localStateRepository.internetPrivacyMode.value) {
InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING -> ipScramblerModule.stop()
else -> {}
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt
index a589509..5263559 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt
@@ -26,9 +26,6 @@ import foundation.e.privacymodules.trackers.IBlockTrackersPrivacyModule
import foundation.e.privacymodules.trackers.ITrackTrackersPrivacyModule
import foundation.e.privacymodules.trackers.Tracker
import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@@ -41,13 +38,6 @@ class TrackersStateUseCase(
private val appListsRepository: AppListsRepository,
private val coroutineScope: CoroutineScope
) {
-
- private val _areAllTrackersBlocked = MutableStateFlow(
- blockTrackersPrivacyModule.isBlockingEnabled() &&
- blockTrackersPrivacyModule.isWhiteListEmpty()
- )
- val areAllTrackersBlocked: StateFlow<Boolean> = _areAllTrackersBlocked
-
init {
trackersPrivacyModule.start(trackersRepository.trackers, enableNotification = false)
coroutineScope.launch {
@@ -63,7 +53,7 @@ class TrackersStateUseCase(
}
private fun updateAllTrackersBlockedState() {
- _areAllTrackersBlocked.value = blockTrackersPrivacyModule.isBlockingEnabled() &&
+ localStateRepository.areAllTrackersBlocked.value = blockTrackersPrivacyModule.isBlockingEnabled() &&
blockTrackersPrivacyModule.isWhiteListEmpty()
}