Skip to content

Commit

Permalink
Add some analytics on ResizableHomeNavigationRail events
Browse files Browse the repository at this point in the history
  • Loading branch information
alashow committed Dec 18, 2021
1 parent 0b367c1 commit 876ad6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -144,6 +147,7 @@ private fun Modifier.resizableArea(
newAnchor = 0
setDragSnapCurrentAnchor(newAnchor)
setDividerDragOffset(dragSnapAnchors[dragSnapCurrentAnchor])
analytics.event("home.navigationRail.snapAnchor", mapOf("anchor" to newAnchor))
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ 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
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")
Expand All @@ -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)
Expand All @@ -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)) }
}
}
}

0 comments on commit 876ad6d

Please sign in to comment.