diff --git a/android-app/app/src/main/java/app/tivi/appinitializers/LoggerInitializer.kt b/android-app/app/src/main/java/app/tivi/appinitializers/LoggerInitializer.kt deleted file mode 100644 index b91c1c7d7a..0000000000 --- a/android-app/app/src/main/java/app/tivi/appinitializers/LoggerInitializer.kt +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018, Google LLC, Christopher Banes and the Tivi project contributors -// SPDX-License-Identifier: Apache-2.0 - -package app.tivi.appinitializers - -import app.tivi.BuildConfig -import app.tivi.util.Logger -import me.tatarka.inject.annotations.Inject - -@Inject -class LoggerInitializer( - private val logger: Logger, -) : AppInitializer { - @Suppress("KotlinConstantConditions") - override fun init() { - val debugMode = when { - BuildConfig.DEBUG -> true - BuildConfig.FLAVOR == "qa" -> true - else -> false - } - logger.setup(debugMode) - } -} diff --git a/android-app/app/src/main/java/app/tivi/inject/AndroidApplicationComponent.kt b/android-app/app/src/main/java/app/tivi/inject/AndroidApplicationComponent.kt index ef15e74a2e..8d743463b2 100644 --- a/android-app/app/src/main/java/app/tivi/inject/AndroidApplicationComponent.kt +++ b/android-app/app/src/main/java/app/tivi/inject/AndroidApplicationComponent.kt @@ -8,20 +8,17 @@ import android.content.Context import app.tivi.BuildConfig import app.tivi.TiviApplication import app.tivi.app.ApplicationInfo +import app.tivi.app.Flavor import app.tivi.appinitializers.AppInitializer import app.tivi.appinitializers.AppInitializers import app.tivi.appinitializers.EmojiInitializer -import app.tivi.appinitializers.LoggerInitializer -import app.tivi.appinitializers.TmdbInitializer import app.tivi.common.imageloading.ImageLoadingComponent import app.tivi.data.traktauth.TraktOAuthInfo import app.tivi.home.ContentViewSetterComponent import app.tivi.tasks.TiviWorkerFactory import app.tivi.tmdb.TmdbOAuthInfo -import app.tivi.util.AppCoroutineDispatchers import java.io.File import java.util.concurrent.TimeUnit -import kotlinx.coroutines.Dispatchers import me.tatarka.inject.annotations.Component import me.tatarka.inject.annotations.IntoSet import me.tatarka.inject.annotations.Provides @@ -44,23 +41,17 @@ abstract class AndroidApplicationComponent( abstract val initializers: AppInitializers abstract val workerFactory: TiviWorkerFactory - /** - * Need to wait to upgrade to Coroutines 1.7.x so we can reference IO from common - */ @ApplicationScope @Provides - fun provideCoroutineDispatchers(): AppCoroutineDispatchers = AppCoroutineDispatchers( - io = Dispatchers.IO, - computation = Dispatchers.Default, - main = Dispatchers.Main, + fun provideApplicationId(application: Application): ApplicationInfo = ApplicationInfo( + packageName = application.packageName, + debugBuild = BuildConfig.DEBUG, + flavor = when (BuildConfig.FLAVOR) { + "qa" -> Flavor.Qa + else -> Flavor.Standard + }, ) - @ApplicationScope - @Provides - fun provideApplicationId(application: Application): ApplicationInfo { - return ApplicationInfo(application.packageName) - } - @ApplicationScope @Provides fun provideTmdbApiKey(): TmdbOAuthInfo = TmdbOAuthInfo(BuildConfig.TMDB_API_KEY) @@ -79,14 +70,6 @@ abstract class AndroidApplicationComponent( @IntoSet fun provideEmojiInitializer(bind: EmojiInitializer): AppInitializer = bind - @Provides - @IntoSet - fun provideLoggerInitializer(bind: LoggerInitializer): AppInitializer = bind - - @Provides - @IntoSet - fun provideTmdbInitializer(bind: TmdbInitializer): AppInitializer = bind - @ApplicationScope @Provides fun provideOkHttpClient( diff --git a/core/base/src/commonMain/kotlin/app/tivi/app/ApplicationInfo.kt b/core/base/src/commonMain/kotlin/app/tivi/app/ApplicationInfo.kt index 91683b993d..e321d61ed3 100644 --- a/core/base/src/commonMain/kotlin/app/tivi/app/ApplicationInfo.kt +++ b/core/base/src/commonMain/kotlin/app/tivi/app/ApplicationInfo.kt @@ -5,4 +5,10 @@ package app.tivi.app data class ApplicationInfo( val packageName: String, + val debugBuild: Boolean, + val flavor: Flavor, ) + +enum class Flavor { + Qa, Standard +} diff --git a/core/logging/src/androidMain/kotlin/app/tivi/util/LoggerComponent.kt b/core/logging/src/androidMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt similarity index 88% rename from core/logging/src/androidMain/kotlin/app/tivi/util/LoggerComponent.kt rename to core/logging/src/androidMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt index 5c098c1d2c..e1b568d6a9 100644 --- a/core/logging/src/androidMain/kotlin/app/tivi/util/LoggerComponent.kt +++ b/core/logging/src/androidMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt @@ -6,7 +6,7 @@ package app.tivi.util import app.tivi.inject.ApplicationScope import me.tatarka.inject.annotations.Provides -actual interface LoggerComponent { +actual interface LoggerPlatformComponent { @ApplicationScope @Provides fun provideLogger(bind: TimberLogger): Logger = bind diff --git a/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerComponent.kt b/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerComponent.kt deleted file mode 100644 index 68f62b0408..0000000000 --- a/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerComponent.kt +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2022, Christopher Banes and the Tivi project contributors -// SPDX-License-Identifier: Apache-2.0 - -package app.tivi.util - -expect interface LoggerComponent diff --git a/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerInitializer.kt b/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerInitializer.kt new file mode 100644 index 0000000000..8ab51bd7dc --- /dev/null +++ b/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerInitializer.kt @@ -0,0 +1,25 @@ +// Copyright 2018, Google LLC, Christopher Banes and the Tivi project contributors +// SPDX-License-Identifier: Apache-2.0 + +package app.tivi.util + +import app.tivi.app.ApplicationInfo +import app.tivi.app.Flavor +import app.tivi.appinitializers.AppInitializer +import me.tatarka.inject.annotations.Inject + +@Inject +class LoggerInitializer( + private val logger: Logger, + private val applicationInfo: ApplicationInfo, +) : AppInitializer { + override fun init() { + logger.setup( + debugMode = when { + applicationInfo.debugBuild -> true + applicationInfo.flavor == Flavor.Qa -> true + else -> false + }, + ) + } +} diff --git a/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt b/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt new file mode 100644 index 0000000000..c570ab812c --- /dev/null +++ b/core/logging/src/commonMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt @@ -0,0 +1,16 @@ +// Copyright 2022, Christopher Banes and the Tivi project contributors +// SPDX-License-Identifier: Apache-2.0 + +package app.tivi.util + +import app.tivi.appinitializers.AppInitializer +import me.tatarka.inject.annotations.IntoSet +import me.tatarka.inject.annotations.Provides + +expect interface LoggerPlatformComponent + +interface LoggerComponent : LoggerPlatformComponent { + @Provides + @IntoSet + fun provideLoggerInitializer(bind: LoggerInitializer): AppInitializer = bind +} diff --git a/core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerComponent.kt b/core/logging/src/iosMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt similarity index 88% rename from core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerComponent.kt rename to core/logging/src/iosMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt index c3c9db14de..c55d765983 100644 --- a/core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerComponent.kt +++ b/core/logging/src/iosMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt @@ -6,7 +6,7 @@ package app.tivi.util import app.tivi.inject.ApplicationScope import me.tatarka.inject.annotations.Provides -actual interface LoggerComponent { +actual interface LoggerPlatformComponent { @ApplicationScope @Provides fun provideLogger(bind: KermitLogger): Logger = bind diff --git a/core/logging/src/iosMain/kotlin/app/tivi/util/LoggerComponent.kt b/core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt similarity index 88% rename from core/logging/src/iosMain/kotlin/app/tivi/util/LoggerComponent.kt rename to core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt index c3c9db14de..c55d765983 100644 --- a/core/logging/src/iosMain/kotlin/app/tivi/util/LoggerComponent.kt +++ b/core/logging/src/jvmMain/kotlin/app/tivi/util/LoggerPlatformComponent.kt @@ -6,7 +6,7 @@ package app.tivi.util import app.tivi.inject.ApplicationScope import me.tatarka.inject.annotations.Provides -actual interface LoggerComponent { +actual interface LoggerPlatformComponent { @ApplicationScope @Provides fun provideLogger(bind: KermitLogger): Logger = bind diff --git a/android-app/app/src/main/java/app/tivi/appinitializers/AppInitializers.kt b/shared/src/commonMain/kotlin/app/tivi/appinitializers/AppInitializers.kt similarity index 100% rename from android-app/app/src/main/java/app/tivi/appinitializers/AppInitializers.kt rename to shared/src/commonMain/kotlin/app/tivi/appinitializers/AppInitializers.kt diff --git a/android-app/app/src/main/java/app/tivi/appinitializers/TmdbInitializer.kt b/shared/src/commonMain/kotlin/app/tivi/appinitializers/TmdbInitializer.kt similarity index 100% rename from android-app/app/src/main/java/app/tivi/appinitializers/TmdbInitializer.kt rename to shared/src/commonMain/kotlin/app/tivi/appinitializers/TmdbInitializer.kt diff --git a/shared/src/commonMain/kotlin/app/tivi/inject/SharedApplicationComponent.kt b/shared/src/commonMain/kotlin/app/tivi/inject/SharedApplicationComponent.kt index e2f48409e7..5b9906aeb5 100644 --- a/shared/src/commonMain/kotlin/app/tivi/inject/SharedApplicationComponent.kt +++ b/shared/src/commonMain/kotlin/app/tivi/inject/SharedApplicationComponent.kt @@ -3,6 +3,8 @@ package app.tivi.inject +import app.tivi.appinitializers.AppInitializer +import app.tivi.appinitializers.TmdbInitializer import app.tivi.core.analytics.AnalyticsComponent import app.tivi.core.perf.PerformanceComponent import app.tivi.data.SqlDelightDatabaseComponent @@ -22,8 +24,13 @@ import app.tivi.settings.PreferencesComponent import app.tivi.tasks.TasksComponent import app.tivi.tmdb.TmdbComponent import app.tivi.trakt.TraktComponent +import app.tivi.util.AppCoroutineDispatchers import app.tivi.util.LoggerComponent import app.tivi.util.PowerControllerComponent +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.IO +import me.tatarka.inject.annotations.IntoSet +import me.tatarka.inject.annotations.Provides interface SharedApplicationComponent : ApiComponent, @@ -38,7 +45,23 @@ interface CoreComponent : LoggerComponent, PerformanceComponent, PowerControllerComponent, - PreferencesComponent + PreferencesComponent { + + /** + * Need to wait to upgrade to Coroutines 1.7.x so we can reference IO from common + */ + @ApplicationScope + @Provides + fun provideCoroutineDispatchers(): AppCoroutineDispatchers = AppCoroutineDispatchers( + io = Dispatchers.IO, + computation = Dispatchers.Default, + main = Dispatchers.Main, + ) + + @Provides + @IntoSet + fun provideTmdbInitializer(bind: TmdbInitializer): AppInitializer = bind +} interface DataComponent : EpisodeBinds,