From 2f3fc85d658cb37d3e64a404c596a5b33ac56685 Mon Sep 17 00:00:00 2001 From: Don Turner Date: Mon, 20 Feb 2023 21:07:43 +0000 Subject: [PATCH] Make Hilt provide Firebase.analytics Change-Id: I57bec82713ce7ce3a17cd4ad0f377c28c2aedb89 --- .../nowinandroid/core/analytics/AnalyticsModule.kt | 11 +++++++++++ .../core/analytics/FirebaseAnalyticsHelper.kt | 11 ++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/AnalyticsModule.kt b/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/AnalyticsModule.kt index e947d036b..9f875ae6d 100644 --- a/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/AnalyticsModule.kt +++ b/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/AnalyticsModule.kt @@ -16,14 +16,25 @@ 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.Module +import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) abstract class AnalyticsModule { @Binds abstract fun bindsAnalyticsHelper(analyticsHelperImpl: FirebaseAnalyticsHelper): AnalyticsHelper + + companion object { + @Provides + @Singleton + fun provideFirebaseAnalytics(): FirebaseAnalytics { return Firebase.analytics } + } } diff --git a/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/FirebaseAnalyticsHelper.kt b/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/FirebaseAnalyticsHelper.kt index 96b9ce67d..75dfbc468 100644 --- a/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/FirebaseAnalyticsHelper.kt +++ b/core/analytics/src/prod/java/com/google/samples/apps/nowinandroid/core/analytics/FirebaseAnalyticsHelper.kt @@ -16,19 +16,16 @@ 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.ktx.Firebase import javax.inject.Inject -import javax.inject.Singleton /** * Implementation of `AnalyticsHelper` which logs events to a Firebase backend. */ -@Singleton -class FirebaseAnalyticsHelper @Inject constructor() : AnalyticsHelper { - - private val firebaseAnalytics = Firebase.analytics +class FirebaseAnalyticsHelper @Inject constructor( + private val firebaseAnalytics: FirebaseAnalytics, +) : AnalyticsHelper { override fun logEvent(event: AnalyticsEvent) { firebaseAnalytics.logEvent(event.type) {