Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Push initializers out of :android-app #1328

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
},
)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down