From 1326b1a979381aa7004153bba28f3ffe6ba6d34e Mon Sep 17 00:00:00 2001 From: JUNWON LEE Date: Sun, 15 Sep 2024 17:42:46 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20App=20->=20analytics=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=EB=A1=9C=20FIrebase=20init=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=20(#318)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/analytics/AnalyticsInitializer.kt | 28 +++++++++++++++ .../rogue/helper/analytics/AnalyticsLogger.kt | 8 ++--- .../poke/rogue/helper/PokeRogueHelperApp.kt | 34 ++----------------- 3 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsInitializer.kt diff --git a/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsInitializer.kt b/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsInitializer.kt new file mode 100644 index 00000000..eab04f16 --- /dev/null +++ b/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsInitializer.kt @@ -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") + } + } +} diff --git a/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsLogger.kt b/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsLogger.kt index f5989a82..791c99dc 100644 --- a/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsLogger.kt +++ b/android/analytics/src/main/java/poke/rogue/helper/analytics/AnalyticsLogger.kt @@ -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 { diff --git a/android/app/src/main/java/poke/rogue/helper/PokeRogueHelperApp.kt b/android/app/src/main/java/poke/rogue/helper/PokeRogueHelperApp.kt index c4d644a6..eab70e34 100644 --- a/android/app/src/main/java/poke/rogue/helper/PokeRogueHelperApp.kt +++ b/android/app/src/main/java/poke/rogue/helper/PokeRogueHelperApp.kt @@ -1,9 +1,7 @@ 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 @@ -11,7 +9,7 @@ class PokeRogueHelperApp : Application() { override fun onCreate() { super.onCreate() initTimber() - initFirebase() + AnalyticsInitializer.init() DefaultDexRepository.init(this) } @@ -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" - } }