Clean code
This commit is contained in:
parent
7378fb0a2f
commit
5596625d3c
|
|
@ -44,6 +44,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class API {
|
||||
|
||||
|
|
@ -151,6 +152,11 @@ public class API {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean onTimeout() {
|
||||
stopService();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkAccessToken() {
|
||||
if (user.getAccessToken().isEmpty()) refreshAccessToken();
|
||||
}
|
||||
|
|
@ -171,10 +177,11 @@ public class API {
|
|||
if (oauth.getAccessToken().isEmpty()) oauthRequest();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (e instanceof TimeoutException) return onTimeout();
|
||||
e.printStackTrace();
|
||||
user.clean().save();
|
||||
stopService();
|
||||
getQRCode();
|
||||
startFlow();
|
||||
return true;
|
||||
} finally {
|
||||
while (user.getAccessToken().isEmpty()) SystemClock.sleep(250);
|
||||
|
|
@ -421,7 +428,7 @@ public class API {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void getQRCode() {
|
||||
private void startFlow() {
|
||||
if (Utils.isMobile()) {
|
||||
Init.run(this::showInput);
|
||||
} else {
|
||||
|
|
@ -438,7 +445,7 @@ public class API {
|
|||
FrameLayout frame = new FrameLayout(Init.context());
|
||||
EditText input = new EditText(Init.context());
|
||||
frame.addView(input, params);
|
||||
dialog = new AlertDialog.Builder(Init.getActivity()).setTitle("請輸入Token").setView(frame).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show();
|
||||
dialog = new AlertDialog.Builder(Init.getActivity()).setTitle("請輸入Token").setView(frame).setNegativeButton(android.R.string.cancel, (dialog, which) -> onNegative()).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
|
@ -452,6 +459,15 @@ public class API {
|
|||
});
|
||||
}
|
||||
|
||||
private void onNegative() {
|
||||
try {
|
||||
dialog.dismiss();
|
||||
Init.getActivity().finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void showQRCode(Data data) {
|
||||
try {
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240));
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
package com.github.catvod.spider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.yiso.Item;
|
||||
import com.github.catvod.utils.Utils;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class YiSo extends Ali {
|
||||
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
super.init(context, extend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String searchContent(String key, boolean quick) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return "";
|
||||
String url = "https://yiso.fun/api/search?name=" + URLEncoder.encode(key) + "&from=ali";
|
||||
Map<String, String> result = new HashMap<>();
|
||||
Utils.loadWebView(url, getWebViewClient(result));
|
||||
while (!result.containsKey("json")) SystemClock.sleep(50);
|
||||
String json = JsonParser.parseString(Objects.requireNonNull(result.get("json"))).getAsJsonPrimitive().getAsString();
|
||||
return Result.string(Item.objectFrom(json).getData().getList(key));
|
||||
}
|
||||
|
||||
private WebViewClient getWebViewClient(Map<String, String> result) {
|
||||
return new WebViewClient() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
|
||||
view.evaluateJavascript("document.getElementsByTagName('pre')[0].textContent", value -> {
|
||||
if (!value.equals("null")) result.put("json", value);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,10 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static boolean isMobile() {
|
||||
return Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
||||
boolean hasCamera = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
||||
boolean hasPhone = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
||||
boolean hasBT = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
||||
return hasCamera && hasPhone && hasBT;
|
||||
}
|
||||
|
||||
public static boolean isSub(String ext) {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
1cad1d2b01a603e950109d009a884da0
|
||||
e1c6d4103c73f8fd333acdda1dfab6f7
|
||||
|
|
|
|||
Loading…
Reference in New Issue