├── 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 |
4 |
5 |
6 |
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 |
4 |
5 |
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 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
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 |
24 |
25 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/DaggerTutorialApplication.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 |
6 | import com.jakewharton.picasso.OkHttp3Downloader;
7 | import com.squareup.picasso.Picasso;
8 |
9 |
10 | import java.io.File;
11 |
12 | import ir.coursio.daggertutorial.api.ApiService;
13 | import ir.coursio.daggertutorial.modules.ApiServiceModule;
14 | import ir.coursio.daggertutorial.modules.ContextModule;
15 | import ir.coursio.daggertutorial.modules.NetworkModule;
16 | import ir.coursio.daggertutorial.modules.PicassoModule;
17 | import okhttp3.Cache;
18 | import okhttp3.OkHttpClient;
19 | import okhttp3.logging.HttpLoggingInterceptor;
20 | import retrofit2.Retrofit;
21 | import retrofit2.converter.gson.GsonConverterFactory;
22 | import timber.log.Timber;
23 |
24 | /**
25 | * Created by Taher on 21/04/2017.
26 | * Project: DaggerTutorial
27 | */
28 |
29 | public class DaggerTutorialApplication extends Application {
30 | DaggerTutorialApplicationComponent component;
31 |
32 | @Override
33 | public void onCreate() {
34 | super.onCreate();
35 | Timber.plant(new Timber.DebugTree());
36 | component = DaggerDaggerTutorialApplicationComponent.builder()
37 | .contextModule(new ContextModule(this))
38 | .build();
39 |
40 |
41 | }
42 |
43 | public DaggerTutorialApplicationComponent component() {
44 | return component;
45 | }
46 |
47 | public static DaggerTutorialApplication get(Activity activity) {
48 | return (DaggerTutorialApplication) activity.getApplication();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 |
10 | import ir.coursio.daggertutorial.handler.PermissionHandler;
11 |
12 | /**
13 | * Created by Taher on 08/04/2017.
14 | * Project: RetrofitTutorial
15 | */
16 |
17 | public class BaseActivity extends AppCompatActivity {
18 |
19 | @Override
20 | protected void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | getPermissions();
23 | }
24 |
25 | @Override
26 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
27 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
28 | Intent intent = new Intent("PERMISSION_RECEIVER");
29 | intent.putExtra("requestCode", requestCode);
30 | intent.putExtra("permissions", permissions);
31 | intent.putExtra("grantResults", grantResults);
32 | sendBroadcast(intent);
33 | }
34 |
35 | private void getPermissions(){
36 | String[] permissions = {Manifest.permission.INTERNET};
37 | new PermissionHandler().checkPermission(BaseActivity.this, permissions, new PermissionHandler.OnPermissionResponse() {
38 | @Override
39 | public void onPermissionGranted() {
40 | }
41 |
42 | @Override
43 | public void onPermissionDenied() {
44 | }
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/modules/NetworkModule.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial.modules;
2 |
3 | import android.content.Context;
4 |
5 | import java.io.File;
6 |
7 | import dagger.Module;
8 | import dagger.Provides;
9 | import ir.coursio.daggertutorial.scopes.DaggerTutorialApplicationScope;
10 | import okhttp3.Cache;
11 | import okhttp3.OkHttpClient;
12 | import okhttp3.logging.HttpLoggingInterceptor;
13 | import timber.log.Timber;
14 |
15 | /**
16 | * Created by Taher on 21/04/2017.
17 | * Project: DaggerTutorial
18 | */
19 |
20 | @Module(includes = ContextModule.class)
21 | public class NetworkModule {
22 | @Provides
23 | @DaggerTutorialApplicationScope
24 | public OkHttpClient okHttpClient(HttpLoggingInterceptor loggingInterceptor, Cache cache) {
25 | return new OkHttpClient.Builder()
26 | .addInterceptor(loggingInterceptor)
27 | .cache(cache)
28 | .build();
29 | }
30 |
31 | @Provides
32 | @DaggerTutorialApplicationScope
33 | public HttpLoggingInterceptor loggingInterceptor() {
34 | return new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
35 | @Override
36 | public void log(String message) {
37 | Timber.i(message);
38 | }
39 | });
40 | }
41 |
42 | @Provides
43 | @DaggerTutorialApplicationScope
44 | public Cache cache(File cacheFile) {
45 | return new Cache(cacheFile, 5 * 1000 * 1000); //5MB cache;
46 | }
47 |
48 | @Provides
49 | @DaggerTutorialApplicationScope
50 | public File file(Context context) {
51 | File cacheFile = new File(context.getCacheDir(), "okhttp_cache");
52 | cacheFile.mkdirs();
53 | return cacheFile;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/modules/ApiServiceModule.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial.modules;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import ir.coursio.daggertutorial.api.ApiService;
6 | import ir.coursio.daggertutorial.qualifier.ApiServiceQualifier;
7 | import ir.coursio.daggertutorial.qualifier.RetrofitQualifier;
8 | import ir.coursio.daggertutorial.scopes.DaggerTutorialApplicationScope;
9 | import okhttp3.OkHttpClient;
10 | import retrofit2.Retrofit;
11 | import retrofit2.converter.gson.GsonConverterFactory;
12 |
13 | /**
14 | * Created by Taher on 21/04/2017.
15 | * Project: DaggerTutorial
16 | */
17 |
18 | @Module(includes = NetworkModule.class)
19 | public class ApiServiceModule {
20 | private static final String BASE_URL = "http://api.icndb.com/";
21 |
22 | @Provides
23 | @ApiServiceQualifier
24 | @DaggerTutorialApplicationScope
25 | public ApiService apiService(@RetrofitQualifier Retrofit retrofit) {
26 | return retrofit.create(ApiService.class);
27 | }
28 |
29 | @Provides
30 | @RetrofitQualifier
31 | @DaggerTutorialApplicationScope
32 | public Retrofit retrofit(OkHttpClient client) {
33 | return new Retrofit.Builder()
34 | .baseUrl(BASE_URL)
35 | .client(client)
36 | .addConverterFactory(GsonConverterFactory.create())
37 | .build();
38 |
39 | }
40 |
41 |
42 | @Provides
43 | @DaggerTutorialApplicationScope
44 | public ApiService anotherApiService(Retrofit retrofit) {
45 | return retrofit.create(ApiService.class);
46 | }
47 |
48 | @Provides
49 | @DaggerTutorialApplicationScope
50 | public Retrofit anotherRetrofit(OkHttpClient client) {
51 | return new Retrofit.Builder()
52 | .baseUrl(BASE_URL)
53 | .client(client)
54 | .addConverterFactory(GsonConverterFactory.create())
55 | .build();
56 |
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "ir.coursio.daggertutorial"
8 | minSdkVersion 10
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:recyclerview-v7:25.1.1'
31 | compile 'com.android.support:cardview-v7:25.1.1'
32 |
33 |
34 | // Dagger 2
35 | compile "com.google.dagger:dagger:2.10"
36 | annotationProcessor "com.google.dagger:dagger-compiler:2.10"
37 | provided 'javax.annotation:jsr250-api:1.0'
38 |
39 | //Retrofit
40 | compile 'com.squareup.retrofit2:retrofit:2.2.0'
41 | compile 'com.squareup.retrofit2:converter-gson:2.2.0'
42 | compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
43 |
44 | //OKHttp
45 | compile 'com.squareup.okhttp3:logging-interceptor:3.7.0'
46 | compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
47 |
48 |
49 | //Picasso
50 | compile 'com.squareup.picasso:picasso:2.5.2'
51 |
52 | //Butter Knife
53 | compile 'com.jakewharton:butterknife:8.5.1'
54 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
55 |
56 | //Timber
57 | compile 'com.jakewharton.timber:timber:4.5.1'
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 |
7 |
8 | import javax.inject.Inject;
9 |
10 | import butterknife.BindView;
11 | import butterknife.ButterKnife;
12 | import butterknife.OnClick;
13 | import ir.coursio.daggertutorial.api.ApiService;
14 | import ir.coursio.daggertutorial.model.Responses.JokeListResponse;
15 | import ir.coursio.daggertutorial.modules.MainActivityModule;
16 | import ir.coursio.daggertutorial.qualifier.ApiServiceQualifier;
17 | import ir.coursio.daggertutorial.view.JokeAdapter;
18 | import retrofit2.Call;
19 | import retrofit2.Callback;
20 | import retrofit2.Response;
21 |
22 | public class MainActivity extends BaseActivity {
23 |
24 | @BindView(R.id.recycler_view)
25 | RecyclerView recyclerView;
26 |
27 | Call mCall;
28 | @Inject
29 | JokeAdapter mAdapter;
30 |
31 | @Inject
32 | @ApiServiceQualifier
33 | ApiService apiService;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_main);
39 | ButterKnife.bind(this);
40 | MainActivityComponent component = DaggerMainActivityComponent.builder()
41 | .mainActivityModule(new MainActivityModule(this))
42 | .daggerTutorialApplicationComponent(DaggerTutorialApplication.get(this).component())
43 | .build();
44 | component.injectMainActivity(this);
45 |
46 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
47 | recyclerView.setAdapter(mAdapter);
48 |
49 | }
50 |
51 | @Override
52 | protected void onDestroy() {
53 | super.onDestroy();
54 | if (mCall != null) {
55 | mCall.cancel();
56 | }
57 | }
58 |
59 | @OnClick(R.id.btnGetJoke)
60 | public void getJoke() {
61 | mCall = apiService.getJokes();
62 | mCall.enqueue(new Callback() {
63 | @Override
64 | public void onResponse(Call call, Response response) {
65 | mAdapter.SwapData(response.body().getJokes());
66 | }
67 |
68 | @Override
69 | public void onFailure(Call call, Throwable t) {
70 |
71 | }
72 | });
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/view/JokeAdapter.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial.view;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 |
12 | import com.squareup.picasso.Picasso;
13 |
14 | import java.util.ArrayList;
15 |
16 | import javax.inject.Inject;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 | import ir.coursio.daggertutorial.BaseActivity;
21 | import ir.coursio.daggertutorial.MainActivity;
22 | import ir.coursio.daggertutorial.R;
23 | import ir.coursio.daggertutorial.model.Subs.JokeStruct;
24 |
25 |
26 | /**
27 | * Created by Taher on 11/04/2017.
28 | * Project: ReactiveRetrofitTutorial
29 | */
30 |
31 | public class JokeAdapter extends RecyclerView.Adapter {
32 |
33 | private Picasso picasso;
34 | private Context mContext;
35 | private ArrayList mJokeList = new ArrayList<>(0);
36 |
37 | @Inject
38 | public JokeAdapter(MainActivity mContext, Picasso picasso) {
39 | this.mContext = mContext;
40 | this.picasso = picasso;
41 | }
42 |
43 | public void SwapData(ArrayList mJokeList) {
44 | this.mJokeList = mJokeList;
45 | notifyDataSetChanged();
46 | }
47 |
48 | @Override
49 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
50 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_joke, parent, false);
51 | return new ViewHolder(view);
52 | }
53 |
54 | @Override
55 | public void onBindViewHolder(ViewHolder holder, int position) {
56 | if (mJokeList != null) {
57 | holder.txtJoke.setText(mJokeList.get(position).getText());
58 |
59 | picasso.load("http://coursio.ir/wp-content/uploads/2017/04/logo.png")
60 | .into(holder.imageView);
61 | }
62 | }
63 |
64 |
65 | @Override
66 | public int getItemCount() {
67 | return mJokeList.size();
68 | }
69 |
70 | public class ViewHolder extends RecyclerView.ViewHolder {
71 |
72 | @BindView(R.id.txtJoke)
73 | TextView txtJoke;
74 |
75 | @BindView(R.id.img)
76 | ImageView imageView;
77 |
78 | public ViewHolder(View view) {
79 | super(view);
80 | ButterKnife.bind(this, view);
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | Android
39 |
40 |
41 | Android > Lint > Internationalization > Bidirectional Text
42 |
43 |
44 | XML
45 |
46 |
47 |
48 |
49 | AndroidUnknownAttribute
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/java/ir/coursio/daggertutorial/handler/PermissionHandler.java:
--------------------------------------------------------------------------------
1 | package ir.coursio.daggertutorial.handler;
2 |
3 | import android.app.Activity;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.content.pm.PackageManager;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.support.annotation.NonNull;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.util.Log;
14 |
15 | /**
16 | * Created by Taher on 17/03/2017.
17 | * Project: RetrofitTutorial
18 | */
19 |
20 | public class PermissionHandler {
21 |
22 |
23 | private BroadcastReceiver permissionReceiver;
24 | private OnPermissionResponse listener;
25 | private Activity activity;
26 |
27 | public void checkPermission(Activity _activity,String[] permission,OnPermissionResponse _listener) {
28 | listener = _listener;
29 | activity = _activity;
30 |
31 | if (Build.VERSION.SDK_INT >= 23) {
32 | for(int i = 0;i= 23) {
58 | if (activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
59 | listener.onPermissionGranted();
60 | } else {
61 | registerReceiver();
62 | ActivityCompat.requestPermissions(activity, new String[]{permission}, 1);
63 | }
64 |
65 | } else {
66 | listener.onPermissionGranted();
67 | }
68 | }
69 |
70 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
71 | if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
72 | listener.onPermissionGranted();
73 | }else {
74 | listener.onPermissionDenied();
75 | }
76 | }
77 |
78 | public interface OnPermissionResponse{
79 | void onPermissionGranted();
80 | void onPermissionDenied();
81 | }
82 |
83 | private void registerReceiver() {
84 | permissionReceiver = new BroadcastReceiver() {
85 | @Override
86 | public void onReceive(Context context, Intent intent) {
87 | Bundle extras = intent.getExtras();
88 | if (extras != null)
89 | {
90 | int requestCode = extras.getInt("requestCode");
91 | String[] permissions = intent.getStringArrayExtra("permissions");
92 | int[] grantResults = intent.getIntArrayExtra("grantResults");
93 | onRequestPermissionsResult(requestCode,permissions,grantResults);
94 | activity.unregisterReceiver(permissionReceiver);
95 | }
96 | }
97 | };
98 |
99 | IntentFilter localIntentFilter = new IntentFilter();
100 | localIntentFilter.addAction("PERMISSION_RECEIVER");
101 | activity.registerReceiver(permissionReceiver, localIntentFilter);
102 | }
103 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------