mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
Analytics: display opt-in from Home
This commit is contained in:
parent
c1438f0a65
commit
cf267ae234
4 changed files with 28 additions and 5 deletions
|
@ -50,6 +50,7 @@ class AnalyticsStore @Inject constructor(
|
|||
|
||||
val didAskUserConsentFlow: Flow<Boolean> = context.dataStore.data
|
||||
.map { preferences -> preferences[didAskUserConsent].orFalse() }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val analyticsIdFlow: Flow<String> = context.dataStore.data
|
||||
.map { preferences -> preferences[analyticsId].orEmpty() }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<HomeActivityViewState, HomeActivityViewActions, HomeActivityViewEvents>(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() {
|
||||
|
|
Loading…
Reference in a new issue