summaryrefslogtreecommitdiff
path: root/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt')
-rw-r--r--app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt54
1 files changed, 30 insertions, 24 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt
index c7d4a27..2afd6ee 100644
--- a/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt
+++ b/app/src/main/java/foundation/e/advancedprivacy/data/repositories/LocalStateRepository.kt
@@ -19,18 +19,18 @@
package foundation.e.advancedprivacy.data.repositories
import android.content.Context
-import android.content.Intent
import foundation.e.advancedprivacy.domain.entities.ApplicationDescription
-import foundation.e.advancedprivacy.domain.entities.FeatureServiceState
+import foundation.e.advancedprivacy.domain.entities.FeatureState
import foundation.e.advancedprivacy.domain.entities.LocationMode
-import foundation.e.advancedprivacy.domain.entities.ShowFeaturesWarning
+import foundation.e.advancedprivacy.domain.entities.MainFeatures
+import foundation.e.advancedprivacy.domain.repositories.LocalStateRepository
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
-class LocalStateRepository(context: Context) {
+class LocalStateRepositoryImpl(context: Context) : LocalStateRepository {
companion object {
private const val SHARED_PREFS_FILE = "localState"
private const val KEY_BLOCK_TRACKERS = "blockTrackers"
@@ -47,25 +47,26 @@ class LocalStateRepository(context: Context) {
private val sharedPref = context.getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE)
private val _blockTrackers = MutableStateFlow(sharedPref.getBoolean(KEY_BLOCK_TRACKERS, true))
- val blockTrackers = _blockTrackers.asStateFlow()
- fun setBlockTrackers(enabled: Boolean) {
+ override val blockTrackers = _blockTrackers.asStateFlow()
+
+ override fun setBlockTrackers(enabled: Boolean) {
set(KEY_BLOCK_TRACKERS, enabled)
_blockTrackers.update { enabled }
}
- val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)
+ override val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)
private val _fakeLocationEnabled = MutableStateFlow(sharedPref.getBoolean(KEY_FAKE_LOCATION, false))
- val fakeLocationEnabled = _fakeLocationEnabled.asStateFlow()
+ override val fakeLocationEnabled = _fakeLocationEnabled.asStateFlow()
- fun setFakeLocationEnabled(enabled: Boolean) {
+ override fun setFakeLocationEnabled(enabled: Boolean) {
set(KEY_FAKE_LOCATION, enabled)
_fakeLocationEnabled.update { enabled }
}
- var fakeLocation: Pair<Float, Float>
+ override var fakeLocation: Pair<Float, Float>
get() = Pair(
// Initial default value is Quezon City
sharedPref.getFloat(KEY_FAKE_LATITUDE, 14.6760f),
@@ -79,43 +80,48 @@ class LocalStateRepository(context: Context) {
.apply()
}
- val locationMode: MutableStateFlow<LocationMode> = MutableStateFlow(LocationMode.REAL_LOCATION)
+ override val locationMode: MutableStateFlow<LocationMode> = MutableStateFlow(LocationMode.REAL_LOCATION)
private val _ipScramblingSetting = MutableStateFlow(sharedPref.getBoolean(KEY_IP_SCRAMBLING, false))
- val ipScramblingSetting = _ipScramblingSetting.asStateFlow()
- fun setIpScramblingSetting(enabled: Boolean) {
+ override val ipScramblingSetting = _ipScramblingSetting.asStateFlow()
+
+ override fun setIpScramblingSetting(enabled: Boolean) {
set(KEY_IP_SCRAMBLING, enabled)
_ipScramblingSetting.update { enabled }
}
- val internetPrivacyMode: MutableStateFlow<FeatureServiceState> = MutableStateFlow(FeatureServiceState.OFF)
+ override val internetPrivacyMode: MutableStateFlow<FeatureState> = MutableStateFlow(FeatureState.OFF)
+
+ private val _startVpnDisclaimer = MutableSharedFlow<MainFeatures>()
- private val _startVpnDisclaimer = MutableSharedFlow<ShowFeaturesWarning.IpScrambling>()
- suspend fun emitStartVpnDisclaimer(intent: Intent?) {
- _startVpnDisclaimer.emit(ShowFeaturesWarning.IpScrambling(startVpnDisclaimer = intent))
+ override suspend fun emitStartVpnDisclaimer(feature: MainFeatures) {
+ _startVpnDisclaimer.emit(feature)
}
- val startVpnDisclaimer: SharedFlow<ShowFeaturesWarning.IpScrambling> = _startVpnDisclaimer
+
+ override val startVpnDisclaimer: SharedFlow<MainFeatures> = _startVpnDisclaimer
private val _otherVpnRunning = MutableSharedFlow<ApplicationDescription>()
- suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) {
+
+ override suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) {
_otherVpnRunning.emit(appDesc)
}
- val otherVpnRunning: SharedFlow<ApplicationDescription> = _otherVpnRunning
- var firstBoot: Boolean
+ override val otherVpnRunning: SharedFlow<ApplicationDescription> = _otherVpnRunning
+
+ override var firstBoot: Boolean
get() = sharedPref.getBoolean(KEY_FIRST_BOOT, true)
set(value) = set(KEY_FIRST_BOOT, value)
- var hideWarningTrackers: Boolean
+ override var hideWarningTrackers: Boolean
get() = sharedPref.getBoolean(KEY_HIDE_WARNING_TRACKERS, false)
set(value) = set(KEY_HIDE_WARNING_TRACKERS, value)
- var hideWarningLocation: Boolean
+ override var hideWarningLocation: Boolean
get() = sharedPref.getBoolean(KEY_HIDE_WARNING_LOCATION, false)
set(value) = set(KEY_HIDE_WARNING_LOCATION, value)
- var hideWarningIpScrambling: Boolean
+ override var hideWarningIpScrambling: Boolean
get() = sharedPref.getBoolean(KEY_HIDE_WARNING_IPSCRAMBLING, false)
set(value) = set(KEY_HIDE_WARNING_IPSCRAMBLING, value)