diff --git a/vector/src/main/java/im/vector/app/features/analytics/ui/consent/AnalyticsConsentViewState.kt b/vector/src/main/java/im/vector/app/features/analytics/ui/consent/AnalyticsConsentViewState.kt index f7496710e2..46a21a400a 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/ui/consent/AnalyticsConsentViewState.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/ui/consent/AnalyticsConsentViewState.kt @@ -21,12 +21,4 @@ import com.airbnb.mvrx.MavericksState data class AnalyticsConsentViewState( val userConsent: Boolean = false, val didAskUserConsent: Boolean = false -) : MavericksState { - val shouldCheckTheBox: Boolean = - if (didAskUserConsent) { - userConsent - } else { - // default value - true - } -} +) : MavericksState diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 2dd1e93c4a..c1c7feb7df 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -288,7 +288,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } private fun observeAnalyticsState() { - analyticsConsentViewModel.onEach(AnalyticsConsentViewState::shouldCheckTheBox) { + analyticsConsentViewModel.onEach(AnalyticsConsentViewState::userConsent) { analyticsConsent.isChecked = it } } @@ -296,8 +296,15 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( private fun setUpAnalytics() { analyticsCategory.isVisible = analyticsConfig.isEnabled - analyticsConsent.setOnPreferenceClickListener { - analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent(analyticsConsent.isChecked)) + analyticsConsent.setOnPreferenceChangeListener { _, newValue -> + val newValueBool = newValue as? Boolean ?: false + if (newValueBool) { + // User want to enable analytics, display the opt in screen + navigator.openAnalyticsOptIn(requireContext()) + } else { + // Just disable analytics + analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent(false)) + } true } }