// Path: app/src/main/java/york/com/retrofit2rxjavademo/di/module/NetworkModule.java
// @Module
// public class NetworkModule {
// //    private String mBaseUrl = "http://rap.taobao.org/mockjsdata/15987/";
//     private String mBaseUrl;
//     private int DEFAULT_TIMEOUT = 10;
// 
//     // Constructor needs one parameter to instantiate.
//     public NetworkModule(String baseUrl, int default_timeout) {
//         this.mBaseUrl = baseUrl;
//         this.DEFAULT_TIMEOUT = default_timeout;
//     }
// 
//     // Dagger will only look for methods annotated with @Provides
//     @Provides
//     @AppScope
//     // Application reference must come from AppModule.class
//     SharedPreferences providesSharedPreferences(MyApplication application) {
//         return PreferenceManager.getDefaultSharedPreferences(application);
//     }
// 
//     @Provides
//     @AppScope
//     Cache provideOkHttpCache(MyApplication application) {
//         int cacheSize = 10 * 1024 * 1024; // 10 MiB
//         Cache cache = new Cache(application.getCacheDir(), cacheSize);
//         return cache;
//     }
// 
//     @Provides
//     @AppScope
//     Gson provideGson() {
//         GsonBuilder gsonBuilder = new GsonBuilder();
//         gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
//         return gsonBuilder.create();
//     }
// 
//     @Provides
//     @AppScope
//     @Named("cached")
//     OkHttpClient provideOkHttpClient(Cache cache) {
//         OkHttpClient client =
//                 new OkHttpClient.Builder()
//                         .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .addNetworkInterceptor(
//                                 new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
//                         .retryOnConnectionFailure(true)
//                         .cache(cache)
//                         .build();
//         return client;
//     }
// 
//     @Provides
//     @AppScope
//     @Named("noncached")
//     OkHttpClient provideNonCachedOkHttpClient() {
//         OkHttpClient client =
//                 new OkHttpClient.Builder()
//                         .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .addNetworkInterceptor(
//                                 new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
//                         .retryOnConnectionFailure(true)
//                         .build();
//         return client;
//     }
// 
//     @Provides
//     @AppScope
//     Retrofit provideRetrofit(Gson gson, @Named("cached") OkHttpClient okHttpClient) {
//         return new Retrofit.Builder()
//                 .addConverterFactory(GsonConverterFactory.create(gson))
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .client(okHttpClient)
//                 .baseUrl(mBaseUrl)
//                 .build();
//     }
// 
// 
//     /**
//      *  使用自定义Converter处理message在错误时返回在data字段
//      * @param gson
//      * @param okHttpClient
//      * @return
//      */
//     @Provides
//     @AppScope
//     @Named("custom_converter")
//     Retrofit provideCustomConverterRetrofit(Gson gson, @Named("cached") OkHttpClient okHttpClient) {
//         return new Retrofit.Builder()
//                 .addConverterFactory(CustomGsonConverterFactory.create(gson))
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .client(okHttpClient)
//                 .baseUrl(mBaseUrl)
//                 .build();
//     }
// }


import android.app.Activity;
import android.app.Application;
import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import york.com.retrofit2rxjavademo.di.component.DaggerAppComponent;
import york.com.retrofit2rxjavademo.di.module.NetworkModule;
package york.com.retrofit2rxjavademo;




/**
 * @author YorkYu
 * @version V1.0
 * @Project: Retrofit2RxjavaDemo
 * @Package york.com.retrofit2rxjavademo
 * @Description:
 * @time 2016/7/25 17:08
 */
public class MyApplication extends Application implements HasActivityInjector {
    @Inject
    DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

    private static final String sBASE_URL = "http://rap.taobao.org/mockjsdata/15987/";
    private static final int sDEFAULT_TIMEOUT = 10;

