aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/foundation/e/privacycentralapp/features
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/features')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt55
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt43
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt14
3 files changed, 56 insertions, 56 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt
index ca45393..95726db 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFeature.kt
@@ -22,14 +22,13 @@ import foundation.e.flowmvi.Actor
import foundation.e.flowmvi.Reducer
import foundation.e.flowmvi.SingleEventProducer
import foundation.e.flowmvi.feature.BaseFeature
-import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
+import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.domain.entities.LocationMode
-import foundation.e.privacycentralapp.domain.usecases.FakeLocationStateUseCase
+import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState
import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase
-import foundation.e.privacycentralapp.domain.usecases.IpScramblingStateUseCase
-import foundation.e.privacycentralapp.domain.usecases.TrackersStateUseCase
import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase
import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
@@ -49,10 +48,11 @@ class DashboardFeature(
singleEventProducer
) {
data class State(
- val isQuickPrivacyEnabled: Boolean = false,
- val isAllTrackersBlocked: Boolean = false,
+ val quickPrivacyState: QuickPrivacyState = QuickPrivacyState.DISABLED,
+ val isTrackersDenied: Boolean = false,
+ val isLocationHidden: Boolean = false,
+ val isIpHidden: Boolean? = false,
val locationMode: LocationMode = LocationMode.REAL_LOCATION,
- val internetPrivacyMode: InternetPrivacyMode = InternetPrivacyMode.REAL_IP,
val leakedTrackersCount: Int? = null,
val trackersCount: Int? = null,
val activeTrackersCount: Int? = null,
@@ -66,6 +66,7 @@ class DashboardFeature(
object NavigateToLocationSingleEvent : SingleEvent()
object NavigateToPermissionsSingleEvent : SingleEvent()
object NewStatisticsAvailableSingleEvent : SingleEvent()
+ data class ToastMessageSingleEvent(val message: Int) : SingleEvent()
}
sealed class Action {
@@ -80,8 +81,8 @@ class DashboardFeature(
sealed class Effect {
object NoEffect : Effect()
- data class UpdateStateEffect(val isEnabled: Boolean) : Effect()
- data class IpScramblingModeUpdatedEffect(val mode: InternetPrivacyMode) : Effect()
+ data class UpdateStateEffect(val state: QuickPrivacyState) : Effect()
+ data class IpScramblingModeUpdatedEffect(val isIpHidden: Boolean?) : Effect()
data class TrackersStatisticsUpdatedEffect(
val dayStatistics: List<Pair<Int, Int>>,
val dayLabels: List<String>,
@@ -96,24 +97,23 @@ class DashboardFeature(
object OpenAppsPermissionsEffect : Effect()
object OpenTrackersEffect : Effect()
object NewStatisticsAvailablesEffect : Effect()
+ object FirstIPTrackerActivationEffect : Effect()
+ data class LocationHiddenUpdatedEffect(val isLocationHidden: Boolean) : Effect()
}
companion object {
fun create(
coroutineScope: CoroutineScope,
getPrivacyStateUseCase: GetQuickPrivacyStateUseCase,
- ipScramblingStateUseCase: IpScramblingStateUseCase,
trackersStatisticsUseCase: TrackersStatisticsUseCase,
- trackersStateUseCase: TrackersStateUseCase,
- fakeLocationStateUseCase: FakeLocationStateUseCase
): DashboardFeature =
DashboardFeature(
initialState = State(),
coroutineScope,
reducer = { state, effect ->
when (effect) {
- is Effect.UpdateStateEffect -> state.copy(isQuickPrivacyEnabled = effect.isEnabled)
- is Effect.IpScramblingModeUpdatedEffect -> state.copy(internetPrivacyMode = effect.mode)
+ is Effect.UpdateStateEffect -> state.copy(quickPrivacyState = effect.state)
+ is Effect.IpScramblingModeUpdatedEffect -> state.copy(isIpHidden = effect.isIpHidden)
is Effect.TrackersStatisticsUpdatedEffect -> state.copy(
dayStatistics = effect.dayStatistics,
dayLabels = effect.dayLabels,
@@ -123,7 +123,10 @@ class DashboardFeature(
)
is Effect.TrackersBlockedUpdatedEffect -> state.copy(
- isAllTrackersBlocked = effect.areAllTrackersBlocked
+ isTrackersDenied = effect.areAllTrackersBlocked
+ )
+ is Effect.LocationHiddenUpdatedEffect -> state.copy(
+ isLocationHidden = effect.isLocationHidden
)
is Effect.UpdateLocationModeEffect -> state.copy(locationMode = effect.mode)
@@ -133,24 +136,30 @@ class DashboardFeature(
actor = { _: State, action: Action ->
when (action) {
Action.TogglePrivacyAction -> {
- getPrivacyStateUseCase.toggle()
- flowOf(Effect.NewStatisticsAvailablesEffect)
+ val isFirstActivation = getPrivacyStateUseCase.toggleReturnIsFirstActivation()
+ flow {
+ emit(Effect.NewStatisticsAvailablesEffect)
+ if (isFirstActivation) emit(Effect.FirstIPTrackerActivationEffect)
+ }
}
Action.InitAction -> merge(
- getPrivacyStateUseCase.quickPrivacyEnabledFlow.map {
+ getPrivacyStateUseCase.quickPrivacyState.map {
Effect.UpdateStateEffect(it)
},
- ipScramblingStateUseCase.internetPrivacyMode.map {
+ getPrivacyStateUseCase.isIpHidden.map {
Effect.IpScramblingModeUpdatedEffect(it)
},
trackersStatisticsUseCase.listenUpdates().map {
Effect.NewStatisticsAvailablesEffect
},
- trackersStateUseCase.areAllTrackersBlocked.map {
+ getPrivacyStateUseCase.isTrackersDenied.map {
Effect.TrackersBlockedUpdatedEffect(it)
},
- fakeLocationStateUseCase.locationMode.map {
+ getPrivacyStateUseCase.isLocationHidden.map {
+ Effect.LocationHiddenUpdatedEffect(it)
+ },
+ getPrivacyStateUseCase.locationMode.map {
Effect.UpdateLocationModeEffect(it)
}
)
@@ -188,6 +197,10 @@ class DashboardFeature(
SingleEvent.NavigateToTrackersSingleEvent
is Effect.NewStatisticsAvailablesEffect ->
SingleEvent.NewStatisticsAvailableSingleEvent
+ is Effect.FirstIPTrackerActivationEffect ->
+ SingleEvent.ToastMessageSingleEvent(
+ message = R.string.dashboard_first_ipscrambling_activation
+ )
else -> null
}
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
index 96ace56..588eedd 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
@@ -22,6 +22,7 @@ import android.os.Bundle
import android.text.Html
import android.text.Html.FROM_HTML_MODE_LEGACY
import android.view.View
+import android.widget.Toast
import androidx.core.content.ContextCompat.getColor
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
@@ -35,8 +36,8 @@ import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.common.GraphHolder
import foundation.e.privacycentralapp.common.NavToolbarFragment
import foundation.e.privacycentralapp.databinding.FragmentDashboardBinding
-import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
import foundation.e.privacycentralapp.domain.entities.LocationMode
+import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState
import foundation.e.privacycentralapp.extensions.viewModelProviderFactoryOf
import foundation.e.privacycentralapp.features.dashboard.DashboardFeature.State
import foundation.e.privacycentralapp.features.internetprivacy.InternetPrivacyFragment
@@ -104,6 +105,9 @@ class DashboardFragment :
DashboardFeature.SingleEvent.NewStatisticsAvailableSingleEvent -> {
viewModel.submitAction(DashboardFeature.Action.FetchStatistics)
}
+ is DashboardFeature.SingleEvent.ToastMessageSingleEvent ->
+ Toast.makeText(requireContext(), event.message, Toast.LENGTH_LONG)
+ .show()
}
}
}
@@ -159,50 +163,48 @@ class DashboardFragment :
override fun render(state: State) {
binding.stateLabel.text = getString(
- if (state.isQuickPrivacyEnabled) R.string.dashboard_state_title_on
- else R.string.dashboard_state_title_off
+ when (state.quickPrivacyState) {
+ QuickPrivacyState.DISABLED -> R.string.dashboard_state_title_off
+ QuickPrivacyState.FULL_ENABLED -> R.string.dashboard_state_title_on
+ QuickPrivacyState.ENABLED -> R.string.dashboard_state_title_custom
+ }
)
binding.stateIcon.setImageResource(
- if (state.isQuickPrivacyEnabled) R.drawable.ic_shield_on
+ if (state.quickPrivacyState.isEnabled()) R.drawable.ic_shield_on
else R.drawable.ic_shield_off
)
- binding.togglePrivacyCentral.isChecked = state.isQuickPrivacyEnabled
+ binding.togglePrivacyCentral.isChecked = state.quickPrivacyState.isEnabled()
- val trackersEnabled = state.isQuickPrivacyEnabled && state.isAllTrackersBlocked
binding.stateTrackers.text = getString(
- if (trackersEnabled) R.string.dashboard_state_trackers_on
+ if (state.isTrackersDenied) R.string.dashboard_state_trackers_on
else R.string.dashboard_state_trackers_off
)
binding.stateTrackers.setTextColor(
getColor(
requireContext(),
- if (trackersEnabled) R.color.green_valid
+ if (state.isTrackersDenied) R.color.green_valid
else R.color.red_off
)
)
- val geolocEnabled = state.isQuickPrivacyEnabled && state.locationMode != LocationMode.REAL_LOCATION
binding.stateGeolocation.text = getString(
- if (geolocEnabled) R.string.dashboard_state_geolocation_on
+ if (state.isLocationHidden) R.string.dashboard_state_geolocation_on
else R.string.dashboard_state_geolocation_off
)
binding.stateGeolocation.setTextColor(
getColor(
requireContext(),
- if (geolocEnabled) R.color.green_valid
+ if (state.isLocationHidden) R.color.green_valid
else R.color.red_off
)
)
- val ipAddressEnabled = state.isQuickPrivacyEnabled && state.internetPrivacyMode != InternetPrivacyMode.REAL_IP
- val isLoading = state.isQuickPrivacyEnabled && state.internetPrivacyMode in listOf(
- InternetPrivacyMode.HIDE_IP_LOADING,
- InternetPrivacyMode.REAL_IP_LOADING
- )
+ val isLoading = state.isIpHidden == null
+
binding.stateIpAddress.text = getString(
- if (ipAddressEnabled) R.string.dashboard_state_ipaddress_on
+ if (state.isIpHidden == true) R.string.dashboard_state_ipaddress_on
else R.string.dashboard_state_ipaddress_off
)
@@ -212,7 +214,7 @@ class DashboardFragment :
binding.stateIpAddress.setTextColor(
getColor(
requireContext(),
- if (ipAddressEnabled) R.color.green_valid
+ if (state.isIpHidden == true) R.color.green_valid
else R.color.red_off
)
)
@@ -252,10 +254,7 @@ class DashboardFragment :
)
binding.internetActivityPrivacy.subTitle = getString(
- if (state.isQuickPrivacyEnabled &&
- state.internetPrivacyMode != InternetPrivacyMode.REAL_IP
- )
- R.string.dashboard_internet_activity_privacy_subtitle_on
+ if (state.isIpHidden == true) R.string.dashboard_internet_activity_privacy_subtitle_on
else R.string.dashboard_internet_activity_privacy_subtitle_off
)
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt
index 0dbcdda..ffd7951 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt
@@ -20,10 +20,7 @@ package foundation.e.privacycentralapp.features.dashboard
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import foundation.e.privacycentralapp.common.Factory
-import foundation.e.privacycentralapp.domain.usecases.FakeLocationStateUseCase
import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase
-import foundation.e.privacycentralapp.domain.usecases.IpScramblingStateUseCase
-import foundation.e.privacycentralapp.domain.usecases.TrackersStateUseCase
import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
@@ -31,10 +28,7 @@ import kotlinx.coroutines.launch
class DashboardViewModel(
private val getPrivacyStateUseCase: GetQuickPrivacyStateUseCase,
- private val ipScramblingStateUseCase: IpScramblingStateUseCase,
private val trackersStatisticsUseCase: TrackersStatisticsUseCase,
- private val trackersStateUseCase: TrackersStateUseCase,
- private val fakeLocationStateUseCase: FakeLocationStateUseCase
) : ViewModel() {
private val _actions = MutableSharedFlow<DashboardFeature.Action>()
@@ -44,10 +38,7 @@ class DashboardViewModel(
DashboardFeature.create(
coroutineScope = viewModelScope,
getPrivacyStateUseCase = getPrivacyStateUseCase,
- ipScramblingStateUseCase = ipScramblingStateUseCase,
trackersStatisticsUseCase = trackersStatisticsUseCase,
- trackersStateUseCase = trackersStateUseCase,
- fakeLocationStateUseCase = fakeLocationStateUseCase
)
}
@@ -60,12 +51,9 @@ class DashboardViewModel(
class DashBoardViewModelFactory(
private val getPrivacyStateUseCase: GetQuickPrivacyStateUseCase,
- private val ipScramblingStateUseCase: IpScramblingStateUseCase,
private val trackersStatisticsUseCase: TrackersStatisticsUseCase,
- private val trackersStateUseCase: TrackersStateUseCase,
- private val fakeLocationStateUseCase: FakeLocationStateUseCase
) : Factory<DashboardViewModel> {
override fun create(): DashboardViewModel {
- return DashboardViewModel(getPrivacyStateUseCase, ipScramblingStateUseCase, trackersStatisticsUseCase, trackersStateUseCase, fakeLocationStateUseCase)
+ return DashboardViewModel(getPrivacyStateUseCase, trackersStatisticsUseCase)
}
}