aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/foundation/e/privacycentralapp/data
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/data')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt78
1 files changed, 33 insertions, 45 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
index d39ee43..92ee0c1 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt
@@ -24,14 +24,13 @@ import foundation.e.privacymodules.permissions.data.ApplicationDescription
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
-import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
class LocalStateRepository(context: Context) {
companion object {
private const val SHARED_PREFS_FILE = "localState"
- private const val KEY_QUICK_PRIVACY = "quickPrivacy"
+ private const val KEY_BLOCK_TRACKERS = "blockTrackers"
private const val KEY_IP_SCRAMBLING = "ipScrambling"
private const val KEY_FAKE_LOCATION = "fakeLocation"
private const val KEY_FAKE_LATITUDE = "fakeLatitude"
@@ -41,58 +40,48 @@ class LocalStateRepository(context: Context) {
private val sharedPref = context.getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE)
- private val quickPrivacyEnabledMutableFlow =
- MutableStateFlow<Boolean>(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false))
- val isQuickPrivacyEnabled: Boolean get() = quickPrivacyEnabledMutableFlow.value
+ private val _blockTrackers = MutableStateFlow(sharedPref.getBoolean(KEY_BLOCK_TRACKERS, true))
+ val blockTrackers = _blockTrackers.asStateFlow()
- fun setQuickPrivacyReturnIsFirstActivation(value: Boolean): Boolean {
- val isFirstActivation = value && !sharedPref.contains(KEY_QUICK_PRIVACY)
- set(KEY_QUICK_PRIVACY, value)
- quickPrivacyEnabledMutableFlow.value = value
- return isFirstActivation
+ fun setBlockTrackers(enabled: Boolean) {
+ set(KEY_BLOCK_TRACKERS, enabled)
+ _blockTrackers.update { enabled }
}
- private val _otherVpnRunning = MutableSharedFlow<ApplicationDescription>()
- suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) {
- _otherVpnRunning.emit(appDesc)
- }
+ val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)
- val otherVpnRunning: SharedFlow<ApplicationDescription> = _otherVpnRunning
+ private val _fakeLocationEnabled = MutableStateFlow(sharedPref.getBoolean(KEY_FAKE_LOCATION, true))
- var quickPrivacyEnabledFlow: StateFlow<Boolean> = quickPrivacyEnabledMutableFlow
+ val fakeLocationEnabled = _fakeLocationEnabled.asStateFlow()
- val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)
+ fun setFakeLocationEnabled(enabled: Boolean) {
+ set(KEY_FAKE_LOCATION, enabled)
+ _fakeLocationEnabled.update { enabled }
+ }
- var fakeLocation: Pair<Float, Float>?
- get() = if (sharedPref.getBoolean(KEY_FAKE_LOCATION, true))
- Pair(
- // Initial default value is Quezon City
- sharedPref.getFloat(KEY_FAKE_LATITUDE, 14.6760f),
- sharedPref.getFloat(KEY_FAKE_LONGITUDE, 121.0437f)
- )
- else null
+ var fakeLocation: Pair<Float, Float>
+ get() = Pair(
+ // Initial default value is Quezon City
+ sharedPref.getFloat(KEY_FAKE_LATITUDE, 14.6760f),
+ sharedPref.getFloat(KEY_FAKE_LONGITUDE, 121.0437f)
+ )
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()
- }
+ sharedPref.edit()
+ .putFloat(KEY_FAKE_LATITUDE, value.first)
+ .putFloat(KEY_FAKE_LONGITUDE, value.second)
+ .apply()
}
val locationMode: MutableStateFlow<LocationMode> = MutableStateFlow(LocationMode.REAL_LOCATION)
- private val _ipScramblingSetting = MutableStateFlow(sharedPref.getBoolean(KEY_IP_SCRAMBLING, true))
+ private val _ipScramblingSetting = MutableStateFlow(sharedPref.getBoolean(KEY_IP_SCRAMBLING, false))
val ipScramblingSetting = _ipScramblingSetting.asStateFlow()
+ fun isIpScramblingFirstActivation(enabled: Boolean): Boolean {
+ return enabled && !sharedPref.contains(KEY_IP_SCRAMBLING)
+ }
+
fun setIpScramblingSetting(enabled: Boolean) {
set(KEY_IP_SCRAMBLING, enabled)
_ipScramblingSetting.update { enabled }
@@ -100,18 +89,17 @@ class LocalStateRepository(context: Context) {
val internetPrivacyMode: MutableStateFlow<InternetPrivacyMode> = MutableStateFlow(InternetPrivacyMode.REAL_IP)
- private val _showQuickPrivacyDisabledMessage = MutableStateFlow(false)
- val showQuickPrivacyDisabledMessage: StateFlow<Boolean> = _showQuickPrivacyDisabledMessage
-
- fun setShowQuickPrivacyDisabledMessage(show: Boolean) {
- _showQuickPrivacyDisabledMessage.value = show
+ private val _otherVpnRunning = MutableSharedFlow<ApplicationDescription>()
+ suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) {
+ _otherVpnRunning.emit(appDesc)
}
+ val otherVpnRunning: SharedFlow<ApplicationDescription> = _otherVpnRunning
var firstBoot: Boolean
get() = sharedPref.getBoolean(KEY_FIRST_BOOT, true)
set(value) = set(KEY_FIRST_BOOT, value)
private fun set(key: String, value: Boolean) {
- sharedPref.edit().putBoolean(key, value).commit()
+ sharedPref.edit().putBoolean(key, value).apply()
}
}