Merge pull request #605 from android/dt/update-analytics

Make Hilt provide Firebase.analytics
pull/607/head
Don Turner 2 years ago committed by GitHub
commit c677db2344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,14 +16,25 @@
package com.google.samples.apps.nowinandroid.core.analytics package com.google.samples.apps.nowinandroid.core.analytics
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
import dagger.Binds import dagger.Binds
import dagger.Module import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module @Module
@InstallIn(SingletonComponent::class) @InstallIn(SingletonComponent::class)
abstract class AnalyticsModule { abstract class AnalyticsModule {
@Binds @Binds
abstract fun bindsAnalyticsHelper(analyticsHelperImpl: FirebaseAnalyticsHelper): AnalyticsHelper abstract fun bindsAnalyticsHelper(analyticsHelperImpl: FirebaseAnalyticsHelper): AnalyticsHelper
companion object {
@Provides
@Singleton
fun provideFirebaseAnalytics(): FirebaseAnalytics { return Firebase.analytics }
}
} }

@ -16,19 +16,16 @@
package com.google.samples.apps.nowinandroid.core.analytics package com.google.samples.apps.nowinandroid.core.analytics
import com.google.firebase.analytics.ktx.analytics import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.logEvent import com.google.firebase.analytics.ktx.logEvent
import com.google.firebase.ktx.Firebase
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton
/** /**
* Implementation of `AnalyticsHelper` which logs events to a Firebase backend. * Implementation of `AnalyticsHelper` which logs events to a Firebase backend.
*/ */
@Singleton class FirebaseAnalyticsHelper @Inject constructor(
class FirebaseAnalyticsHelper @Inject constructor() : AnalyticsHelper { private val firebaseAnalytics: FirebaseAnalytics,
) : AnalyticsHelper {
private val firebaseAnalytics = Firebase.analytics
override fun logEvent(event: AnalyticsEvent) { override fun logEvent(event: AnalyticsEvent) {
firebaseAnalytics.logEvent(event.type) { firebaseAnalytics.logEvent(event.type) {

Loading…
Cancel
Save