Skip to content

Instantly share code, notes, and snippets.

@szugyi
Created August 10, 2020 12:53
Show Gist options
  • Save szugyi/5f0afd94399950382ebf19acf0f8afcd to your computer and use it in GitHub Desktop.
Save szugyi/5f0afd94399950382ebf19acf0f8afcd to your computer and use it in GitHub Desktop.
class CounterAnalyticsModel @Inject constructor(
private val analyticsTracker: AnalyticsTracker
) : AnalyticsModel<CounterViewModel>() {
override fun onScreenViewModelAttached() {
viewModel.viewModelScope.launch {
flowOf(
viewModel.decrementValue
.getExecutedEvents()
.onEach {
analyticsTracker.logEvent(
Event.DECREMENT_CLICKED,
Param.VALUE to viewModel.value.value!!
)
},
viewModel.incrementValue
.getExecutedEvents()
.onEach {
analyticsTracker.logEvent(
Event.INCREMENT_CLICKED,
Param.VALUE to viewModel.value.value!!
)
}
).flattenMerge()
.collect()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment