|
|
|
@ -17,11 +17,14 @@
@@ -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(
@@ -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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|