From 04ff873d7add7f34adddc7027ff16a76111ba250 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Sat, 19 Oct 2024 14:37:23 +0900 Subject: [PATCH] [FEAT/#288] put amplitude tracker in activity --- .../com/terning/core/analytics/AmplitudeTracker.kt | 5 +++++ .../java/com/terning/feature/main/MainActivity.kt | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt index c9123c664..3340bcc90 100644 --- a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt +++ b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt @@ -1,6 +1,7 @@ package com.terning.core.analytics import android.content.Context +import androidx.compose.runtime.staticCompositionLocalOf import com.amplitude.android.Amplitude import com.amplitude.android.Configuration import com.terning.core.BuildConfig @@ -8,6 +9,10 @@ import dagger.hilt.android.qualifiers.ApplicationContext import timber.log.Timber import javax.inject.Inject +val LocalTracker = staticCompositionLocalOf { + error("No AmplitudeTracker provided") +} + class AmplitudeTracker @Inject constructor( @ApplicationContext private val context: Context ) { diff --git a/feature/src/main/java/com/terning/feature/main/MainActivity.kt b/feature/src/main/java/com/terning/feature/main/MainActivity.kt index 58b15268d..7e6e44656 100644 --- a/feature/src/main/java/com/terning/feature/main/MainActivity.kt +++ b/feature/src/main/java/com/terning/feature/main/MainActivity.kt @@ -4,18 +4,28 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.CompositionLocalProvider +import com.terning.core.analytics.AmplitudeTracker +import com.terning.core.analytics.LocalTracker import com.terning.core.designsystem.theme.TerningPointTheme import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject @AndroidEntryPoint class MainActivity : ComponentActivity() { + + @Inject + lateinit var tracker: AmplitudeTracker + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { val navigator: MainNavigator = rememberMainNavigator() TerningPointTheme { - MainScreen(navigator) + CompositionLocalProvider(LocalTracker provides tracker) { + MainScreen(navigator) + } } } }