diff --git a/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt b/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt index a67268f0e6..d732e27a82 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/store/AnalyticsStore.kt @@ -50,6 +50,7 @@ class AnalyticsStore @Inject constructor( val didAskUserConsentFlow: Flow = context.dataStore.data .map { preferences -> preferences[didAskUserConsent].orFalse() } + .distinctUntilChanged() val analyticsIdFlow: Flow = context.dataStore.data .map { preferences -> preferences[analyticsId].orEmpty() } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index b50a3a98a9..e049d15bac 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -246,6 +246,7 @@ class HomeActivity : is HomeActivityViewEvents.OnNewSession -> handleOnNewSession(it) HomeActivityViewEvents.PromptToEnableSessionPush -> handlePromptToEnablePush() is HomeActivityViewEvents.OnCrossSignedInvalidated -> handleCrossSigningInvalidated(it) + HomeActivityViewEvents.ShowAnalyticsOptIn -> handleShowAnalyticsOptIn() }.exhaustive } homeActivityViewModel.onEach { renderState(it) } @@ -272,6 +273,10 @@ class HomeActivity : } } + private fun handleShowAnalyticsOptIn() { + navigator.openAnalyticsOptIn(this) + } + private fun handleIntent(intent: Intent?) { intent?.dataString?.let { deepLink -> val resolvedLink = when { diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewEvents.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewEvents.kt index 7753a7f58b..adc44a57bd 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewEvents.kt @@ -19,9 +19,10 @@ package im.vector.app.features.home import im.vector.app.core.platform.VectorViewEvents import org.matrix.android.sdk.api.util.MatrixItem -sealed class HomeActivityViewEvents : VectorViewEvents { - data class AskPasswordToInitCrossSigning(val userItem: MatrixItem.UserItem?) : HomeActivityViewEvents() - data class OnNewSession(val userItem: MatrixItem.UserItem?, val waitForIncomingRequest: Boolean = true) : HomeActivityViewEvents() - data class OnCrossSignedInvalidated(val userItem: MatrixItem.UserItem) : HomeActivityViewEvents() - object PromptToEnableSessionPush : HomeActivityViewEvents() +sealed interface HomeActivityViewEvents : VectorViewEvents { + data class AskPasswordToInitCrossSigning(val userItem: MatrixItem.UserItem?) : HomeActivityViewEvents + data class OnNewSession(val userItem: MatrixItem.UserItem?, val waitForIncomingRequest: Boolean = true) : HomeActivityViewEvents + data class OnCrossSignedInvalidated(val userItem: MatrixItem.UserItem) : HomeActivityViewEvents + object PromptToEnableSessionPush : HomeActivityViewEvents + object ShowAnalyticsOptIn : HomeActivityViewEvents } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index 59b9cafd6e..c975d53f33 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -21,11 +21,13 @@ import com.airbnb.mvrx.MavericksViewModelFactory import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import im.vector.app.config.analyticsConfig import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.extensions.exhaustive import im.vector.app.core.platform.VectorViewModel +import im.vector.app.features.analytics.store.AnalyticsStore import im.vector.app.features.login.ReAuthHelper import im.vector.app.features.session.coroutineScope import im.vector.app.features.settings.VectorPreferences @@ -59,6 +61,7 @@ class HomeActivityViewModel @AssistedInject constructor( @Assisted initialState: HomeActivityViewState, private val activeSessionHolder: ActiveSessionHolder, private val reAuthHelper: ReAuthHelper, + private val analyticsStore: AnalyticsStore, private val vectorPreferences: VectorPreferences ) : VectorViewModel(initialState) { @@ -77,6 +80,19 @@ class HomeActivityViewModel @AssistedInject constructor( observeInitialSync() checkSessionPushIsOn() observeCrossSigningReset() + observeAnalytics() + } + + private fun observeAnalytics() { + if (analyticsConfig.isEnabled) { + analyticsStore.didAskUserConsentFlow + .onEach { didAskUser -> + if (!didAskUser) { + _viewEvents.post(HomeActivityViewEvents.ShowAnalyticsOptIn) + } + } + .launchIn(viewModelScope) + } } private fun cleanupFiles() {