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 c9123c66..3340bcc9 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 58b15268..7e6e4465 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) + } } } }