Improve ScreenTracker.
This commit is contained in:
committed by
Benoit Marty
parent
f11dd23327
commit
37c41131ea
@@ -37,7 +37,7 @@ class TroubleshootNotificationsNode @AssistedInject constructor(
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
screenTracker.TrackScreen(this, MobileScreen.ScreenName.NotificationTroubleshoot)
|
||||
screenTracker.TrackScreen(MobileScreen.ScreenName.NotificationTroubleshoot)
|
||||
val state = presenter.present()
|
||||
TroubleshootNotificationsView(
|
||||
state = state,
|
||||
|
||||
@@ -24,7 +24,6 @@ android {
|
||||
dependencies {
|
||||
api(projects.services.analyticsproviders.api)
|
||||
api(projects.services.toolbox.api)
|
||||
api(libs.appyx.core)
|
||||
implementation(libs.coroutines.core)
|
||||
implementation(projects.libraries.matrix.api)
|
||||
implementation(projects.libraries.core)
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
package io.element.android.services.analytics.api
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
|
||||
interface ScreenTracker {
|
||||
@Composable
|
||||
fun TrackScreen(
|
||||
node: Node,
|
||||
screen: MobileScreen.ScreenName,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ dependencies {
|
||||
implementation(projects.libraries.androidutils)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(projects.libraries.architecture)
|
||||
implementation(projects.libraries.designsystem)
|
||||
implementation(projects.libraries.sessionStorage.api)
|
||||
|
||||
api(projects.services.analyticsproviders.api)
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package io.element.android.services.analytics.impl
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import com.bumble.appyx.core.lifecycle.subscribe
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import io.element.android.libraries.designsystem.utils.OnLifecycleEvent
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.services.analytics.api.AnalyticsService
|
||||
import io.element.android.services.analytics.api.ScreenTracker
|
||||
@@ -35,24 +38,22 @@ class DefaultScreenTracker @Inject constructor(
|
||||
) : ScreenTracker {
|
||||
@Composable
|
||||
override fun TrackScreen(
|
||||
node: Node,
|
||||
screen: MobileScreen.ScreenName,
|
||||
) {
|
||||
LaunchedEffect(Unit) {
|
||||
var startTime = 0L
|
||||
node.lifecycle.subscribe(
|
||||
onResume = {
|
||||
var startTime by remember { mutableLongStateOf(0L) }
|
||||
OnLifecycleEvent { _, event ->
|
||||
when (event) {
|
||||
Lifecycle.Event.ON_RESUME -> {
|
||||
startTime = systemClock.epochMillis()
|
||||
},
|
||||
onPause = {
|
||||
analyticsService.screen(
|
||||
screen = MobileScreen(
|
||||
durationMs = (systemClock.epochMillis() - startTime).toInt(),
|
||||
screenName = screen
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
Lifecycle.Event.ON_PAUSE -> analyticsService.screen(
|
||||
screen = MobileScreen(
|
||||
durationMs = (systemClock.epochMillis() - startTime).toInt(),
|
||||
screenName = screen
|
||||
)
|
||||
)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user