// Path: teachlibrary/src/main/java/com/rock/teachlibrary/rxevent/RxSchedulers.java
// public class RxSchedulers {
//     public static <T> Observable.Transformer<T, T> io_main() {
//         return new Observable.Transformer<T, T>() {
//             @Override
//             public Observable<T> call(Observable<T> observable) {
//                 return observable.subscribeOn(Schedulers.io())
//                         .observeOn(AndroidSchedulers.mainThread());
//             }
//         };
//     }
// }
// 
// Path: vmovie/src/main/java/com/rock/vmovie/api/Api.java
// public class Api {
// 
//     private static final int READ_TIME_OUT = 10 * 1000;
// 
//     private static final int CONNECT_TIME_OUT = 10 * 1000;
// 
//     private static final long CACHE_STALE_SEC = 60 * 60 * 24 * 2;
// 
//     public static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
// 
//     public static final String CACHE_CONTROL_AGE = "max-age=5";
// 
//     public static final int DEFAULT_SERVER = 0;
// 
//     public static final int SPECIAL_SERVER = 1;
// 
//     public static SparseArray<ApiService> mServers = new SparseArray<>(2);
// 
//     private Api() {
//         this(DEFAULT_SERVER);
//     }
// 
//     private Api(int type) {
//         //缓存
//         File cacheFile = new File(VMovieApp.getContext().getCacheDir(), "cache");
//         Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
//         //增加头部信息
//         Interceptor headerInterceptor = new Interceptor() {
//             @Override
//             public Response intercept(Chain chain) throws IOException {
//                 Request build = chain.request().newBuilder()
//                         .addHeader("Content-Type", "application/json")
//                         .build();
//                 return chain.proceed(build);
//             }
//         };
// 
// 
//         Interceptor mRewriteCacheControlInterceptor = new Interceptor() {
//             @Override
//             public Response intercept(Chain chain) throws IOException {
//                 Request request = chain.request();
//                 if (!NetWorkUtil.isNetConnected(VMovieApp.getContext())) {
//                     request = request.newBuilder()
//                             .cacheControl(CacheControl.FORCE_CACHE)
//                             .build();
//                 }
//                 Response originalResponse = chain.proceed(request);
//                 if (NetWorkUtil.isNetConnected(VMovieApp.getContext())) {
//                     String cacheControl = request.cacheControl().toString();
//                     return originalResponse.newBuilder()
//                             .removeHeader("Pragma")
//                             .header("Cache-Control", cacheControl)
//                             .build();
//                 } else {
//                     return originalResponse.newBuilder()
//                             .removeHeader("Pragma")
//                             .header("Cache-Control", "public, only-if-cached, max-stale=" + CACHE_STALE_SEC)
//                             .build();
//                 }
//             }
//         };
//         OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                 .readTimeout(READ_TIME_OUT, TimeUnit.MILLISECONDS)
//                 .connectTimeout(CONNECT_TIME_OUT, TimeUnit.MILLISECONDS)
//                 .addInterceptor(mRewriteCacheControlInterceptor)
//                 .addNetworkInterceptor(mRewriteCacheControlInterceptor)
//                 .addInterceptor(headerInterceptor)
//                 .cache(cache)
//                 .build();
//         String baseUrl = BuildConfig.BaseUrl;
//         switch (type) {
//             case SPECIAL_SERVER:
//                 baseUrl = BuildConfig.BaseUrlSpecial;
//                 break;
//         }
//         Retrofit retrofit = new Retrofit.Builder()
//                 .client(okHttpClient)
//                 .baseUrl(baseUrl)
//                 .addConverterFactory(GsonConverterFactory.create())
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .build();
//         switch (type) {
//             case SPECIAL_SERVER:
//                 mServers.put(SPECIAL_SERVER, retrofit.create(ApiService.class));
//                 break;
//             default:
//                 mServers.put(DEFAULT_SERVER, retrofit.create(ApiService.class));
//         }
// 
//     }
// 
// 
//     public static ApiService getDefault() {
//         return getService(DEFAULT_SERVER);
//     }
// 
//     public static ApiService getService(int type) {
//         if (mServers.get(type) == null) {
//             synchronized (Api.class) {
//                 if (mServers.get(type) == null) {
//                     new Api(type);
//                 }
//             }
//         }
//         return mServers.get(type);
//     }
// 
// 
//     public static String getCacheControl() {
//         return NetWorkUtil.isNetConnected(VMovieApp.getContext()) ? CACHE_CONTROL_AGE : CACHE_CONTROL_CACHE;
//     }
// 
// }
// 
// Path: vmovie/src/main/java/com/rock/vmovie/ui/channeldetail/contract/ChannelDetailContract.java
// public interface ChannelDetailContract {
// 
//      interface Model extends BaseModel{
// 
//          Observable<ChannelDetail> getChannelDetail(int page,int size,String cateid);
// 
//      }
// 
//     interface View extends BaseView{
// 
//         void returnChannelDetail(ChannelDetail channelDetail);
// 
//     }
// 
//     static abstract class Presenter extends BasePresenter<Model,View>{
// 
//         public abstract void getChannelDetailRequest(int page,int size,String cateid);
// 
//     }
// 
// }


