mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Analytics: Display the opt in screen from the setting, and cleanup the code
This commit is contained in:
parent
219bb89c3a
commit
d63f9073b7
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user