create event tracker class to inject into view models
This commit is contained in:
@ -8,8 +8,6 @@ import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
import com.segment.analytics.kotlin.android.Analytics
|
||||
import com.segment.analytics.kotlin.core.*
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@ -27,16 +25,5 @@ object AppModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideAnalytics(
|
||||
@ApplicationContext app: Context
|
||||
): Analytics {
|
||||
val writeKey = app.getString(R.string.segment_write_key)
|
||||
|
||||
// TODO: abstract analytics to custom class
|
||||
return Analytics(writeKey, app.applicationContext) {
|
||||
trackApplicationLifecycleEvents = true
|
||||
application = app.applicationContext
|
||||
useLifecycleObserver = true
|
||||
}
|
||||
}
|
||||
fun provideAnalytics(@ApplicationContext app: Context) = EventTracker(app)
|
||||
}
|
||||
|
||||
@ -36,7 +36,8 @@ data class PendingEmailUserCreds(
|
||||
|
||||
@HiltViewModel
|
||||
class LoginViewModel @Inject constructor(
|
||||
private val datastoreRepo: DatastoreRepository
|
||||
private val datastoreRepo: DatastoreRepository,
|
||||
private val eventTracker: EventTracker
|
||||
): ViewModel() {
|
||||
private var validateUsernameJob: Job? = null
|
||||
|
||||
@ -90,6 +91,10 @@ class LoginViewModel @Inject constructor(
|
||||
showSocialLogin()
|
||||
}
|
||||
|
||||
fun registerUser() {
|
||||
// TODO: eventTracker.registerUser()
|
||||
}
|
||||
|
||||
private fun resetState() {
|
||||
validateUsernameJob = null
|
||||
isLoading = false
|
||||
|
||||
@ -19,7 +19,6 @@ import javax.inject.Inject
|
||||
@HiltViewModel
|
||||
class HomeViewModel @Inject constructor(
|
||||
private val networker: Networker,
|
||||
private val analytics: com.segment.analytics.kotlin.core.Analytics
|
||||
): ViewModel() {
|
||||
private var cursor: String? = null
|
||||
private var items: List<LinkedItem> = listOf()
|
||||
|
||||
@ -53,6 +53,13 @@ fun RootView(
|
||||
} else {
|
||||
WelcomeScreen(viewModel = loginViewModel)
|
||||
}
|
||||
|
||||
DisposableEffect(hasAuthToken) {
|
||||
if (hasAuthToken) {
|
||||
loginViewModel.registerUser()
|
||||
}
|
||||
onDispose {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user