-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcos Holgado
committed
Dec 15, 2018
1 parent
34efd06
commit 9ec7be8
Showing
29 changed files
with
385 additions
and
38 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.marcosholgado | ||
|
||
import android.app.Application | ||
import com.marcosholgado.core.di.CoreComponentProvider | ||
import com.marcosholgado.daggerplayground.di.CoreComponent | ||
import com.marcosholgado.daggerplayground.di.DaggerCoreComponent | ||
|
||
class MyApplication : Application(), CoreComponentProvider { | ||
|
||
private lateinit var coreComponent: CoreComponent | ||
|
||
override fun provideCoreComponent(): CoreComponent { | ||
if (!this::coreComponent.isInitialized) { | ||
coreComponent = DaggerCoreComponent | ||
.builder() | ||
.build() | ||
} | ||
return coreComponent | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/marcosholgado/daggerplayground/ExpensiveObject.kt
This file was deleted.
Oops, something went wrong.
18 changes: 12 additions & 6 deletions
18
app/src/main/java/com/marcosholgado/daggerplayground/MainActivity.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,26 +1,32 @@ | ||
package com.marcosholgado.daggerplayground | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.marcosholgado.daggerplayground.di.DaggerMainComponent | ||
import com.marcosholgado.daggerplayground.di.MyModule | ||
import dagger.Lazy | ||
import com.marcosholgado.core.ExpensiveObject | ||
import com.marcosholgado.core.di.CoreInjectHelper | ||
import com.marcosholgado.daggerplayground.di.DaggerFeature2Component | ||
import com.marcosholgado.mymodule.OtherActivity | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import javax.inject.Inject | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
@Inject | ||
lateinit var expensiveObject: Lazy<ExpensiveObject> | ||
lateinit var expensiveObject: ExpensiveObject | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
DaggerMainComponent.builder().myModule(MyModule()).build().inject(this) | ||
DaggerFeature2Component | ||
.builder() | ||
.coreComponent(CoreInjectHelper.provideCoreComponent(applicationContext)) | ||
.build() | ||
.inject(this) | ||
|
||
button.setOnClickListener { | ||
textView.text = "Size is ${expensiveObject.get().intArray?.size}" | ||
startActivity(Intent(this, OtherActivity::class.java)) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/marcosholgado/daggerplayground/di/Feature2Component.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,11 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import com.marcosholgado.core.di.FeatureScope | ||
import com.marcosholgado.daggerplayground.MainActivity | ||
import dagger.Component | ||
|
||
@Component(modules = [Feature2Module::class], dependencies = [CoreComponent::class]) | ||
@FeatureScope | ||
interface Feature2Component { | ||
fun inject(mainActivity: MainActivity) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/marcosholgado/daggerplayground/di/Feature2Module.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,10 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
class Feature2Module { | ||
@Provides | ||
fun provideInt() = 1 | ||
} |
9 changes: 0 additions & 9 deletions
9
app/src/main/java/com/marcosholgado/daggerplayground/di/MainComponent.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,72 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
|
||
implementation 'androidx.appcompat:appcompat:1.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
implementation 'androidx.core:core-ktx:1.0.0' | ||
|
||
// Dagger | ||
implementation "com.google.dagger:dagger:2.19" | ||
implementation "com.google.dagger:dagger-android:2.19" | ||
implementation "com.google.dagger:dagger-android-support:2.19" | ||
|
||
kapt "com.google.dagger:dagger-compiler:2.19" | ||
kapt "com.google.dagger:dagger-android-processor:2.19" | ||
|
||
testImplementation 'junit:junit:4.12' | ||
|
||
// Core library | ||
androidTestImplementation 'androidx.test:core:1.0.0' | ||
androidTestUtil 'androidx.test:orchestrator:1.1.0' | ||
|
||
// AndroidJUnitRunner and JUnit Rules | ||
androidTestImplementation 'androidx.test:runner:1.1.0' | ||
androidTestImplementation 'androidx.test:rules:1.1.0' | ||
|
||
// Assertions | ||
androidTestImplementation 'androidx.test.ext:junit:1.0.0' | ||
androidTestImplementation 'androidx.test.ext:truth:1.0.0' | ||
androidTestImplementation 'com.google.truth:truth:0.42' | ||
|
||
// Espresso dependencies | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0' | ||
androidTestImplementation 'androidx.test.janktesthelper:janktesthelper:1.0.1' | ||
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' | ||
|
||
androidTestImplementation 'io.reactivex.rxjava2:rxandroid:2.0.2' | ||
androidTestImplementation 'io.reactivex.rxjava2:rxjava:2.1.10' | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.marcosholgado.core" /> |
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,3 @@ | ||
package com.marcosholgado.core | ||
|
||
class ExpensiveObject |
11 changes: 11 additions & 0 deletions
11
core/src/main/java/com/marcosholgado/core/di/CoreComponent.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,11 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import com.marcosholgado.core.ExpensiveObject | ||
import dagger.Component | ||
import javax.inject.Singleton | ||
|
||
@Component(modules = [CoreModule::class]) | ||
@Singleton | ||
interface CoreComponent { | ||
fun getExpensiveObject(): ExpensiveObject | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/com/marcosholgado/core/di/CoreComponentProvider.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,7 @@ | ||
package com.marcosholgado.core.di | ||
|
||
import com.marcosholgado.daggerplayground.di.CoreComponent | ||
|
||
interface CoreComponentProvider { | ||
fun provideCoreComponent(): CoreComponent | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/java/com/marcosholgado/core/di/CoreInjectHelper.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,14 @@ | ||
package com.marcosholgado.core.di | ||
|
||
import android.content.Context | ||
import com.marcosholgado.daggerplayground.di.CoreComponent | ||
|
||
object CoreInjectHelper { | ||
fun provideCoreComponent(applicationContext: Context): CoreComponent { | ||
return if (applicationContext is CoreComponentProvider) { | ||
(applicationContext as CoreComponentProvider).provideCoreComponent() | ||
} else { | ||
throw IllegalStateException("The application context you have passed does not implement CoreComponentProvider") | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...osholgado/daggerplayground/di/MyModule.kt → ...a/com/marcosholgado/core/di/CoreModule.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,13 +1,13 @@ | ||
package com.marcosholgado.daggerplayground.di | ||
|
||
import com.marcosholgado.daggerplayground.ExpensiveObject | ||
import com.marcosholgado.core.ExpensiveObject | ||
import dagger.Module | ||
import dagger.Provides | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
class MyModule { | ||
|
||
class CoreModule { | ||
@Provides | ||
@Singleton | ||
fun provideExpensiveObject(): ExpensiveObject = ExpensiveObject() | ||
|
||
} |
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,7 @@ | ||
package com.marcosholgado.core.di | ||
|
||
import javax.inject.Scope | ||
|
||
@Scope | ||
@Retention | ||
annotation class FeatureScope |
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,3 @@ | ||
<resources> | ||
<string name="app_name">core</string> | ||
</resources> |
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 @@ | ||
/build |
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,73 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation project(path: ':core') | ||
|
||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
|
||
implementation 'androidx.appcompat:appcompat:1.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
implementation 'androidx.core:core-ktx:1.0.0' | ||
|
||
// Dagger | ||
implementation "com.google.dagger:dagger:2.19" | ||
implementation "com.google.dagger:dagger-android:2.19" | ||
implementation "com.google.dagger:dagger-android-support:2.19" | ||
|
||
kapt "com.google.dagger:dagger-compiler:2.19" | ||
kapt "com.google.dagger:dagger-android-processor:2.19" | ||
|
||
testImplementation 'junit:junit:4.12' | ||
|
||
// Core library | ||
androidTestImplementation 'androidx.test:core:1.0.0' | ||
androidTestUtil 'androidx.test:orchestrator:1.1.0' | ||
|
||
// AndroidJUnitRunner and JUnit Rules | ||
androidTestImplementation 'androidx.test:runner:1.1.0' | ||
androidTestImplementation 'androidx.test:rules:1.1.0' | ||
|
||
// Assertions | ||
androidTestImplementation 'androidx.test.ext:junit:1.0.0' | ||
androidTestImplementation 'androidx.test.ext:truth:1.0.0' | ||
androidTestImplementation 'com.google.truth:truth:0.42' | ||
|
||
// Espresso dependencies | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0' | ||
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0' | ||
androidTestImplementation 'androidx.test.janktesthelper:janktesthelper:1.0.1' | ||
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' | ||
|
||
androidTestImplementation 'io.reactivex.rxjava2:rxandroid:2.0.2' | ||
androidTestImplementation 'io.reactivex.rxjava2:rxjava:2.1.10' | ||
} |
Oops, something went wrong.