// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java
// public class AppApplication extends Application {
// 
//     /*网络是否连接*/
//     public static boolean isNetConnect;/*网络连接状态监听*/
//     private ConnectionReceiver connectionReceiver = new ConnectionReceiver();
//     public static AppApplication APP_APPLICATION;
// 
//     //刷新广播监听
//     public static final String REFRESH_ACTION = "REFRESH_ACTION";
// 
//     public static AppApplication getInstance() {
//         return APP_APPLICATION;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         // Create global configuration and initialize ImageLoader with this config
//         APP_APPLICATION = this;
//         initImageLoader(getApplicationContext());
//         registerNetReceiver();
// 
//         FlowManager.init(this);
//     }
// 
//     public static void initImageLoader(Context context) {
//         // This configuration tuning is custom. You can tune every option, you may tune some of them,
//         // or you can create default configuration by
//         //  ImageLoaderConfiguration.createDefault(this);
//         // method.
//         ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
//         config.threadPriority(Thread.NORM_PRIORITY - 2);
//         config.denyCacheImageMultipleSizesInMemory();
//         config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
//         config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
//         config.tasksProcessingOrder(QueueProcessingType.LIFO);
//         config.writeDebugLogs(); // Remove for release app
// 
//         // Initialize ImageLoader with configuration.
//         ImageLoader.getInstance().init(config.build());
//     }
// 
//     /**
//      * 注册网络连接状态监听
//      */
//     public void registerNetReceiver() {
//         IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
//         registerReceiver(connectionReceiver, connectionIntentFilter);
//     }
// 
//     /**
//      * 注销网络连接状态监听
//      */
//     public void unregisterNetReceiver() {
//         if (connectionReceiver != null) {
//             unregisterReceiver(connectionReceiver);
//         }
//     }
// }


import com.example.app.rxjava.AppApplication;
import java.io.IOException;
import java.util.logging.Logger;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
package com.example.app.rxjava.base.interceptor;

/**
 * Created by Administrator on 2016/3/4.
 */




/**
 * 有网络时，发起网络请求
 * 无网络时先从缓存中取值，如果缓存时间超过4周，则发起网络请求
 * <p>
 *
 */
public class CacheInterceptor implements Interceptor {

    //private int maxAge = 0;// 有网络时 设置缓存超时时间0秒
    private int maxStale = 60 * 60 * 24 * 28;// 无网络时，设置超时为4周

    public CacheInterceptor() {

    }

    @Override
// Path: app/src/main/java/com/example/app/rxjava/AppApplication.java
// public class AppApplication extends Application {
// 
//     /*网络是否连接*/
//     public static boolean isNetConnect;/*网络连接状态监听*/
//     private ConnectionReceiver connectionReceiver = new ConnectionReceiver();
//     public static AppApplication APP_APPLICATION;
// 
//     //刷新广播监听
//     public static final String REFRESH_ACTION = "REFRESH_ACTION";
// 
//     public static AppApplication getInstance() {
//         return APP_APPLICATION;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         // Create global configuration and initialize ImageLoader with this config
//         APP_APPLICATION = this;
//         initImageLoader(getApplicationContext());
//         registerNetReceiver();
// 
//         FlowManager.init(this);
//     }
// 
//     public static void initImageLoader(Context context) {
//         // This configuration tuning is custom. You can tune every option, you may tune some of them,
//         // or you can create default configuration by
//         //  ImageLoaderConfiguration.createDefault(this);
//         // method.
//         ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
//         config.threadPriority(Thread.NORM_PRIORITY - 2);
//         config.denyCacheImageMultipleSizesInMemory();
//         config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
//         config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
//         config.tasksProcessingOrder(QueueProcessingType.LIFO);
//         config.writeDebugLogs(); // Remove for release app
// 
//         // Initialize ImageLoader with configuration.
//         ImageLoader.getInstance().init(config.build());
//     }
// 
//     /**
//      * 注册网络连接状态监听
//      */
//     public void registerNetReceiver() {
//         IntentFilter connectionIntentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
//         registerReceiver(connectionReceiver, connectionIntentFilter);
//     }
// 
//     /**
//      * 注销网络连接状态监听
//      */
//     public void unregisterNetReceiver() {
//         if (connectionReceiver != null) {
//             unregisterReceiver(connectionReceiver);
//         }
//     }
// }


// Path: app/src/main/java/com/example/app/rxjava/base/interceptor/CacheInterceptor.java
import com.example.app.rxjava.AppApplication;
import java.io.IOException;
import java.util.logging.Logger;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

package com.example.app.rxjava.base.interceptor;

/**
 * Created by Administrator on 2016/3/4.
 */




/**
 * 有网络时，发起网络请求
 * 无网络时先从缓存中取值，如果缓存时间超过4周，则发起网络请求
 * <p>
 *
 */
public class CacheInterceptor implements Interceptor {

    //private int maxAge = 0;// 有网络时 设置缓存超时时间0秒
    private int maxStale = 60 * 60 * 24 * 28;// 无网络时，设置超时为4周

    public CacheInterceptor() {

    }

    @Override
    public Response intercept(Chain chain) throws IOException {