-
Notifications
You must be signed in to change notification settings - Fork 174
Было сложно, но я сделал #71
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
NSabirov
wants to merge
2
commits into
Otus-Android:master
Choose a base branch
from
NSabirov:master
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,27 @@ | ||
| ### Реализуйте ApplicationComponent | ||
| Это корень нашего дерева компонентов. Инициализируется в классе App, прокидывает в граф через Component Dependencies/Subcomponents ниже по графу следующие сущности: | ||
| - Context(Application) до FragmentProducerComponent и FragmentReceiverComponent. | ||
| Проброс Context в граф реализуйте через BindsInstance + ComponentFactory | ||
|
|
||
| Это корень нашего дерева компонентов. Инициализируется в классе App, прокидывает в граф через | ||
| Component Dependencies/Subcomponents ниже по графу следующие сущности: | ||
|
|
||
| - Context(Application) до FragmentProducerComponent и FragmentReceiverComponent. | ||
| Проброс Context в граф реализуйте через BindsInstance + ComponentFactory | ||
|
|
||
| ### Реализуйте MainActivityComponent | ||
|
|
||
| Инициализируется в MainActivity. Прокидывает следующие сущности: | ||
|
|
||
| - Context(Activity). Проброс в граф реализуйте через BindsInstance + ComponentFactory | ||
| - Ваша реализация обсервера(Coroutine Channel/StateFlow/Subject либо другую реализацию обсервера). Он понадобится нам чтобы отправлять евенты из одного фрагмента и принимать их в другом, в обоих фрагментах должен быть один и тот же инстанс обсервера. | ||
| - Ваша реализация обсервера(Coroutine Channel/StateFlow/Subject либо другую реализацию обсервера). | ||
| Он понадобится нам чтобы отправлять евенты из одного фрагмента и принимать их в другом, в обоих | ||
| фрагментах должен быть один и тот же инстанс обсервера. | ||
|
|
||
| ### Реализуйте FragmentReceiverComponent/FragmentProducerComponent | ||
| Коммуникацию между Producer и Receiver осуществите через канал/StateFlow/Subject либо другую реализацию обсервера которая уже есть в графе. ViewModelProducer должна отправлять эвенты, ViewModelReceiver должна получать эвенты. Обсерверы должны прокидываться в конструкторы вьюмоделей и существовать в единственном экземпляре в Activity. | ||
|
|
||
| Коммуникацию между Producer и Receiver осуществите через канал/StateFlow/Subject либо другую | ||
| реализацию обсервера которая уже есть в графе. ViewModelProducer должна отправлять эвенты, | ||
| ViewModelReceiver должна получать эвенты. Обсерверы должны прокидываться в конструкторы вьюмоделей и | ||
| существовать в единственном экземпляре в Activity. | ||
| Флоу отправки эвента выглядит следующим образом: | ||
| Клик на кнопку button в FragmentProducer -> вызов метода вьюмодели -> проброс евента в обсервер -> евент ловится на стороне ViewModelReceiver -> евент передается FragmentReceiver и вызывается функция ru.otus.daggerhomework.FragmentReceiver#populateColor | ||
| Клик на кнопку button в FragmentProducer -> вызов метода вьюмодели -> проброс евента в обсервер -> | ||
| евент ловится на стороне ViewModelReceiver -> евент передается FragmentReceiver и вызывается функция | ||
| ru.otus.daggerhomework.FragmentReceiver#populateColor |
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,15 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.app.Application | ||
| import ru.otus.daggerhomework.components.ApplicationComponent | ||
| import ru.otus.daggerhomework.components.DaggerApplicationComponent | ||
|
|
||
| class App :Application() { | ||
|
|
||
| lateinit var appComponent: ApplicationComponent | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
| appComponent = DaggerApplicationComponent.factory().create(this) | ||
| } | ||
| } |
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
26 changes: 0 additions & 26 deletions
26
app/src/main/java/ru/otus/daggerhomework/FragmentProducer.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
app/src/main/java/ru/otus/daggerhomework/FragmentReceiver.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
16 changes: 0 additions & 16 deletions
16
app/src/main/java/ru/otus/daggerhomework/ViewModelProducer.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
app/src/main/java/ru/otus/daggerhomework/ViewModelReceiver.kt
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
app/src/main/java/ru/otus/daggerhomework/components/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,49 @@ | ||
| package ru.otus.daggerhomework.components | ||
|
|
||
| import android.content.Context | ||
| import dagger.BindsInstance | ||
| import dagger.Component | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import javax.inject.Named | ||
| import javax.inject.Singleton | ||
|
|
||
| //@Component(modules = [DataModule::class]) | ||
| @Component | ||
| @Singleton | ||
| interface ApplicationComponent { | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create( | ||
| @BindsInstance | ||
| @Named("ApplicationContext") | ||
| appContext: Context | ||
| //dataModule: DataModule, | ||
| ): ApplicationComponent | ||
| } | ||
|
|
||
| @Named("ApplicationContext") | ||
| fun provideContext(): Context | ||
| /*fun provideColorFlow(): MutableSharedFlow<Int> | ||
| fun provideStateFlow(): MutableStateFlow<State>*/ | ||
| } | ||
|
|
||
|
|
||
| /*@Module | ||
| @Named("DataModule") | ||
| class DataModule { | ||
|
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. Подключи его в активитикомпонент |
||
| private val colorFlow = MutableSharedFlow<Int>(replay = 1) | ||
|
|
||
| private val stateFlow = MutableStateFlow<State>(Empty) | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideColorFlow(): MutableSharedFlow<Int> = colorFlow | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideStateFlow(): MutableStateFlow<State> = stateFlow | ||
| }*/ | ||
28 changes: 28 additions & 0 deletions
28
app/src/main/java/ru/otus/daggerhomework/components/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,28 @@ | ||
| package ru.otus.daggerhomework.components | ||
|
|
||
| import dagger.Binds | ||
| import dagger.BindsInstance | ||
| import dagger.Module | ||
| import dagger.Subcomponent | ||
| import ru.otus.daggerhomework.ColorGenerator | ||
| import ru.otus.daggerhomework.ColorGeneratorImpl | ||
| import ru.otus.daggerhomework.producer.FragmentProducer | ||
| import ru.otus.daggerhomework.producer.ViewModelFactory | ||
| import javax.inject.Singleton | ||
|
|
||
| @Subcomponent(modules = [ColorModule::class]) | ||
| interface FragmentProducerComponent { | ||
| fun inject(fragmentProducer: FragmentProducer) | ||
| fun provideViewModelFactory(): ViewModelFactory | ||
|
|
||
| @Subcomponent.Factory | ||
| interface Factory{ | ||
| fun create(): FragmentProducerComponent | ||
| } | ||
| } | ||
|
|
||
| @Module | ||
| interface ColorModule{ | ||
| @Binds | ||
| fun bindColorGenerator(cgImpl: ColorGeneratorImpl): ColorGenerator | ||
| } |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/ru/otus/daggerhomework/components/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.components | ||
|
|
||
| import dagger.BindsInstance | ||
| import dagger.Subcomponent | ||
| import ru.otus.daggerhomework.receiver.FragmentReceiver | ||
| import ru.otus.daggerhomework.receiver.ViewModelFactory | ||
| import javax.inject.Singleton | ||
|
|
||
| @Subcomponent | ||
| interface FragmentReceiverComponent { | ||
| fun inject(fragmentReceiver: FragmentReceiver) | ||
| fun provideViewModelFactory(): ViewModelFactory | ||
|
|
||
| @Subcomponent.Factory | ||
| interface Factory{ | ||
| fun create(): FragmentReceiverComponent | ||
| } | ||
| } |
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.
А это зачем?)