import com.rock.teachlibrary.rxevent.RxSchedulers;
import com.rock.vmovie.api.Api;
import com.rock.vmovie.bean.ChannelDetail;
import com.rock.vmovie.ui.channeldetail.contract.ChannelDetailContract;
import rx.Observable;
package com.rock.vmovie.ui.channeldetail.model;



/**
 * Created by Rock on 2016/12/26.
 */

public class ChannelDetailModel implements ChannelDetailContract.Model {

    @Override
    public Observable<ChannelDetail> getChannelDetail(int page, int size, String cateid) {
// Path: teachlibrary/src/main/java/com/rock/teachlibrary/rxevent/RxSchedulers.java
// public class RxSchedulers {
//     public static <T> Observable.Transformer<T, T> io_main() {
//         return new Observable.Transformer<T, T>() {
//             @Override
//             public Observable<T> call(Observable<T> observable) {
//                 return observable.subscribeOn(Schedulers.io())
//                         .observeOn(AndroidSchedulers.mainThread());
//             }
//         };
//     }
// }
// 
// Path: vmovie/src/main/java/com/rock/vmovie/api/Api.java
// public class Api {
// 
//     private static final int READ_TIME_OUT = 10 * 1000;
// 
//     private static final int CONNECT_TIME_OUT = 10 * 1000;
// 
//     private static final long CACHE_STALE_SEC = 60 * 60 * 24 * 2;
// 
//     public static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
// 
//     public static final String CACHE_CONTROL_AGE = "max-age=5";
// 
//     public static final int DEFAULT_SERVER = 0;
// 
//     public static final int SPECIAL_SERVER = 1;
// 
//     public static SparseArray<ApiService> mServers = new SparseArray<>(2);
// 
//     private Api() {
//         this(DEFAULT_SERVER);
//     }
// 
//     private Api(int type) {
//         //缓存
//         File cacheFile = new File(VMovieApp.getContext().getCacheDir(), "cache");
//         Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb
//         //增加头部信息
//         Interceptor headerInterceptor = new Interceptor() {
//             @Override
//             public Response intercept(Chain chain) throws IOException {
//                 Request build = chain.request().newBuilder()
//                         .addHeader("Content-Type", "application/json")
//                         .build();
//                 return chain.proceed(build);
//             }
//         };
// 
// 
//         Interceptor mRewriteCacheControlInterceptor = new Interceptor() {
//             @Override
//             public Response intercept(Chain chain) throws IOException {
//                 Request request = chain.request();
//                 if (!NetWorkUtil.isNetConnected(VMovieApp.getContext())) {
//                     request = request.newBuilder()
//                             .cacheControl(CacheControl.FORCE_CACHE)
//                             .build();
//                 }
//                 Response originalResponse = chain.proceed(request);
//                 if (NetWorkUtil.isNetConnected(VMovieApp.getContext())) {
//                     String cacheControl = request.cacheControl().toString();
//                     return originalResponse.newBuilder()
//                             .removeHeader("Pragma")
//                             .header("Cache-Control", cacheControl)
//                             .build();
//                 } else {
//                     return originalResponse.newBuilder()
//                             .removeHeader("Pragma")
//                             .header("Cache-Control", "public, only-if-cached, max-stale=" + CACHE_STALE_SEC)
//                             .build();
//                 }
//             }
//         };
//         OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                 .readTimeout(READ_TIME_OUT, TimeUnit.MILLISECONDS)
//                 .connectTimeout(CONNECT_TIME_OUT, TimeUnit.MILLISECONDS)
//                 .addInterceptor(mRewriteCacheControlInterceptor)
//                 .addNetworkInterceptor(mRewriteCacheControlInterceptor)
//                 .addInterceptor(headerInterceptor)
//                 .cache(cache)
//                 .build();
//         String baseUrl = BuildConfig.BaseUrl;
//         switch (type) {
//             case SPECIAL_SERVER:
//                 baseUrl = BuildConfig.BaseUrlSpecial;
//                 break;
//         }
//         Retrofit retrofit = new Retrofit.Builder()
//                 .client(okHttpClient)
//                 .baseUrl(baseUrl)
//                 .addConverterFactory(GsonConverterFactory.create())
//                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                 .build();
//         switch (type) {
//             case SPECIAL_SERVER:
//                 mServers.put(SPECIAL_SERVER, retrofit.create(ApiService.class));
//                 break;
//             default:
//                 mServers.put(DEFAULT_SERVER, retrofit.create(ApiService.class));
//         }
// 
//     }
// 
// 
//     public static ApiService getDefault() {
//         return getService(DEFAULT_SERVER);
//     }
// 
//     public static ApiService getService(int type) {
//         if (mServers.get(type) == null) {
//             synchronized (Api.class) {
//                 if (mServers.get(type) == null) {
//                     new Api(type);
//                 }
//             }
//         }
//         return mServers.get(type);
//     }
// 
// 
//     public static String getCacheControl() {
//         return NetWorkUtil.isNetConnected(VMovieApp.getContext()) ? CACHE_CONTROL_AGE : CACHE_CONTROL_CACHE;
//     }
// 
// }
// 
// Path: vmovie/src/main/java/com/rock/vmovie/ui/channeldetail/contract/ChannelDetailContract.java
// public interface ChannelDetailContract {
// 
//      interface Model extends BaseModel{
// 
//          Observable<ChannelDetail> getChannelDetail(int page,int size,String cateid);
// 
//      }
// 
//     interface View extends BaseView{
// 
//         void returnChannelDetail(ChannelDetail channelDetail);
// 
//     }
// 
//     static abstract class Presenter extends BasePresenter<Model,View>{
// 
//         public abstract void getChannelDetailRequest(int page,int size,String cateid);
// 
//     }
// 
// }


// Path: vmovie/src/main/java/com/rock/vmovie/ui/channeldetail/model/ChannelDetailModel.java
import com.rock.teachlibrary.rxevent.RxSchedulers;
import com.rock.vmovie.api.Api;
import com.rock.vmovie.bean.ChannelDetail;
import com.rock.vmovie.ui.channeldetail.contract.ChannelDetailContract;
import rx.Observable;

package com.rock.vmovie.ui.channeldetail.model;



/**
 * Created by Rock on 2016/12/26.
 */

public class ChannelDetailModel implements ChannelDetailContract.Model {

    @Override
    public Observable<ChannelDetail> getChannelDetail(int page, int size, String cateid) {
        return Api.getDefault().getChannelDetail(Api.getCacheControl(),page,size,cateid).compose(RxSchedulers.<ChannelDetail>io_main());