Skip to content

Commit

Permalink
[FEAT/#288] put amplitude tracker in activity
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Oct 19, 2024
1 parent 04522aa commit 04ff873
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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
import dagger.hilt.android.qualifiers.ApplicationContext
import timber.log.Timber
import javax.inject.Inject

val LocalTracker = staticCompositionLocalOf<AmplitudeTracker> {
error("No AmplitudeTracker provided")
}

class AmplitudeTracker @Inject constructor(
@ApplicationContext private val context: Context
) {
Expand Down
12 changes: 11 additions & 1 deletion feature/src/main/java/com/terning/feature/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 04ff873

Please sign in to comment.