-
Notifications
You must be signed in to change notification settings - Fork 174
Уф. Готово Dagger 2 #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KPAHAPK
wants to merge
1
commit into
Otus-Android:master
Choose a base branch
from
KPAHAPK:homework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Уф. Готово Dagger 2 #131
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,18 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.app.Application | ||
| import ru.otus.daggerhomework.di.ApplicationComponent | ||
| import ru.otus.daggerhomework.di.DaggerApplicationComponent | ||
|
|
||
|
|
||
| class App : Application() { | ||
|
|
||
| lateinit var appComponent: ApplicationComponent | ||
| private set | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
| appComponent = DaggerApplicationComponent.factory().create(this) | ||
| } | ||
|
|
||
| class App :Application() { | ||
| } |
4 changes: 0 additions & 4 deletions
4
app/src/main/java/ru/otus/daggerhomework/ApplicationComponent.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/ru/otus/daggerhomework/di/ApplicationComponent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import android.content.Context | ||
| import dagger.BindsInstance | ||
| import dagger.Component | ||
| import javax.inject.Qualifier | ||
| import javax.inject.Singleton | ||
|
|
||
|
|
||
| @Component | ||
| @Singleton | ||
| interface ApplicationComponent { | ||
|
|
||
| @ApplicationContext | ||
| fun provideContext(): Context | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create(@BindsInstance @ApplicationContext context: Context): ApplicationComponent | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/ru/otus/daggerhomework/di/FragmentProducerComponent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import dagger.Component | ||
| import ru.otus.daggerhomework.FragmentProducer | ||
|
|
||
| @Component(dependencies = [MainActivityComponent::class]) | ||
| @FragmentScope | ||
| interface FragmentProducerComponent { | ||
|
|
||
| fun inject(fragmentProducer: FragmentProducer) | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create(mainActivityComponent: MainActivityComponent): FragmentProducerComponent | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/otus/daggerhomework/di/FragmentProducerModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import dagger.Module | ||
|
|
||
| @Module | ||
| object FragmentProducerModule { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И этот |
||
| } | ||
18 changes: 18 additions & 0 deletions
18
app/src/main/java/ru/otus/daggerhomework/di/FragmentReceiverComponent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import dagger.Component | ||
| import ru.otus.daggerhomework.FragmentProducer | ||
| import ru.otus.daggerhomework.FragmentReceiver | ||
|
|
||
| @Component(dependencies = [MainActivityComponent::class]) | ||
| @FragmentScope | ||
| interface FragmentReceiverComponent { | ||
|
|
||
| fun inject(fragmentReceiver: FragmentReceiver) | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create(mainActivityComponent: MainActivityComponent): FragmentReceiverComponent | ||
| } | ||
|
|
||
| } |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/otus/daggerhomework/di/FragmentReceiverModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import dagger.Module | ||
|
|
||
| @Module | ||
| object FragmentReceiverModule { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А зачем этот модуль? |
||
| } | ||
28 changes: 28 additions & 0 deletions
28
app/src/main/java/ru/otus/daggerhomework/di/MainActivityComponent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package ru.otus.daggerhomework.di | ||
|
|
||
| import android.content.Context | ||
| import dagger.BindsInstance | ||
| import dagger.Component | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import ru.otus.daggerhomework.ColorGenerator | ||
| import ru.otus.daggerhomework.MainActivity | ||
|
|
||
| @Component(dependencies = [ApplicationComponent::class], modules = [MainModule::class]) | ||
| @ActivityScope | ||
| interface MainActivityComponent { | ||
| fun provideContext():Context | ||
|
|
||
| fun provideColorGenerator(): ColorGenerator | ||
|
|
||
| fun provideMutableStateFlow(): MutableStateFlow<Int> | ||
| fun provideStateFlow(): StateFlow<Int> | ||
|
|
||
| @ApplicationContext | ||
| fun provideApplicationContext(): Context | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create(@BindsInstance context: Context, applicationComponent: ApplicationComponent): MainActivityComponent | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь будет утечка контекста тк андродовская ViewModel живет дольше чем активити. Убери суперкласс