diff --git a/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRail.kt b/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRail.kt index b18c1ff1..d838b4fb 100644 --- a/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRail.kt +++ b/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRail.kt @@ -37,6 +37,8 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import com.google.accompanist.insets.systemBarsPadding +import tm.alashow.base.util.event +import tm.alashow.common.compose.LocalAnalytics import tm.alashow.common.compose.rememberFlowWithLifecycle import tm.alashow.datmusic.ui.playback.PlaybackMiniControlsDefaults import tm.alashow.navigation.screens.RootScreen @@ -125,6 +127,7 @@ private fun Modifier.resizableArea( orientation: Orientation = Orientation.Horizontal, ) = composed { val haptic = LocalHapticFeedback.current + val analytics = LocalAnalytics.current draggable( orientation = orientation, state = rememberDraggableState { delta -> @@ -144,6 +147,7 @@ private fun Modifier.resizableArea( newAnchor = 0 setDragSnapCurrentAnchor(newAnchor) setDividerDragOffset(dragSnapAnchors[dragSnapCurrentAnchor]) + analytics.event("home.navigationRail.snapAnchor", mapOf("anchor" to newAnchor)) }, ) } diff --git a/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRailViewModel.kt b/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRailViewModel.kt index 366306ca..c5c9b5ef 100644 --- a/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRailViewModel.kt +++ b/app/src/main/kotlin/tm/alashow/datmusic/ui/home/ResizableHomeNavigationRailViewModel.kt @@ -8,6 +8,7 @@ import androidx.datastore.preferences.core.floatPreferencesKey import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.google.firebase.analytics.FirebaseAnalytics import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow @@ -15,6 +16,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.launch +import tm.alashow.base.util.event import tm.alashow.data.PreferencesStore private val HomeNavigationRailDragOffsetKey = floatPreferencesKey("HomeNavigationRailWeightKey") @@ -24,6 +26,7 @@ private const val HomeNavigationRailWeightDefault = 0f class ResizableHomeNavigationRailViewModel @Inject constructor( handle: SavedStateHandle, private val preferencesStore: PreferencesStore, + private val analytics: FirebaseAnalytics, ) : ViewModel() { private val dragOffsetState = MutableStateFlow(handle.get(HomeNavigationRailDragOffsetKey.name) ?: HomeNavigationRailWeightDefault) @@ -49,5 +52,10 @@ class ResizableHomeNavigationRailViewModel @Inject constructor( .debounce(100) .collectLatest { preferencesStore.save(HomeNavigationRailDragOffsetKey, it) } } + viewModelScope.launch { + dragOffsetState + .debounce(2000) + .collectLatest { analytics.event("home.navigationRail.resize", mapOf("offset" to it)) } + } } }