Skip to content

Commit

Permalink
Add analytics events for DateTimeSelectorScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Dec 19, 2024
1 parent 39e121f commit c454181
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package xyz.ksharma.krail.trip.planner.ui.state.datetimeselector

sealed interface DateTimeSelectorEvent {

data object ResetDateTimeClick : DateTimeSelectorEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.navigation.toRoute
import org.koin.compose.viewmodel.koinViewModel
import xyz.ksharma.krail.trip.planner.ui.navigation.DateTimeSelectorRoute
import xyz.ksharma.krail.trip.planner.ui.state.datetimeselector.DateTimeSelectionItem
import xyz.ksharma.krail.trip.planner.ui.state.datetimeselector.DateTimeSelectorEvent

internal fun NavGraphBuilder.dateTimeSelectorDestination(navController: NavHostController) {
composable<DateTimeSelectorRoute> { backStackEntry ->
Expand All @@ -29,7 +30,10 @@ internal fun NavGraphBuilder.dateTimeSelectorDestination(navController: NavHostC
value = dateTimeSelection?.toJsonString(),
)
navController.popBackStack()
}
},
onResetClick = {
viewModel.onEvent(DateTimeSelectorEvent.ResetDateTimeClick)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fun DateTimeSelectorScreen(
modifier: Modifier = Modifier,
onBackClick: () -> Unit = {},
onDateTimeSelected: (DateTimeSelectionItem?) -> Unit = {},
onResetClick: () -> Unit = {},
) {
// Colors
val themeColorHex by LocalThemeColor.current
Expand Down Expand Up @@ -142,6 +143,7 @@ fun DateTimeSelectorScreen(
timePickerState.minute = now.time.minute
journeyTimeOption = JourneyTimeOptions.LEAVE
reset = true
onResetClick()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import xyz.ksharma.krail.core.analytics.Analytics
import xyz.ksharma.krail.core.analytics.AnalyticsScreen
import xyz.ksharma.krail.core.analytics.event.AnalyticsEvent
import xyz.ksharma.krail.core.analytics.event.trackScreenViewEvent
import xyz.ksharma.krail.trip.planner.ui.state.datetimeselector.DateTimeSelectorEvent

class DateTimeSelectorViewModel(
private val analytics: Analytics,
Expand All @@ -20,4 +22,14 @@ class DateTimeSelectorViewModel(
.onStart {
analytics.trackScreenViewEvent(screen = AnalyticsScreen.PlanTrip)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), Unit)

fun onEvent(event: DateTimeSelectorEvent) {
when (event) {
is DateTimeSelectorEvent.ResetDateTimeClick -> onResetDateTimeClick()
}
}

private fun onResetDateTimeClick() {
analytics.track(AnalyticsEvent.ResetTimeClickEvent)
}
}

0 comments on commit c454181

Please sign in to comment.