From eba5aa94cecdac2f49625e22ad3471eaf9006420 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 7 Dec 2021 13:07:58 +0100 Subject: [PATCH] Analytics: ViewEvent sent before the View is ready. --- .../main/java/im/vector/app/features/home/HomeActivity.kt | 1 + .../vector/app/features/home/HomeActivityViewActions.kt | 5 +++-- .../im/vector/app/features/home/HomeActivityViewModel.kt | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) 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 e049d15bac..c5a9ad8736 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 @@ -271,6 +271,7 @@ class HomeActivity : if (isFirstCreation()) { handleIntent(intent) } + homeActivityViewModel.handle(HomeActivityViewActions.ViewStarted) } private fun handleShowAnalyticsOptIn() { diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewActions.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewActions.kt index 9df45e4553..5f89c89bc9 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewActions.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewActions.kt @@ -18,6 +18,7 @@ package im.vector.app.features.home import im.vector.app.core.platform.VectorViewModelAction -sealed class HomeActivityViewActions : VectorViewModelAction { - object PushPromptHasBeenReviewed : HomeActivityViewActions() +sealed interface HomeActivityViewActions : VectorViewModelAction { + object ViewStarted : HomeActivityViewActions + object PushPromptHasBeenReviewed : HomeActivityViewActions } 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 c975d53f33..35c112b63a 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 @@ -72,10 +72,13 @@ class HomeActivityViewModel @AssistedInject constructor( companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() + private var isInitialized = false private var checkBootstrap = false private var onceTrusted = false - init { + private fun initialize() { + if (isInitialized) return + isInitialized = true cleanupFiles() observeInitialSync() checkSessionPushIsOn() @@ -257,6 +260,9 @@ class HomeActivityViewModel @AssistedInject constructor( HomeActivityViewActions.PushPromptHasBeenReviewed -> { vectorPreferences.setDidAskUserToEnableSessionPush() } + HomeActivityViewActions.ViewStarted -> { + initialize() + } }.exhaustive } }