├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ └── layout │ │ │ │ ├── menu_joke.xml │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── ir │ │ │ │ └── coursio │ │ │ │ └── daggertutorial │ │ │ │ ├── scopes │ │ │ │ ├── MainActivityScope.java │ │ │ │ └── DaggerTutorialApplicationScope.java │ │ │ │ ├── qualifier │ │ │ │ ├── ApiServiceQualifier.java │ │ │ │ └── RetrofitQualifier.java │ │ │ │ ├── api │ │ │ │ └── ApiService.java │ │ │ │ ├── MainActivityComponent.java │ │ │ │ ├── modules │ │ │ │ ├── ContextModule.java │ │ │ │ ├── MainActivityModule.java │ │ │ │ ├── PicassoModule.java │ │ │ │ ├── NetworkModule.java │ │ │ │ └── ApiServiceModule.java │ │ │ │ ├── model │ │ │ │ ├── Responses │ │ │ │ │ └── JokeListResponse.java │ │ │ │ └── Subs │ │ │ │ │ └── JokeStruct.java │ │ │ │ ├── DaggerTutorialApplicationComponent.java │ │ │ │ ├── DaggerTutorialApplication.java │ │ │ │ ├── BaseActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── view │ │ │ │ └── JokeAdapter.java │ │ │ │ └── handler │ │ │ │ └── PermissionHandler.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── ir │ │ │ └── coursio │ │ │ └── daggertutorial │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── ir │ │ └── coursio │ │ └── daggertutorial │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── Taher.xml ├── encodings.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/Taher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DaggerTutorial 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TaherHaghverdi/DaggerTutorial/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #424242 4 | #424242 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 20 11:34:17 IRDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/scopes/MainActivityScope.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.scopes; 2 | 3 | import javax.inject.Scope; 4 | 5 | /** 6 | * Created by Taher on 22/04/2017. 7 | * Project: DaggerTutorial 8 | */ 9 | 10 | @Scope 11 | public @interface MainActivityScope { 12 | } 13 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/qualifier/ApiServiceQualifier.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.qualifier; 2 | 3 | import javax.inject.Qualifier; 4 | 5 | /** 6 | * Created by Taher on 21/04/2017. 7 | * Project: DaggerTutorial 8 | */ 9 | @Qualifier 10 | public @interface ApiServiceQualifier { 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/qualifier/RetrofitQualifier.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.qualifier; 2 | 3 | import javax.inject.Qualifier; 4 | 5 | /** 6 | * Created by Taher on 21/04/2017. 7 | * Project: DaggerTutorial 8 | */ 9 | 10 | @Qualifier 11 | public @interface RetrofitQualifier { 12 | } 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/api/ApiService.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.api; 2 | 3 | import ir.coursio.daggertutorial.model.Responses.JokeListResponse; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | 7 | /** 8 | * Created by Taher on 2/5/2017. 9 | * Project: MyApplication 10 | */ 11 | 12 | 13 | public interface ApiService { 14 | 15 | @GET("jokes") 16 | Call getJokes(); 17 | } -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/scopes/DaggerTutorialApplicationScope.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.scopes; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | import javax.inject.Scope; 7 | 8 | /** 9 | * Created by Taher on 21/04/2017. 10 | * Project: DaggerTutorial 11 | */ 12 | 13 | @Scope 14 | @Retention(RetentionPolicy.CLASS) 15 | public @interface DaggerTutorialApplicationScope { 16 | } 17 | -------------------------------------------------------------------------------- /app/src/test/java/ir/coursio/daggertutorial/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/MainActivityComponent.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial; 2 | 3 | 4 | import dagger.Component; 5 | import ir.coursio.daggertutorial.modules.MainActivityModule; 6 | import ir.coursio.daggertutorial.scopes.MainActivityScope; 7 | 8 | /** 9 | * Created by Taher on 22/04/2017. 10 | * Project: DaggerTutorial 11 | */ 12 | 13 | @Component(modules = MainActivityModule.class, dependencies = DaggerTutorialApplicationComponent.class) 14 | @MainActivityScope 15 | public interface MainActivityComponent { 16 | void injectMainActivity(MainActivity mainActivity); 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DaggerTutorial 2 | 3 | This is a tutorial project following series of tutorials on Dagger 2. you can find tutorials [here](http://coursio.ir/tag/dagger-2). 4 | 5 | 6 | ## Installation 7 | 8 | You can clone the project into android studio and check it out. 9 | 10 | ## Contributing 11 | If you have sth to add feel free to contribute. To do that you just need: 12 | 13 | 1. Fork it! 14 | 2. Create your feature branch: `git checkout -b my-new-feature` 15 | 3. Commit your changes: `git commit -am 'Add some feature'` 16 | 4. Push to the branch: `git push origin my-new-feature` 17 | 5. Submit a pull request :D 18 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/modules/ContextModule.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.modules; 2 | 3 | import android.content.Context; 4 | 5 | import dagger.Module; 6 | import dagger.Provides; 7 | import ir.coursio.daggertutorial.scopes.DaggerTutorialApplicationScope; 8 | 9 | /** 10 | * Created by Taher on 21/04/2017. 11 | * Project: DaggerTutorial 12 | */ 13 | 14 | @Module 15 | public class ContextModule { 16 | 17 | private final Context context; 18 | 19 | public ContextModule(Context context) { 20 | this.context = context; 21 | } 22 | 23 | @Provides 24 | @DaggerTutorialApplicationScope 25 | public Context context() { 26 | return context; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/modules/MainActivityModule.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.modules; 2 | 3 | 4 | import dagger.Module; 5 | import dagger.Provides; 6 | import ir.coursio.daggertutorial.MainActivity; 7 | import ir.coursio.daggertutorial.scopes.MainActivityScope; 8 | 9 | /** 10 | * Created by Taher on 22/04/2017. 11 | * Project: DaggerTutorial 12 | */ 13 | 14 | @Module 15 | public class MainActivityModule { 16 | private final MainActivity mainActivity; 17 | 18 | public MainActivityModule(MainActivity mainActivity) { 19 | this.mainActivity = mainActivity; 20 | } 21 | 22 | @Provides 23 | @MainActivityScope 24 | public MainActivity mainActivity(){ 25 | return mainActivity; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/model/Responses/JokeListResponse.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.model.Responses; 2 | 3 | 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | 7 | import java.io.Serializable; 8 | import java.util.ArrayList; 9 | 10 | import ir.coursio.daggertutorial.model.Subs.JokeStruct; 11 | 12 | 13 | /** 14 | * Created by Taher on 11/04/2017. 15 | * Project: ReactiveRetrofitTutorial 16 | */ 17 | 18 | public class JokeListResponse implements Serializable { 19 | 20 | @SerializedName("type") 21 | private String type; 22 | 23 | @SerializedName("value") 24 | private ArrayList jokes; 25 | 26 | public String getType() { 27 | return type; 28 | } 29 | 30 | public ArrayList getJokes() { 31 | return jokes; 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/model/Subs/JokeStruct.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.model.Subs; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.io.Serializable; 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Created by Taher on 16/03/2017. 10 | * Project: RetrofitTutorial 11 | */ 12 | 13 | public class JokeStruct implements Serializable { 14 | @SerializedName("id") 15 | private int id; 16 | 17 | @SerializedName("joke") 18 | private String text; 19 | 20 | @SerializedName("categories") 21 | private ArrayList categories = new ArrayList<>(); 22 | 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public String getText() { 29 | return text; 30 | } 31 | 32 | public ArrayList getCategories() { 33 | return categories; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/DaggerTutorialApplicationComponent.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial; 2 | 3 | import com.squareup.picasso.Picasso; 4 | 5 | import dagger.Component; 6 | import ir.coursio.daggertutorial.api.ApiService; 7 | import ir.coursio.daggertutorial.modules.ApiServiceModule; 8 | import ir.coursio.daggertutorial.modules.PicassoModule; 9 | import ir.coursio.daggertutorial.qualifier.ApiServiceQualifier; 10 | import ir.coursio.daggertutorial.scopes.DaggerTutorialApplicationScope; 11 | 12 | /** 13 | * Created by Taher on 21/04/2017. 14 | * Project: DaggerTutorial 15 | */ 16 | 17 | @DaggerTutorialApplicationScope 18 | @Component(modules = {ApiServiceModule.class, PicassoModule.class}) 19 | public interface DaggerTutorialApplicationComponent { 20 | 21 | Picasso getPicasso(); 22 | 23 | @ApiServiceQualifier 24 | ApiService getApiService(); 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/ir/coursio/daggertutorial/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("ir.coursio.daggertutorial", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Taher\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/menu_joke.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 15 | 16 | 20 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/ir/coursio/daggertutorial/modules/PicassoModule.java: -------------------------------------------------------------------------------- 1 | package ir.coursio.daggertutorial.modules; 2 | 3 | import android.content.Context; 4 | 5 | import com.jakewharton.picasso.OkHttp3Downloader; 6 | import com.squareup.picasso.Picasso; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | import ir.coursio.daggertutorial.scopes.DaggerTutorialApplicationScope; 11 | import okhttp3.OkHttpClient; 12 | 13 | /** 14 | * Created by Taher on 21/04/2017. 15 | * Project: DaggerTutorial 16 | */ 17 | 18 | @Module(includes = {ContextModule.class, NetworkModule.class}) 19 | public class PicassoModule { 20 | 21 | @Provides 22 | @DaggerTutorialApplicationScope 23 | public Picasso picasso(Context context, OkHttp3Downloader downloader) { 24 | return new Picasso.Builder(context) 25 | .downloader(downloader) 26 | .build(); 27 | } 28 | 29 | @Provides 30 | @DaggerTutorialApplicationScope 31 | public OkHttp3Downloader downloader(OkHttpClient client) { 32 | return new OkHttp3Downloader(client); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |