-
Notifications
You must be signed in to change notification settings - Fork 174
[ДЗ | Dagger 2] - Егор Шкляревский #151
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
jeghor
wants to merge
2
commits into
Otus-Android:master
Choose a base branch
from
jeghor: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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/ru/otus/daggerhomework/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 |
|---|---|---|
| @@ -1,4 +1,17 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.app.Application | ||
| import dagger.BindsInstance | ||
| import dagger.Component | ||
|
|
||
| @Component | ||
| interface ApplicationComponent { | ||
|
|
||
| fun provideApplication(): Application | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
|
|
||
| fun create(@BindsInstance application: Application): ApplicationComponent | ||
| } | ||
| } |
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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/ru/otus/daggerhomework/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,23 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.content.Context | ||
| import dagger.* | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
|
|
||
| @Component( | ||
| modules = [ViewModelProducerModule::class], | ||
| dependencies = [ApplicationComponent::class, MainActivityComponent::class] | ||
| ) | ||
| interface FragmentProducerComponent { | ||
|
|
||
| fun inject(fragmentProducer: FragmentProducer) | ||
| } | ||
|
|
||
| @Module | ||
| object ViewModelProducerModule { | ||
|
|
||
| @Provides | ||
| fun provide(colorGenerator: ColorGenerator, context: Context, flow: MutableStateFlow<Int>): ViewModelProducer { | ||
| return ViewModelProducer(colorGenerator, context, flow) | ||
| } | ||
| } |
27 changes: 22 additions & 5 deletions
27
app/src/main/java/ru/otus/daggerhomework/FragmentReceiver.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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/ru/otus/daggerhomework/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,23 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.app.Application | ||
| import dagger.* | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
|
|
||
| @Component( | ||
| modules = [ViewModelReceiverModule::class], | ||
| dependencies = [ApplicationComponent::class, MainActivityComponent::class] | ||
| ) | ||
| interface FragmentReceiverComponent { | ||
|
|
||
| fun inject(fragmentReceiver: FragmentReceiver) | ||
| } | ||
|
|
||
| @Module | ||
| object ViewModelReceiverModule { | ||
|
|
||
| @Provides | ||
| fun provide(context: Application, flow: MutableStateFlow<Int>): ViewModelReceiver { | ||
| return ViewModelReceiver(context, flow) | ||
| } | ||
| } | ||
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
41 changes: 41 additions & 0 deletions
41
app/src/main/java/ru/otus/daggerhomework/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,41 @@ | ||
| package ru.otus.daggerhomework | ||
|
|
||
| import android.content.Context | ||
| import dagger.* | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
|
|
||
| @Component(modules = [ColorGeneratorModule::class, StateFlowModule::class]) | ||
| interface MainActivityComponent { | ||
|
|
||
| fun provideContext(): Context | ||
|
|
||
| fun provideFlow(): StateFlow<Int> | ||
|
|
||
| fun provideMutableFlow(): MutableStateFlow<Int> | ||
|
|
||
| fun provideColorGenerator(): ColorGenerator | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
|
|
||
| fun create( | ||
| @BindsInstance context: Context, | ||
| @BindsInstance flow: MutableStateFlow<Int> | ||
| ): MainActivityComponent | ||
| } | ||
| } | ||
|
|
||
| @Module | ||
| interface ColorGeneratorModule { | ||
|
|
||
| @Binds | ||
| fun bindColorGenerator(colorGeneratorImpl: ColorGeneratorImpl): ColorGenerator | ||
| } | ||
|
|
||
| @Module | ||
| interface StateFlowModule { | ||
|
|
||
| @Binds | ||
| fun bindStateFlow(mutableStateFlow: MutableStateFlow<Int>): StateFlow<Int> | ||
| } |
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,19 +1,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.constraintlayout.widget.ConstraintLayout | ||
| android:id="@+id/container" | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <TextView | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:text="Hello World!" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintLeft_toLeftOf="parent" | ||
| app:layout_constraintRight_toRightOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" /> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
| tools:context=".MainActivity" /> |
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.
Тоже можно поменять на binds
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.
Немного не понимаю как, я же тут из параметров создаю вьюмодель. По мне биндс не подходит
Можете по подробнее описать?