Skip to content

Commit

Permalink
refactor: App -> analytics 모듈로 FIrebase init 로직 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Sep 10, 2024
1 parent 9b80faa commit 29ee1b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package poke.rogue.helper.analytics

import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

object AnalyticsInitializer {
fun init() {
when (BuildConfig.BUILD_TYPE) {
DEBUG_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(false)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(false)
}

ALPHA_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(false)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
}

BETA_MODE, RELEASE_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(true)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
}

else -> error("Unknown build type")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package poke.rogue.helper.analytics

private const val DEBUG_MODE = "debug"
private const val ALPHA_MODE = "alpha"
private const val BETA_MODE = "beta"
private const val RELEASE_MODE = "release"
internal const val DEBUG_MODE = "debug"
internal const val ALPHA_MODE = "alpha"
internal const val BETA_MODE = "beta"
internal const val RELEASE_MODE = "release"

/** Analytics API surface */
interface AnalyticsLogger {
Expand Down
34 changes: 2 additions & 32 deletions android/app/src/main/java/poke/rogue/helper/PokeRogueHelperApp.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package poke.rogue.helper

import android.app.Application
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import poke.rogue.helper.analytics.AnalyticsInitializer
import poke.rogue.helper.data.repository.DefaultDexRepository
import timber.log.Timber

class PokeRogueHelperApp : Application() {
override fun onCreate() {
super.onCreate()
initTimber()
initFirebase()
AnalyticsInitializer.init()
DefaultDexRepository.init(this)
}

Expand All @@ -26,32 +24,4 @@ class PokeRogueHelperApp : Application() {
)
}
}

private fun initFirebase() {
when (BuildConfig.BUILD_TYPE) {
DEBUG_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(false)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(false)
}

ALPHA_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(false)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
}

BETA_MODE, RELEASE_MODE -> {
Firebase.analytics.setAnalyticsCollectionEnabled(true)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
}

else -> error("Unknown build type")
}
}

companion object {
private const val DEBUG_MODE = "debug"
private const val ALPHA_MODE = "alpha"
private const val BETA_MODE = "beta"
private const val RELEASE_MODE = "release"
}
}

0 comments on commit 29ee1b1

Please sign in to comment.