// Path: code/base/src/main/java/vn/eazy/base/mvp/intergration/handler/error/RxErrorHandler.java
// public class RxErrorHandler {
//     public final String TAG = this.getClass().getSimpleName();
//     private ErrorHandlerFactory mHandlerFactory;
// 
//     public RxErrorHandler(Builder builder) {
//         this.mHandlerFactory = builder.errorHandlerFactory;
//     }
// 
// 
//     public static Builder builder() {
//         return new Builder();
//     }
// 
//     public ErrorHandlerFactory getHandlerFactory() {
//         return mHandlerFactory;
//     }
// 
//     public static final class Builder {
//         private Context context;
//         private ResponseErrorListener mResponseErrorListener;
//         private ErrorHandlerFactory errorHandlerFactory;
// 
//         private Builder() {
//         }
// 
//         public Builder with(Context context) {
//             this.context = context;
//             return this;
//         }
// 
//         public Builder responseErrorListener(ResponseErrorListener responseErrorListener) {
//             this.mResponseErrorListener = responseErrorListener;
//             return this;
//         }
// 
//         public RxErrorHandler build() {
//             if (context == null)
//                 throw new IllegalStateException("Context is required");
// 
//             if (mResponseErrorListener == null)
//                 throw new IllegalStateException("ResponseErrorListener is required");
// 
//             this.errorHandlerFactory = new ErrorHandlerFactory(context, mResponseErrorListener);
// 
//             return new RxErrorHandler(this);
//         }
//     }
// 
// }
// 
// Path: code/base/src/main/java/vn/eazy/base/mvp/intergration/handler/error/listener/ResponseErrorListener.java
// public interface ResponseErrorListener {
//     void handleResponseError(Context context, Throwable t);
// 
//     ResponseErrorListener EMPTY = new ResponseErrorListener() {
//         @Override
//         public void handleResponseError(Context context, Throwable t) {
// 
//         }
//     };
// }


import android.app.Application;
import android.content.Context;
import android.support.annotation.Nullable;
import com.ihsanbal.logging.Level;
import com.ihsanbal.logging.LoggingInterceptor;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import okhttp3.Cache;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import vn.eazy.base.mvp.BuildConfig;
import vn.eazy.base.mvp.intergration.handler.error.RxErrorHandler;
import vn.eazy.base.mvp.intergration.handler.error.listener.ResponseErrorListener;
package vn.eazy.base.mvp.di.module;






/**
 * Created by harryle on 6/17/17.
 */
@Module
public class ClientModule {
    private static final int CACHE_SIZE = 10 * 1024 * 1024; //10MiB
    private static final int CONNECT_TIMEOUT = 10;
    private static final int READ_TIMEOUT = 30;
    private static final int WRITE_TIMEOUT = 60;
    //Todo Application's injected from AppModule

    @Provides
    @Singleton
    public Cache provideCache(File cacheFile) {
        Cache cache = new Cache(cacheFile, CACHE_SIZE);
        return cache;
    }

    @Provides
    @Singleton
    public OkHttpClient.Builder provideOkHttpBuilder() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        return builder;
    }

    @Provides
    @Singleton
    public OkHttpClient provideOkHttpClient(Application application, OkHttpClient.Builder builder, @Nullable Cache cache, @Nullable List<Interceptor> interceptors, @Nullable OkHttpConfiguration httpConfiguration) {
        builder.cache(cache)
                .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
// Path: code/base/src/main/java/vn/eazy/base/mvp/intergration/handler/error/RxErrorHandler.java
// public class RxErrorHandler {
//     public final String TAG = this.getClass().getSimpleName();
//     private ErrorHandlerFactory mHandlerFactory;
// 
//     public RxErrorHandler(Builder builder) {
//         this.mHandlerFactory = builder.errorHandlerFactory;
//     }
// 
// 
//     public static Builder builder() {
//         return new Builder();
//     }
// 
//     public ErrorHandlerFactory getHandlerFactory() {
//         return mHandlerFactory;
//     }
// 
//     public static final class Builder {
//         private Context context;
//         private ResponseErrorListener mResponseErrorListener;
//         private ErrorHandlerFactory errorHandlerFactory;
// 
//         private Builder() {
//         }
// 
//         public Builder with(Context context) {
//             this.context = context;
//             return this;
//         }
// 
//         public Builder responseErrorListener(ResponseErrorListener responseErrorListener) {
//             this.mResponseErrorListener = responseErrorListener;
//             return this;
//         }
// 
//         public RxErrorHandler build() {
//             if (context == null)
//                 throw new IllegalStateException("Context is required");
// 
//             if (mResponseErrorListener == null)
//                 throw new IllegalStateException("ResponseErrorListener is required");
// 
//             this.errorHandlerFactory = new ErrorHandlerFactory(context, mResponseErrorListener);
// 
//             return new RxErrorHandler(this);
//         }
//     }
// 
// }
// 
// Path: code/base/src/main/java/vn/eazy/base/mvp/intergration/handler/error/listener/ResponseErrorListener.java
// public interface ResponseErrorListener {
//     void handleResponseError(Context context, Throwable t);
// 
//     ResponseErrorListener EMPTY = new ResponseErrorListener() {
//         @Override
//         public void handleResponseError(Context context, Throwable t) {
// 
//         }
//     };
// }


// Path: code/base/src/main/java/vn/eazy/base/mvp/di/module/ClientModule.java
import android.app.Application;
import android.content.Context;
import android.support.annotation.Nullable;
import com.ihsanbal.logging.Level;
import com.ihsanbal.logging.LoggingInterceptor;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import okhttp3.Cache;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import vn.eazy.base.mvp.BuildConfig;
import vn.eazy.base.mvp.intergration.handler.error.RxErrorHandler;
import vn.eazy.base.mvp.intergration.handler.error.listener.ResponseErrorListener;

package vn.eazy.base.mvp.di.module;






/**
 * Created by harryle on 6/17/17.
 */
@Module
public class ClientModule {
    private static final int CACHE_SIZE = 10 * 1024 * 1024; //10MiB
    private static final int CONNECT_TIMEOUT = 10;
    private static final int READ_TIMEOUT = 30;
    private static final int WRITE_TIMEOUT = 60;
    //Todo Application's injected from AppModule

    @Provides
    @Singleton
    public Cache provideCache(File cacheFile) {
        Cache cache = new Cache(cacheFile, CACHE_SIZE);
        return cache;
    }

    @Provides
    @Singleton
    public OkHttpClient.Builder provideOkHttpBuilder() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        return builder;
    }

    @Provides
    @Singleton
    public OkHttpClient provideOkHttpClient(Application application, OkHttpClient.Builder builder, @Nullable Cache cache, @Nullable List<Interceptor> interceptors, @Nullable OkHttpConfiguration httpConfiguration) {
        builder.cache(cache)
                .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)