正在查看: Cashalo v2.25.0.0 应用的 AdapterUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Cashalo v2.25.0.0 应用的 AdapterUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.oriente.adapter.config;
import android.text.TextUtils;
import com.fullstory.FS;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.oriente.adapter.R;
import com.oriente.adapter.http.SslUtil;
import com.oriente.adapter.http.model.GlobalHttpInterceptor;
import com.oriente.adapter.http.model.JsonProtectDeserializer;
import com.oriente.adapter.http.model.ResponseResult;
import com.oriente.core.internal.SingletonSupplier;
import com.oriente.core.internal.Supplier;
import com.oriente.core.page.PageManager;
import com.oriente.core.page.jump.FragmentOption;
import com.oriente.core.task.AsyncTask;
import com.oriente.core.utils.AmountUtils;
import com.oriente.core.utils.ResUtils;
import com.oriente.core.utils.StringUtils;
import com.oriente.http.converter.StringConverterFactory;
import com.oriente.http.intercept.HttpLogger;
import com.oriente.http.model.HttpHeaderUtils;
import com.oriente.http.model.ResponseNumberChecker;
import java.net.CookieStore;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.OriGsonConverterFactory;
public class AdapterUtils {
private static Supplier<? extends CookieStore> sCookieStoreSupplier;
private static Supplier<Gson> sGsonSupplier;
private static Supplier<OkHttpClient> sOkHttpSupplier;
private static final Hashtable<String, Supplier<Retrofit>> sRetrofitSupplierMap = new Hashtable<>();
private static Supplier<OkHttpClient> sUnsafeOkHttpSupplier;
public static void init() {
PageManager.getApplication();
update();
FragmentOption.setDefaultAnimation(R.anim.ori_slide_left_in, R.anim.ori_slide_left_out, R.anim.ori_slide_right_in, R.anim.ori_slide_right_out);
}
public static synchronized void update() {
synchronized (AdapterUtils.class) {
SingletonSupplier singletonSupplier = sGsonSupplier;
if (singletonSupplier instanceof SingletonSupplier) {
singletonSupplier.invalidate();
} else {
sGsonSupplier = createDefaultGsonSupplier();
}
SingletonSupplier singletonSupplier2 = sOkHttpSupplier;
if (singletonSupplier2 instanceof SingletonSupplier) {
singletonSupplier2.invalidate();
} else {
sOkHttpSupplier = createDefaultOkHttpSupplier();
}
SingletonSupplier singletonSupplier3 = sUnsafeOkHttpSupplier;
if (singletonSupplier3 instanceof SingletonSupplier) {
singletonSupplier3.invalidate();
} else {
sUnsafeOkHttpSupplier = createUnsafeOkHttpSupplier();
}
updateRetrofitSupplier();
}
}
public static GsonBuilder gsonBuilder() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(new TypeToken<ResponseResult>() {
}.getType(), new JsonProtectDeserializer()).create();
if (ValueConfig.sDebug || ValueConfig.sDevMode) {
gsonBuilder.registerTypeAdapter(Integer.TYPE, new ResponseNumberChecker());
}
return gsonBuilder;
}
public static OkHttpClient.Builder okHttpBuilder() {
int i = ValueConfig.sConnectTimeout;
int i2 = ValueConfig.sReadTimeout;
OkHttpClient.Builder builder = new OkHttpClient.Builder();
FS.okhttp_addInterceptors(builder);
builder.connectTimeout(i, TimeUnit.SECONDS);
builder.readTimeout(i2, TimeUnit.SECONDS);
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new HttpLogger());
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
if (ValueConfig.isDevDebug()) {
builder.addNetworkInterceptor(httpLoggingInterceptor);
}
GlobalHttpInterceptor.apply(builder);
if (AsyncTask.THREAD_POOL_EXECUTOR instanceof ExecutorService) {
builder.dispatcher(new Dispatcher((ExecutorService) AsyncTask.THREAD_POOL_EXECUTOR));
}
if (ValueConfig.sDevProxy && ValueConfig.sRequestProxy != null) {
builder.proxy(ValueConfig.sRequestProxy);
}
SSLSocketFactory createSSLSocketFactory = (ValueConfig.sDevSSL || ValueConfig.sPreTrustSSL) ? SslUtil.createSSLSocketFactory() : SslUtil.get().getSSLSocketFactory();
if (createSSLSocketFactory != null) {
builder.sslSocketFactory(createSSLSocketFactory, (X509TrustManager) SslUtil.get().getTrustManager());
}
if (ValueConfig.sDevSSL || ValueConfig.sPreTrustSSL) {
builder.hostnameVerifier(new SslUtil.TrustAllHostnameVerifier());
}
return builder;
}
public static OkHttpClient.Builder unsafeOkHttpBuilder() {
int i = ValueConfig.sConnectTimeout;
int i2 = ValueConfig.sReadTimeout;
OkHttpClient.Builder builder = new OkHttpClient.Builder();
FS.okhttp_addInterceptors(builder);
builder.connectTimeout(i, TimeUnit.SECONDS);
builder.readTimeout(i2, TimeUnit.SECONDS);
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new HttpLogger());
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
if (ValueConfig.isDevDebug()) {
builder.addNetworkInterceptor(httpLoggingInterceptor);
}
GlobalHttpInterceptor.apply(builder);
if (AsyncTask.THREAD_POOL_EXECUTOR instanceof ExecutorService) {
builder.dispatcher(new Dispatcher((ExecutorService) AsyncTask.THREAD_POOL_EXECUTOR));
}
if (ValueConfig.sDevProxy && ValueConfig.sRequestProxy != null) {
builder.proxy(ValueConfig.sRequestProxy);
}
builder.sslSocketFactory(SslUtil.createSSLSocketFactory(), (X509TrustManager) SslUtil.get().getTrustManager());
builder.hostnameVerifier(new SslUtil.TrustAllHostnameVerifier());
return builder;
}
private static Supplier<OkHttpClient> createUnsafeOkHttpSupplier() {
return new SingletonSupplier<OkHttpClient>() {
public OkHttpClient create() {
return AdapterUtils.unsafeOkHttpBuilder().build();
}
};
}
public static Retrofit.Builder retrofitBuilder(String str) {
if (StringUtils.isInvisibleOrNull(str)) {
str = ValueConfig.sRequestHost;
}
Retrofit.Builder builder = new Retrofit.Builder();
if (!StringUtils.isInvisibleOrNull(str)) {
builder.baseUrl(str);
}
builder.addConverterFactory(new StringConverterFactory()).addConverterFactory(OriGsonConverterFactory.create());
return builder;
}
public static Gson getGson() {
if (sGsonSupplier == null) {
update();
}
return (Gson) sGsonSupplier.get();
}
public static OkHttpClient getOkHttpClient() {
if (sOkHttpSupplier == null) {
update();
}
return (OkHttpClient) sOkHttpSupplier.get();
}
public static OkHttpClient getUnsafeOkHttpClient() {
if (sUnsafeOkHttpSupplier == null) {
update();
}
return (OkHttpClient) sUnsafeOkHttpSupplier.get();
}
public static Retrofit getRetrofit(String str) {
return (Retrofit) getRetrofitSupplier(str).get();
}
public static synchronized void setCookieStoreSupplier(Supplier<? extends CookieStore> supplier) {
synchronized (AdapterUtils.class) {
if (supplier != null) {
if (supplier != sCookieStoreSupplier) {
synchronized (AdapterUtils.class) {
sCookieStoreSupplier = supplier;
}
}
}
}
}
public static synchronized void setGsonSupplier(Supplier<Gson> supplier) {
synchronized (AdapterUtils.class) {
if (supplier != null) {
if (supplier != sGsonSupplier) {
synchronized (AdapterUtils.class) {
sGsonSupplier = supplier;
}
}
}
}
}
public static synchronized void setOkHttpSupplier(Supplier<OkHttpClient> supplier) {
synchronized (AdapterUtils.class) {
if (supplier != null) {
if (supplier != sOkHttpSupplier) {
synchronized (AdapterUtils.class) {
sOkHttpSupplier = supplier;
}
}
}
}
}
public static void setRetrofitSupplier(Supplier<Retrofit> supplier) {
Retrofit retrofit;
if (supplier == null || (retrofit = (Retrofit) supplier.get()) == null) {
return;
}
String valueOf = String.valueOf(retrofit.baseUrl());
if (StringUtils.isInvisibleOrNull(valueOf)) {
valueOf = "";
}
sRetrofitSupplierMap.put(valueOf, supplier);
}
private static void updateRetrofitSupplier() {
Hashtable<String, Supplier<Retrofit>> hashtable = sRetrofitSupplierMap;
if (hashtable.size() > 0) {
for (Map.Entry<String, Supplier<Retrofit>> entry : hashtable.entrySet()) {
String key = entry.getKey();
SingletonSupplier singletonSupplier = (Supplier) entry.getValue();
if (singletonSupplier instanceof SingletonSupplier) {
singletonSupplier.invalidate();
} else {
sRetrofitSupplierMap.put(key, createDefaultRetrofitSupplier(key));
}
}
}
}
private static Supplier<Retrofit> getRetrofitSupplier(String str) {
if (StringUtils.isInvisibleOrNull(str)) {
str = ValueConfig.sRequestHost;
}
String str2 = StringUtils.isInvisibleOrNull(str) ? "" : str;
Hashtable<String, Supplier<Retrofit>> hashtable = sRetrofitSupplierMap;
Supplier<Retrofit> supplier = hashtable.get(str2);
if (supplier != null) {
return supplier;
}
Supplier<Retrofit> createDefaultRetrofitSupplier = createDefaultRetrofitSupplier(str);
hashtable.put(str2, createDefaultRetrofitSupplier);
return createDefaultRetrofitSupplier;
}
private static Supplier<Gson> createDefaultGsonSupplier() {
return new SingletonSupplier<Gson>() {
public Gson m215create() {
return AdapterUtils.gsonBuilder().create();
}
};
}
private static Supplier<OkHttpClient> createDefaultOkHttpSupplier() {
return new SingletonSupplier<OkHttpClient>() {
public OkHttpClient create() {
return AdapterUtils.okHttpBuilder().build();
}
};
}
private static Supplier<Retrofit> createDefaultRetrofitSupplier(final String str) {
return new SingletonSupplier<Retrofit>() {
public Retrofit create() {
return AdapterUtils.retrofitBuilder(str).client(AdapterUtils.getOkHttpClient()).build();
}
};
}
public static void updateLocal(Locale locale) {
ResUtils.setLocal(locale);
AmountUtils.setLocal(locale);
if (locale != null) {
String language = locale.getLanguage();
String country = locale.getCountry();
StringBuilder sb = new StringBuilder(language);
if (!TextUtils.isEmpty(country)) {
sb.append('-');
sb.append(country);
sb.append(',');
sb.append(language);
sb.append(";q=0.8");
}
HttpHeaderUtils.setAcceptLanguage(sb.toString());
}
}
}