mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 04:08:44 +03:00
Analytics: Display the opt in screen from the setting, and cleanup the code
This commit is contained in:
parent
219bb89c3a
commit
d63f9073b7
2 changed files with 11 additions and 12 deletions
|
@ -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…
Add table
Reference in a new issue