Clean code

This commit is contained in:
FongMi 2023-05-03 17:58:09 +08:00
parent 00714fd7fa
commit a3d41f8595
8 changed files with 29 additions and 137 deletions

View File

@ -44,6 +44,7 @@ import java.util.Map;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class API { public class API {
@ -151,6 +152,11 @@ public class API {
return true; return true;
} }
private boolean onTimeout() {
stopService();
return false;
}
public void checkAccessToken() { public void checkAccessToken() {
if (user.getAccessToken().isEmpty()) refreshAccessToken(); if (user.getAccessToken().isEmpty()) refreshAccessToken();
} }
@ -171,10 +177,11 @@ public class API {
if (oauth.getAccessToken().isEmpty()) oauthRequest(); if (oauth.getAccessToken().isEmpty()) oauthRequest();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
if (e instanceof TimeoutException) return onTimeout();
e.printStackTrace(); e.printStackTrace();
user.clean().save(); user.clean().save();
stopService(); stopService();
getQRCode(); startFlow();
return true; return true;
} finally { } finally {
while (user.getAccessToken().isEmpty()) SystemClock.sleep(250); while (user.getAccessToken().isEmpty()) SystemClock.sleep(250);
@ -421,7 +428,7 @@ public class API {
return result; return result;
} }
private void getQRCode() { private void startFlow() {
if (Utils.isMobile()) { if (Utils.isMobile()) {
Init.run(this::showInput); Init.run(this::showInput);
} else { } else {
@ -438,7 +445,7 @@ public class API {
FrameLayout frame = new FrameLayout(Init.context()); FrameLayout frame = new FrameLayout(Init.context());
EditText input = new EditText(Init.context()); EditText input = new EditText(Init.context());
frame.addView(input, params); 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) { } 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) { private void showQRCode(Data data) {
try { try {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240)); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240));

View File

@ -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);
});
}
};
}
}

View File

@ -35,7 +35,10 @@ public class Utils {
} }
public static boolean isMobile() { 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) { public static boolean isSub(String ext) {

Binary file not shown.

View File

@ -1 +1 @@
1cad1d2b01a603e950109d009a884da0 e1c6d4103c73f8fd333acdda1dfab6f7

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;1cad1d2b01a603e950109d009a884da0", "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;e1c6d4103c73f8fd333acdda1dfab6f7",
"wallpaper": "https://gao.chuqiuyu.tk", "wallpaper": "https://gao.chuqiuyu.tk",
"sites": [ "sites": [
{ {

View File

@ -1,70 +0,0 @@
{
"sites": [
{
"key": "紙條",
"name": "紙條",
"type": 3,
"api": "csp_Paper",
"searchable": 1,
"filterable": 1,
"changeable": 0,
"ext": "影視天下第一",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
},
{
"key": "易搜",
"name": "易搜",
"type": 3,
"api": "csp_YiSo",
"searchable": 1,
"filterable": 0,
"changeable": 0,
"ext": "影視天下第一",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
},
{
"key": "盤搜",
"name": "盤搜",
"type": 3,
"api": "csp_PanSou",
"searchable": 1,
"filterable": 0,
"changeable": 0,
"ext": "影視天下第一",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
},
{
"key": "UP雲搜",
"name": "UP雲搜",
"type": 3,
"api": "csp_UpYun",
"searchable": 1,
"filterable": 0,
"changeable": 0,
"ext": "影視天下第一",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
},
{
"key": "找資源",
"name": "找資源",
"type": 3,
"api": "csp_Zhaozy",
"searchable": 1,
"filterable": 0,
"changeable": 0,
"ext": "影視天下第一$$$test2$$$test2",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
},
{
"key": "push_agent",
"name": "推送",
"type": 3,
"api": "csp_Push",
"searchable": 1,
"filterable": 0,
"changeable": 0,
"ext": "影視天下第一",
"jar": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar"
}
]
}

View File

@ -1,5 +1,5 @@
{ {
"spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;1cad1d2b01a603e950109d009a884da0", "spider": "https://raw.githubusercontent.com/FongMi/CatVodSpider/main/jar/custom_spider.jar;md5;e1c6d4103c73f8fd333acdda1dfab6f7",
"wallpaper": "http://饭太硬.ga/深色壁纸/api.php", "wallpaper": "http://饭太硬.ga/深色壁纸/api.php",
"sites": [ "sites": [
{ {
@ -88,10 +88,10 @@
"changeable": 0 "changeable": 0
}, },
{ {
"key": "搜", "key": "搜",
"name": "搜", "name": "搜",
"type": 3, "type": 3,
"api": "csp_YiSo", "api": "csp_UpYun",
"searchable": 1, "searchable": 1,
"filterable": 0, "filterable": 0,
"changeable": 0 "changeable": 0
@ -114,15 +114,6 @@
"filterable": 0, "filterable": 0,
"changeable": 0 "changeable": 0
}, },
{
"key": "UP雲搜",
"name": "UP雲搜",
"type": 3,
"api": "csp_UpYun",
"searchable": 1,
"filterable": 0,
"changeable": 0
},
{ {
"key": "找資源", "key": "找資源",
"name": "找資源", "name": "找資源",