EhViewer v1.9.7.7版本的 MD5 值为:828893cd54837a794dab17a02809e194
以下内容为反编译后的 UConfigActivity.java 源代码,内容仅作参考
package com.hippo.ehviewer.ui;
import android.os.Bundle;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.CookieManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.acsbendi.requestinspectorwebview.RequestInspectorOptions;
import com.acsbendi.requestinspectorwebview.RequestInspectorWebViewClient;
import com.acsbendi.requestinspectorwebview.WebViewRequest;
import com.acsbendi.requestinspectorwebview.WebViewRequestType;
import com.google.android.material.snackbar.Snackbar;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.client.EhCookieStore;
import com.hippo.ehviewer.client.EhRequestBuilder;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.widget.DialogWebChromeClient;
import com.hippo.widget.ProgressView;
import com.microsoft.appcenter.crashes.Crashes;
import com.xjs.ehviewer.R;
import java.io.IOException;
import java.util.Map;
import kotlin.jvm.internal.LongCompanionObject;
import okhttp3.Cookie;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class UConfigActivity extends ToolbarActivity {
private boolean loaded;
private OkHttpClient okHttpClient;
private ProgressView progress;
private String url;
private WebView webView;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if (this.okHttpClient == null) {
this.okHttpClient = EhApplication.getOkHttpClient(getApplicationContext());
}
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.flush();
cookieManager.removeAllCookies(null);
cookieManager.removeSessionCookies(null);
this.url = EhUrl.getUConfigUrl();
for (Cookie cookie : EhApplication.getEhCookieStore(this).getCookies(HttpUrl.parse(this.url))) {
cookieManager.setCookie(this.url, cookie.toString());
}
setContentView(R.layout.activity_u_config);
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
WebView webView = (WebView) findViewById(R.id.webview);
this.webView = webView;
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
this.webView.setWebViewClient(new UConfigWebViewClient(this.webView));
this.webView.setWebChromeClient(new DialogWebChromeClient(this));
this.webView.loadUrl(this.url);
this.progress = (ProgressView) findViewById(R.id.progress);
Snackbar.make(this.webView, (int) R.string.apply_tip, 0).show();
}
private void apply() {
this.webView.loadUrl("javascript:(function() {\n var apply = document.getElementById(\"apply\").children[0];\n apply.click();\n})();");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.activity_u_config, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
int itemId = menuItem.getItemId();
if (itemId == 16908332) {
finish();
return true;
} else if (itemId == R.id.action_apply) {
if (this.loaded) {
apply();
}
return true;
} else {
return super.onOptionsItemSelected(menuItem);
}
}
private Cookie longLive(Cookie cookie) {
return new Cookie.Builder().name(cookie.name()).value(cookie.value()).domain(cookie.domain()).path(cookie.path()).expiresAt(LongCompanionObject.MAX_VALUE).build();
}
@Override
public void onDestroy() {
String[] split;
super.onDestroy();
this.webView.destroy();
this.webView = null;
String cookie = CookieManager.getInstance().getCookie(this.url);
if (cookie == null || cookie.isEmpty()) {
return;
}
EhCookieStore ehCookieStore = EhApplication.getEhCookieStore(this);
HttpUrl parse = HttpUrl.parse(EhUrl.HOST_E);
HttpUrl parse2 = HttpUrl.parse(EhUrl.HOST_EX);
for (String str : cookie.split(";")) {
Cookie parse3 = Cookie.parse(parse, str);
if (parse3 != null) {
ehCookieStore.addCookie(longLive(parse3));
}
Cookie parse4 = Cookie.parse(parse2, str);
if (parse4 != null) {
ehCookieStore.addCookie(longLive(parse4));
}
}
}
private class UConfigWebViewClient extends RequestInspectorWebViewClient {
final OkHttpClient webOkHttpClient;
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
return true;
}
public UConfigWebViewClient(WebView webView) {
super(webView);
this.webOkHttpClient = UConfigActivity.this.okHttpClient;
}
public UConfigWebViewClient(WebView webView, RequestInspectorOptions requestInspectorOptions) {
super(webView, requestInspectorOptions);
this.webOkHttpClient = UConfigActivity.this.okHttpClient;
}
@Override
public void onFormResubmission(WebView webView, Message message, Message message2) {
super.onFormResubmission(webView, message, message2);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebViewRequest webViewRequest) {
String str = "text/html; charset=UTF-8";
EhRequestBuilder ehRequestBuilder = new EhRequestBuilder(webViewRequest.getHeaders(), webViewRequest.getUrl());
if (AnonymousClass1.$SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType[webViewRequest.getType().ordinal()] == 4) {
ehRequestBuilder.post(buildForm(webViewRequest));
}
try {
Response execute = this.webOkHttpClient.newCall(ehRequestBuilder.build()).execute();
if (execute.body() == null) {
throw new IOException("请求结果为空");
}
String header = execute.header("content-type", "text/html; charset=UTF-8");
if (header != null) {
str = header;
}
String[] split = str.split(";");
String str2 = split[0];
String str3 = "";
if (split.length > 1) {
String[] split2 = split[1].split("=");
if (split2.length > 1) {
str3 = split2[1];
}
}
ResponseBody body = execute.body();
if (str2.equals("text/html")) {
return new WebResourceResponse(str2, str3, body.byteStream());
}
return new WebResourceResponse(str2, str3, body.byteStream());
} catch (IOException e) {
e.printStackTrace();
Crashes.trackError(e);
return null;
}
}
public FormBody buildForm(WebViewRequest webViewRequest) {
Map<String, String> formParameters = webViewRequest.getFormParameters();
FormBody.Builder builder = new FormBody.Builder();
for (Map.Entry<String, String> entry : formParameters.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
return builder.build();
}
@Override
public void onPageFinished(WebView webView, String str) {
UConfigActivity.this.progress.setVisibility(8);
UConfigActivity.this.loaded = true;
}
}
static class AnonymousClass1 {
static final int[] $SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType;
static {
int[] iArr = new int[WebViewRequestType.values().length];
$SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType = iArr;
try {
iArr[WebViewRequestType.FETCH.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType[WebViewRequestType.HTML.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType[WebViewRequestType.XML_HTTP.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$com$acsbendi$requestinspectorwebview$WebViewRequestType[WebViewRequestType.FORM.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
}
}
}