diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-11-18 07:21:49 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-11-18 07:21:49 +0000 |
commit | 2ee502ad3dbfd42c09a88212f5bd179fc531e2e6 (patch) | |
tree | 1b81bc5228aa8c722ca8df289cd9f93c2104522f /app/src/main/java/foundation/e/privacycentralapp/data | |
parent | 82e1bee1454fe5f8bc6653344da76b35f1d3d8a3 (diff) | |
download | advanced-privacy-2ee502ad3dbfd42c09a88212f5bd179fc531e2e6.tar.gz |
568: individuals buttons to activate trackers control, fake location and Hide my ip
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/data')
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt | 78 |
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() } } |