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(
|
data class AnalyticsConsentViewState(
|
||||||
val userConsent: Boolean = false,
|
val userConsent: Boolean = false,
|
||||||
val didAskUserConsent: Boolean = false
|
val didAskUserConsent: Boolean = false
|
||||||
) : MavericksState {
|
) : MavericksState
|
||||||
val shouldCheckTheBox: Boolean =
|
|
||||||
if (didAskUserConsent) {
|
|
||||||
userConsent
|
|
||||||
} else {
|
|
||||||
// default value
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -288,7 +288,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun observeAnalyticsState() {
|
private fun observeAnalyticsState() {
|
||||||
analyticsConsentViewModel.onEach(AnalyticsConsentViewState::shouldCheckTheBox) {
|
analyticsConsentViewModel.onEach(AnalyticsConsentViewState::userConsent) {
|
||||||
analyticsConsent.isChecked = it
|
analyticsConsent.isChecked = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,8 +296,15 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||||||
private fun setUpAnalytics() {
|
private fun setUpAnalytics() {
|
||||||
analyticsCategory.isVisible = analyticsConfig.isEnabled
|
analyticsCategory.isVisible = analyticsConfig.isEnabled
|
||||||
|
|
||||||
analyticsConsent.setOnPreferenceClickListener {
|
analyticsConsent.setOnPreferenceChangeListener { _, newValue ->
|
||||||
analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent(analyticsConsent.isChecked))
|
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
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user