    @Override
    public void onCreate() {
       super.onCreate();

        DaggerAppComponent
                .builder()
                .application(this)
// Path: app/src/main/java/york/com/retrofit2rxjavademo/di/module/NetworkModule.java
// @Module
// public class NetworkModule {
// //    private String mBaseUrl = "http://rap.taobao.org/mockjsdata/15987/";
//     private String mBaseUrl;
//     private int DEFAULT_TIMEOUT = 10;
// 
//     // Constructor needs one parameter to instantiate.
//     public NetworkModule(String baseUrl, int default_timeout) {
//         this.mBaseUrl = baseUrl;
//         this.DEFAULT_TIMEOUT = default_timeout;
//     }
// 
//     // Dagger will only look for methods annotated with @Provides
//     @Provides
//     @AppScope
//     // Application reference must come from AppModule.class
//     SharedPreferences providesSharedPreferences(MyApplication application) {
//         return PreferenceManager.getDefaultSharedPreferences(application);
//     }
// 
//     @Provides
//     @AppScope
//     Cache provideOkHttpCache(MyApplication application) {
//         int cacheSize = 10 * 1024 * 1024; // 10 MiB
//         Cache cache = new Cache(application.getCacheDir(), cacheSize);
//         return cache;
//     }
// 
//     @Provides
//     @AppScope
//     Gson provideGson() {
//         GsonBuilder gsonBuilder = new GsonBuilder();
//         gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
//         return gsonBuilder.create();
//     }
// 
//     @Provides
//     @AppScope
//     @Named("cached")
//     OkHttpClient provideOkHttpClient(Cache cache) {
//         OkHttpClient client =
//                 new OkHttpClient.Builder()
//                         .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .addNetworkInterceptor(
//                                 new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
//                         .retryOnConnectionFailure(true)
//                         .cache(cache)
//                         .build();
//         return client;
//     }
// 
//     @Provides
//     @AppScope
//     @Named("noncached")
//     OkHttpClient provideNonCachedOkHttpClient() {
//         OkHttpClient client =
//                 new OkHttpClient.Builder()
//                         .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                         .addNetworkInterceptor(
//                                 new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
//                         .retryOnConnectionFailure(true)
//                         .build();
//         return client;
//     }
// 
//     @Provides
//     @AppScope
//     Retrofit provideRetrofit(Gson gson, @Named("cached") OkHttpClient okHttpClient) {
//         return new Retrofit.Builder()
//                 .addConverterFactory(GsonConverterFactory.create(gson))
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .client(okHttpClient)
//                 .baseUrl(mBaseUrl)
//                 .build();
//     }
// 
// 
//     /**
//      *  使用自定义Converter处理message在错误时返回在data字段
//      * @param gson
//      * @param okHttpClient
//      * @return
//      */
//     @Provides
//     @AppScope
//     @Named("custom_converter")
//     Retrofit provideCustomConverterRetrofit(Gson gson, @Named("cached") OkHttpClient okHttpClient) {
//         return new Retrofit.Builder()
//                 .addConverterFactory(CustomGsonConverterFactory.create(gson))
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .client(okHttpClient)
//                 .baseUrl(mBaseUrl)
//                 .build();
//     }
// }


// Path: app/src/main/java/york/com/retrofit2rxjavademo/MyApplication.java
import android.app.Activity;
import android.app.Application;
import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import york.com.retrofit2rxjavademo.di.component.DaggerAppComponent;
import york.com.retrofit2rxjavademo.di.module.NetworkModule;

package york.com.retrofit2rxjavademo;




/**
 * @author YorkYu
 * @version V1.0
 * @Project: Retrofit2RxjavaDemo
 * @Package york.com.retrofit2rxjavademo
 * @Description:
 * @time 2016/7/25 17:08
 */
public class MyApplication extends Application implements HasActivityInjector {
    @Inject
    DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

    private static final String sBASE_URL = "http://rap.taobao.org/mockjsdata/15987/";
    private static final int sDEFAULT_TIMEOUT = 10;

    @Override
    public void onCreate() {
       super.onCreate();

        DaggerAppComponent
                .builder()
                .application(this)
                .network(new NetworkModule(sBASE_URL, sDEFAULT_TIMEOUT))