-
Notifications
You must be signed in to change notification settings - Fork 0
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
Modules with dagger 2 #8
Open
dmersiyanov
wants to merge
5
commits into
dev
Choose a base branch
from
modules_with_dagger_2
base: dev
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
5 commits
Select commit
Hold shift + click to select a range
2a230b2
added empty onboarding feature module
d066be8
added empty core module
23c488b
moved sharing code to core module
9c830d3
moved onboarding feature layouts to module
0fdf9f8
added feature module, setup dagger for multi-modules
dmersiyanov 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 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 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 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
38 changes: 28 additions & 10 deletions
38
app/src/main/java/com/dmity/androidacademy/di/AppComponent.kt
This file contains 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,21 +1,39 @@ | ||
package com.dmity.androidacademy.di | ||
|
||
import com.dmity.androidacademy.features.onboarding.OnBoardingActivity | ||
import com.dmity.androidacademy.features.onboarding.OnBoardingViewModel | ||
import com.dmity.androidacademy.features.onboarding.di.OnBoardingModule | ||
import android.app.Application | ||
import android.content.Context | ||
import com.dmity.androidacademy.core.di.AppProvider | ||
|
||
import dagger.BindsInstance | ||
import dagger.Component | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
@Component( | ||
modules = [ | ||
ContextModule::class, | ||
OnBoardingModule::class, | ||
ViewModelModule::class] | ||
modules = [AppModule::class] | ||
) | ||
interface AppComponent { | ||
interface AppComponent : AppProvider { | ||
|
||
companion object { | ||
|
||
private var appComponent: AppProvider? = null | ||
|
||
fun create(application: Application): AppProvider { | ||
return appComponent ?: DaggerAppComponent | ||
.builder() | ||
.application(application.applicationContext) | ||
.build().also { | ||
appComponent = it | ||
} | ||
} | ||
} | ||
|
||
@Component.Builder | ||
interface Builder { | ||
|
||
fun inject(onBoardingViewModel: OnBoardingViewModel) | ||
fun inject(onBoardingActivity: OnBoardingActivity) | ||
@BindsInstance | ||
fun application(context: Context): Builder | ||
|
||
fun build(): AppComponent | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/dmity/androidacademy/di/AppModule.kt
This file contains 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,20 @@ | ||
package com.dmity.androidacademy.di | ||
|
||
import dagger.Module | ||
|
||
@Module | ||
abstract class AppModule { | ||
|
||
@Module | ||
companion object { | ||
|
||
// Пока не используется | ||
// private const val PREFS_NAME = "HABITS_SP" | ||
// | ||
// @JvmStatic | ||
// @Provides | ||
// @Singleton | ||
// fun provideSharedPreferences(context: Context): SharedPreferences = | ||
// context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
app/src/main/java/com/dmity/androidacademy/di/ContextModule.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/dmity/androidacademy/di/FacadeComponent.kt
This file contains 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 com.dmity.androidacademy.di | ||
|
||
import android.app.Application | ||
import com.dmity.androidacademy.NewsApp | ||
import com.dmity.androidacademy.core.di.AppProvider | ||
import com.dmity.androidacademy.core.di.ProvidersFacade | ||
import dagger.Component | ||
|
||
@Component( | ||
dependencies = [AppProvider::class] | ||
) | ||
interface FacadeComponent : ProvidersFacade { | ||
|
||
companion object { | ||
|
||
fun init(application: Application): FacadeComponent = | ||
DaggerFacadeComponent.builder() | ||
.appProvider(AppComponent.create(application)) | ||
.build() | ||
} | ||
|
||
fun inject(app: NewsApp) | ||
} |
14 changes: 0 additions & 14 deletions
14
app/src/main/java/com/dmity/androidacademy/di/ViewModelModule.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
app/src/main/java/com/dmity/androidacademy/di/utils/ViewModelFactory.kt
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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
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.
Закоменченный код лучше не добавлять в гит, это засоряет историю. Нужно либо выпилить сейчас, либо оставить провайдинг.