diff --git a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt index 70488127..57a70f14 100644 --- a/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt +++ b/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt @@ -118,6 +118,10 @@ public class PostHogReplayIntegration( private val isSessionReplayEnabled: Boolean get() = PostHog.isSessionReplayActive() + private var sessionStartTime = 0L + private var sessionEndTime = 0L + + private fun addView( view: View, added: Boolean = true, @@ -148,7 +152,11 @@ public class PostHogReplayIntegration( executor.submit { try { - generateSnapshot(WeakReference(decorView), WeakReference(window), timestamp) + generateSnapshot( + WeakReference(decorView), + WeakReference(window), + timestamp + ) } catch (e: Throwable) { config.logger.log("Session Replay generateSnapshot failed: $e.") } @@ -229,10 +237,19 @@ public class PostHogReplayIntegration( } when (motionEvent.action.and(MotionEvent.ACTION_MASK)) { MotionEvent.ACTION_DOWN -> { - generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchStart) + generateMouseInteractions( + timestamp, + motionEvent, + RRMouseInteraction.TouchStart + ) } + MotionEvent.ACTION_UP -> { - generateMouseInteractions(timestamp, motionEvent, RRMouseInteraction.TouchEnd) + generateMouseInteractions( + timestamp, + motionEvent, + RRMouseInteraction.TouchEnd + ) } } } catch (e: Throwable) { @@ -265,7 +282,8 @@ public class PostHogReplayIntegration( x = absX, y = absY, ) - val mouseInteraction = RRIncrementalMouseInteractionEvent(mouseInteractionData, timestamp) + val mouseInteraction = + RRIncrementalMouseInteractionEvent(mouseInteractionData, timestamp) mouseInteractions.add(mouseInteraction) } @@ -312,6 +330,9 @@ public class PostHogReplayIntegration( // workaround for react native that is started after the window is added // Curtains.rootViews should be empty for normal apps yet + + sessionStartTime = config.dateProvider.currentTimeMillis() + Curtains.rootViews.forEach { view -> addView(view) } @@ -325,6 +346,13 @@ public class PostHogReplayIntegration( override fun uninstall() { try { + sessionEndTime = config.dateProvider.currentTimeMillis() + + //TODO improve this + if (sessionEndTime - sessionStartTime <= config.sessionReplayConfig.minSessionDurationMs) { + //Delete existing session recording? + } + Curtains.onRootViewsChangedListeners -= onRootViewsChangedListener decorViews.entries.forEach { @@ -742,14 +770,17 @@ public class PostHogReplayIntegration( style.verticalAlign = "center" style.horizontalAlign = "center" } + View.TEXT_ALIGNMENT_TEXT_END, View.TEXT_ALIGNMENT_VIEW_END -> { style.verticalAlign = "center" style.horizontalAlign = "right" } + View.TEXT_ALIGNMENT_TEXT_START, View.TEXT_ALIGNMENT_VIEW_START -> { style.verticalAlign = "center" style.horizontalAlign = "left" } + View.TEXT_ALIGNMENT_GRAVITY -> { val horizontalAlignment = when (view.gravity.and(Gravity.HORIZONTAL_GRAVITY_MASK)) { @@ -769,6 +800,7 @@ public class PostHogReplayIntegration( } style.verticalAlign = verticalAlignment } + else -> { style.verticalAlign = "center" style.horizontalAlign = "left"