// Path: client/FourFun/app/src/main/java/com/joker/fourfun/FourFun.java
// public class FourFun extends Application {
//     private static FourFun instance;
// 
//     public static FourFun getInstance() {
//         return instance;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         instance = this;
//         if (LeakCanary.isInAnalyzerProcess(this)) {
//             return;
//         }
//         LeakCanary.install(this);
//     }
// 
//     public Context getContext() {
//         return instance.getApplicationContext();
//     }
// }


import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.joker.fourfun.BuildConfig;
import com.joker.fourfun.FourFun;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
                if (!SystemUtil.isNetworkConnected()) {
                    request = request.newBuilder()
                            .cacheControl(CacheControl.FORCE_CACHE)
                            .build();
                }
                Response response = chain.proceed(request);
                if (SystemUtil.isNetworkConnected()) {
                    int maxAge = 0;
                    // 有网络时, 不缓存, 最大保存时长为0
                    response.newBuilder()
                            .header("Cache-Control", "public, max-age=" + maxAge)
                            .removeHeader("Pragma")
                            .build();
                } else {
                    // 无网络时，设置超时为4周
                    int maxStale = 60 * 60 * 24 * 28;
                    response.newBuilder()
                            .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
                            .removeHeader("Pragma")
                            .build();
                }

                return response;
            }
        };
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(interceptor);
        }
// Path: client/FourFun/app/src/main/java/com/joker/fourfun/FourFun.java
// public class FourFun extends Application {
//     private static FourFun instance;
// 
//     public static FourFun getInstance() {
//         return instance;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         instance = this;
//         if (LeakCanary.isInAnalyzerProcess(this)) {
//             return;
//         }
//         LeakCanary.install(this);
//     }
// 
//     public Context getContext() {
//         return instance.getApplicationContext();
//     }
// }


// Path: client/FourFun/app/src/main/java/com/joker/fourfun/utils/RetrofitUtil.java
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.joker.fourfun.BuildConfig;
import com.joker.fourfun.FourFun;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

                if (!SystemUtil.isNetworkConnected()) {
                    request = request.newBuilder()
                            .cacheControl(CacheControl.FORCE_CACHE)
                            .build();
                }
                Response response = chain.proceed(request);
                if (SystemUtil.isNetworkConnected()) {
                    int maxAge = 0;
                    // 有网络时, 不缓存, 最大保存时长为0
                    response.newBuilder()
                            .header("Cache-Control", "public, max-age=" + maxAge)
                            .removeHeader("Pragma")
                            .build();
                } else {
                    // 无网络时，设置超时为4周
                    int maxStale = 60 * 60 * 24 * 28;
                    response.newBuilder()
                            .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
                            .removeHeader("Pragma")
                            .build();
                }

                return response;
            }
        };
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(interceptor);
        }
        File cacheFile = new File(FourFun.getInstance().getCacheDir().getPath());