Skip to content

Commit

Permalink
Move Anvil codegen to external library (#249)
Browse files Browse the repository at this point in the history
* Add pixnews-anvil-generator

* Add external activity generator

* Move experiment generator to external library. Bump JDK version to 17

* Move initializer generator to external library

* Move test generator to external library. Restore JVM 11

* Mode viewmodel generator to external library

* Mode workmanager generator to external library

* Remove anvil-codegen module
  • Loading branch information
illarionov authored Jan 16, 2024
1 parent 0d8c1ba commit 6d32b4f
Show file tree
Hide file tree
Showing 90 changed files with 131 additions and 1,995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import com.google.accompanist.testharness.TestHarness
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import ru.pixnews.anvil.codegen.test.inject.ContributesTest
import ru.pixnews.feature.calendar.test.element.GameFeedElement
import ru.pixnews.feature.root.PixnewsRootContent
import ru.pixnews.foundation.appconfig.AppConfig
import ru.pixnews.foundation.instrumented.test.base.BaseInstrumentedTest
import ru.pixnews.foundation.instrumented.test.di.ContributesTest
import ru.pixnews.foundation.instrumented.test.di.rule.InjectDependenciesRule
import ru.pixnews.test.assumption.NetworkAssumptions
import ru.pixnews.test.assumption.UpcomingReleaseUseCaseAssumptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import ru.pixnews.MainActivity
import ru.pixnews.anvil.codegen.test.inject.ContributesTest
import ru.pixnews.domain.model.UpcomingReleaseTimeCategory.CURRENT_QUARTER
import ru.pixnews.domain.model.UpcomingReleaseTimeCategory.FEW_DAYS
import ru.pixnews.domain.model.datetime.Date
Expand All @@ -30,7 +31,6 @@ import ru.pixnews.feature.calendar.test.element.CalendarHeaderElement
import ru.pixnews.feature.calendar.test.element.GameFeedElement
import ru.pixnews.foundation.appconfig.AppConfig
import ru.pixnews.foundation.instrumented.test.base.BaseInstrumentedTest
import ru.pixnews.foundation.instrumented.test.di.ContributesTest
import ru.pixnews.foundation.instrumented.test.di.rule.InjectDependenciesRule
import ru.pixnews.library.instrumented.test.util.assertVerticalPaddingBetweenAdjacentItems
import ru.pixnews.test.assumption.UpcomingReleaseUseCaseAssumptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import co.touchlab.kermit.Logger
import org.junit.Rule
import org.junit.Test
import ru.pixnews.MainActivity
import ru.pixnews.anvil.codegen.test.inject.ContributesTest
import ru.pixnews.feature.calendar.test.constants.CalendarTestTag
import ru.pixnews.feature.calendar.test.element.CalendarHeaderElement
import ru.pixnews.foundation.instrumented.test.base.BaseInstrumentedTest
import ru.pixnews.foundation.instrumented.test.di.ContributesTest
import ru.pixnews.foundation.instrumented.test.di.rule.InjectDependenciesRule
import ru.pixnews.library.functional.network.NetworkRequestFailure
import ru.pixnews.test.assumption.UpcomingReleaseUseCaseAssumptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
import ru.pixnews.MainActivity
import ru.pixnews.anvil.codegen.test.inject.ContributesTest
import ru.pixnews.feature.calendar.test.element.CalendarHeaderElement
import ru.pixnews.feature.calendar.test.element.GameFeedElement
import ru.pixnews.foundation.instrumented.test.base.BaseInstrumentedTest
import ru.pixnews.foundation.instrumented.test.di.ContributesTest
import ru.pixnews.foundation.instrumented.test.di.rule.InjectDependenciesRule
import ru.pixnews.library.android.utils.rootView
import ru.pixnews.library.instrumented.test.rule.SystemNavigationRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import ru.pixnews.MainActivity
import ru.pixnews.anvil.codegen.test.inject.ContributesTest
import ru.pixnews.feature.navigation.BottomBarElement
import ru.pixnews.feature.root.TopLevelDestination.CALENDAR
import ru.pixnews.foundation.instrumented.test.base.BaseInstrumentedTest
import ru.pixnews.foundation.instrumented.test.di.ContributesTest
import ru.pixnews.foundation.instrumented.test.di.rule.InjectDependenciesRule
import ru.pixnews.test.assumption.UpcomingReleaseUseCaseAssumptions
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ import ru.pixnews.foundation.di.base.scopes.AppScope
object TestAnalyticsModule {
@Provides
@Reusable
fun provideAnalytics(): Analytics = NoOpAnalytics()
fun provideAnalytics(): Analytics = NoOpAnalytics
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

package ru.pixnews.inject.initializer

import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.AsyncInitializer
import ru.pixnews.foundation.initializers.inject.ContributesInitializer
import ru.pixnews.test.app.mock.igdb.IgdbMockWebServer
import javax.inject.Inject

@ContributesInitializer()
@ContributesInitializer
class StartMockServerInitializer @Inject constructor(
val igdbMockWebServer: IgdbMockWebServer,
) : AsyncInitializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package ru.pixnews.inject.initializer

import co.touchlab.kermit.Logger
import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.AsyncInitializer
import ru.pixnews.foundation.initializers.inject.ContributesInitializer
import ru.pixnews.initializers.FirebaseInitializer

@ContributesInitializer(replaces = [FirebaseInitializer::class])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package ru.pixnews.inject.initializer

import com.squareup.anvil.annotations.MergeComponent
import com.squareup.anvil.annotations.optional.SingleIn
import ru.pixnews.anvil.codegen.initializer.inject.wiring.AppInitializersScope
import ru.pixnews.di.root.component.PixnewsAppComponent
import ru.pixnews.foundation.initializers.inject.AppInitializersScope
import ru.pixnews.inject.MockWebServerHolder

@SingleIn(AppInitializersScope::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import androidx.fragment.app.strictmode.FragmentStrictMode
import androidx.fragment.app.strictmode.FragmentStrictMode.Policy
import co.touchlab.kermit.Logger
import ru.pixnews.MainActivity
import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.Initializer
import ru.pixnews.foundation.initializers.inject.ContributesInitializer
import ru.pixnews.inject.DebugStrictModeInitializerModule
import java.util.concurrent.Executors
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.squareup.anvil.annotations.ContributesTo
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoSet
import ru.pixnews.anvil.codegen.initializer.inject.wiring.AppInitializersScope
import ru.pixnews.foundation.initializers.Initializer
import ru.pixnews.foundation.initializers.inject.AppInitializersScope
import ru.pixnews.initializers.DebugStrictModeInitializer

@ContributesTo(AppInitializersScope::class)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/ru/pixnews/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import co.touchlab.kermit.Logger
import ru.pixnews.anvil.codegen.activity.inject.ContributesActivity
import ru.pixnews.feature.root.PixnewsRootContent
import ru.pixnews.foundation.analytics.Analytics
import ru.pixnews.foundation.appconfig.AppConfig
import ru.pixnews.foundation.di.ui.base.activity.BaseActivity
import ru.pixnews.foundation.di.ui.base.activity.ContributesActivity
import ru.pixnews.foundation.featuretoggles.FeatureToggle
import ru.pixnews.foundation.ui.experiments.DarkModeExperiment
import ru.pixnews.loadingstatus.AppLoadingStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package ru.pixnews.initializers

import co.touchlab.kermit.Logger
import com.google.firebase.FirebaseApp
import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.AsyncInitializer
import ru.pixnews.foundation.initializers.inject.ContributesInitializer
import javax.inject.Provider

@ContributesInitializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package ru.pixnews.initializers

import co.touchlab.kermit.Logger
import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.Initializer
import ru.pixnews.foundation.initializers.inject.ContributesInitializer

@ContributesInitializer
class GlobalLoggerInitializer(private val localLogger: Logger) : Initializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package ru.pixnews.inject.experiments

import com.squareup.anvil.annotations.MergeComponent
import com.squareup.anvil.annotations.optional.SingleIn
import ru.pixnews.anvil.codegen.experiment.inject.wiring.ExperimentScope
import ru.pixnews.foundation.di.base.DaggerMap
import ru.pixnews.foundation.di.base.DaggerSet
import ru.pixnews.foundation.featuretoggles.Experiment
import ru.pixnews.foundation.featuretoggles.ExperimentKey
import ru.pixnews.foundation.featuretoggles.ExperimentVariantSerializer
import ru.pixnews.foundation.featuretoggles.inject.ExperimentScope

@SingleIn(ExperimentScope::class)
@MergeComponent(scope = ExperimentScope::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import dagger.Module
import dagger.Provides
import dagger.Reusable
import dagger.multibindings.Multibinds
import ru.pixnews.anvil.codegen.experiment.inject.wiring.ExperimentScope
import ru.pixnews.foundation.di.base.DaggerMap
import ru.pixnews.foundation.di.base.DaggerSet
import ru.pixnews.foundation.featuretoggles.Experiment
import ru.pixnews.foundation.featuretoggles.ExperimentKey
import ru.pixnews.foundation.featuretoggles.ExperimentVariantSerializer
import ru.pixnews.foundation.featuretoggles.inject.ExperimentScope

@Module
@ContributesTo(ExperimentScope::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package ru.pixnews.inject.initializer
import com.squareup.anvil.annotations.MergeComponent
import com.squareup.anvil.annotations.optional.SingleIn
import dagger.Component
import ru.pixnews.anvil.codegen.initializer.inject.wiring.AppInitializersScope
import ru.pixnews.di.root.component.PixnewsAppComponent
import ru.pixnews.foundation.initializers.inject.AppInitializersScope
import ru.pixnews.inject.FirebaseModule.FirebaseProviderHolder

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import dagger.multibindings.Multibinds
import ru.pixnews.anvil.codegen.initializer.inject.wiring.AppInitializersScope
import ru.pixnews.foundation.coroutines.IoCoroutineDispatcherProvider
import ru.pixnews.foundation.coroutines.RootCoroutineScope
import ru.pixnews.foundation.di.base.DaggerSet
import ru.pixnews.foundation.initializers.AppInitializer
import ru.pixnews.foundation.initializers.AsyncInitializer
import ru.pixnews.foundation.initializers.Initializer
import ru.pixnews.foundation.initializers.inject.AppInitializersScope

@ContributesTo(AppInitializersScope::class)
@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package ru.pixnews.inject.ui
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import ru.pixnews.foundation.di.ui.base.activity.ActivityScope
import ru.pixnews.anvil.codegen.activity.inject.wiring.ActivityScope
import ru.pixnews.foundation.featuretoggles.FeatureManager
import ru.pixnews.foundation.featuretoggles.FeatureToggle
import ru.pixnews.foundation.featuretoggles.getFeatureToggle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.runningFold
import kotlinx.coroutines.flow.stateIn
import kotlinx.datetime.TimeZone
import ru.pixnews.anvil.codegen.viewmodel.inject.ContributesViewModel
import ru.pixnews.feature.calendar.converter.UpcomingGameListConverter.toCalendarListItem
import ru.pixnews.feature.calendar.data.domain.upcoming.ObserveUpcomingReleasesByDateUseCase
import ru.pixnews.feature.calendar.data.domain.upcoming.UpcomingRelease
Expand All @@ -28,7 +29,6 @@ import ru.pixnews.feature.calendar.model.CalendarListItem
import ru.pixnews.feature.calendar.model.CalendarScreenState
import ru.pixnews.feature.calendar.model.CalendarScreenStateLoaded
import ru.pixnews.feature.calendar.model.InitialLoad
import ru.pixnews.foundation.di.ui.base.viewmodel.ContributesViewModel
import ru.pixnews.foundation.featuretoggles.FeatureManager

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ package ru.pixnews.feature.featuretoggles

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import co.touchlab.kermit.Logger
import ru.pixnews.anvil.codegen.activity.inject.ContributesActivity
import ru.pixnews.di.root.component.PixnewsRootComponentHolder
import ru.pixnews.feature.featuretoggles.ui.FeatureToggleListScreen
import ru.pixnews.foundation.appconfig.AppConfig
import ru.pixnews.foundation.di.ui.base.activity.BaseActivity
import ru.pixnews.foundation.di.ui.base.activity.ContributesActivity
import ru.pixnews.foundation.di.ui.base.viewmodel.injectedViewModel
import ru.pixnews.foundation.ui.theme.PixnewsTheme
import javax.inject.Inject

@ContributesActivity
public class FeatureToggleListActivity : BaseActivity() {
private val viewModel by injectedViewModel<FeatureToggleListViewModel>()
private val viewModel: FeatureToggleListViewModel by viewModels<FeatureToggleListViewModel>(
null,
PixnewsRootComponentHolder.appComponent::viewModelFactory,
)

@Inject
internal lateinit var appConfig: AppConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import ru.pixnews.anvil.codegen.viewmodel.inject.ContributesViewModel
import ru.pixnews.feature.featuretoggles.model.FeatureTogglesScreenState
import ru.pixnews.feature.featuretoggles.model.PermanentErrorMessage
import ru.pixnews.feature.featuretoggles.model.VariantUiModel
import ru.pixnews.feature.featuretoggles.model.toExperimentVariant
import ru.pixnews.feature.featuretoggles.model.toUiModel
import ru.pixnews.foundation.di.ui.base.viewmodel.ContributesViewModel
import ru.pixnews.foundation.featuretoggles.Experiment
import ru.pixnews.foundation.featuretoggles.ExperimentKey
import ru.pixnews.foundation.featuretoggles.ExperimentVariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import com.squareup.anvil.annotations.ContributesTo
import com.squareup.anvil.annotations.optional.SingleIn
import dagger.Module
import dagger.Provides
import ru.pixnews.anvil.codegen.viewmodel.inject.wiring.ViewModelScope
import ru.pixnews.foundation.coroutines.IoCoroutineDispatcherProvider
import ru.pixnews.foundation.coroutines.RootCoroutineScope
import ru.pixnews.foundation.di.base.DaggerMap
import ru.pixnews.foundation.di.base.qualifiers.ApplicationContext
import ru.pixnews.foundation.di.ui.base.viewmodel.ViewModelScope
import ru.pixnews.foundation.featuretoggles.ExperimentKey
import ru.pixnews.foundation.featuretoggles.ExperimentVariantSerializer
import ru.pixnews.foundation.featuretoggles.datasource.overrides.OverridesDataSource
Expand Down

This file was deleted.

Loading

0 comments on commit 6d32b4f

Please sign in to comment.