Update ali cache path
This commit is contained in:
parent
c95a8119d1
commit
eefb8bb92d
|
|
@ -26,7 +26,7 @@ import com.github.catvod.net.OkHttp;
|
||||||
import com.github.catvod.net.OkResult;
|
import com.github.catvod.net.OkResult;
|
||||||
import com.github.catvod.spider.Init;
|
import com.github.catvod.spider.Init;
|
||||||
import com.github.catvod.spider.Proxy;
|
import com.github.catvod.spider.Proxy;
|
||||||
import com.github.catvod.utils.Prefers;
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.github.catvod.utils.QRCode;
|
import com.github.catvod.utils.QRCode;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
|
||||||
|
|
@ -34,6 +34,7 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -66,10 +67,18 @@ public class API {
|
||||||
return Loader.INSTANCE;
|
return Loader.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getUserCache() {
|
||||||
|
return FileUtil.getCacheFile("aliyundrive_user");
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getOAuthCache() {
|
||||||
|
return FileUtil.getCacheFile("aliyundrive_oauth");
|
||||||
|
}
|
||||||
|
|
||||||
private API() {
|
private API() {
|
||||||
tempIds = new ArrayList<>();
|
tempIds = new ArrayList<>();
|
||||||
oauth = OAuth.objectFrom(Prefers.getString("aliyundrive_oauth"));
|
oauth = OAuth.objectFrom(FileUtil.read(getOAuthCache()));
|
||||||
user = User.objectFrom(Prefers.getString("aliyundrive_user"));
|
user = User.objectFrom(FileUtil.read(getUserCache()));
|
||||||
quality = new HashMap<>();
|
quality = new HashMap<>();
|
||||||
quality.put("4K", "UHD");
|
quality.put("4K", "UHD");
|
||||||
quality.put("2k", "QHD");
|
quality.put("2k", "QHD");
|
||||||
|
|
@ -432,9 +441,7 @@ public class API {
|
||||||
if (Utils.isMobile()) {
|
if (Utils.isMobile()) {
|
||||||
Init.run(this::showInput);
|
Init.run(this::showInput);
|
||||||
} else {
|
} else {
|
||||||
String url = "https://passport.aliyundrive.com/newlogin/qrcode/generate.do?appName=aliyun_drive&fromSite=52&appName=aliyun_drive&appEntrance=web&isMobile=false&lang=zh_CN&returnUrl=&bizParams=&_bx-v=2.2.3";
|
showQRCode();
|
||||||
Data data = Data.objectFrom(OkHttp.string(url)).getContent().getData();
|
|
||||||
Init.run(() -> showQRCode(data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,13 +452,18 @@ 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).setNeutralButton("QRCode", (dialog, which) -> onNeutral()).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onNeutral() {
|
||||||
|
dismiss();
|
||||||
|
Init.execute(this::showQRCode);
|
||||||
|
}
|
||||||
|
|
||||||
private void onPositive(String text) {
|
private void onPositive(String text) {
|
||||||
dialog.dismiss();
|
dismiss();
|
||||||
Init.execute(() -> {
|
Init.execute(() -> {
|
||||||
if (text.startsWith("http")) setToken(OkHttp.string(text));
|
if (text.startsWith("http")) setToken(OkHttp.string(text));
|
||||||
else if (text.length() == 32) setToken(text);
|
else if (text.length() == 32) setToken(text);
|
||||||
|
|
@ -459,6 +471,12 @@ public class API {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showQRCode() {
|
||||||
|
String url = "https://passport.aliyundrive.com/newlogin/qrcode/generate.do?appName=aliyun_drive&fromSite=52&appName=aliyun_drive&appEntrance=web&isMobile=false&lang=zh_CN&returnUrl=&bizParams=&_bx-v=2.2.3";
|
||||||
|
Data data = Data.objectFrom(OkHttp.string(url)).getContent().getData();
|
||||||
|
Init.run(() -> showQRCode(data));
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.utils.Prefers;
|
import com.github.catvod.ali.API;
|
||||||
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ public class OAuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuth save() {
|
public OAuth save() {
|
||||||
Prefers.put("aliyundrive_oauth", toString());
|
FileUtil.write(API.get().getOAuthCache(), toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ package com.github.catvod.bean.ali;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.utils.Prefers;
|
import com.github.catvod.ali.API;
|
||||||
|
import com.github.catvod.utils.FileUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
|
@ -59,7 +60,7 @@ public class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public User save() {
|
public User save() {
|
||||||
Prefers.put("aliyundrive_user", toString());
|
FileUtil.write(API.get().getUserCache(), toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.github.catvod.utils;
|
||||||
|
|
||||||
|
import com.github.catvod.spider.Init;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class FileUtil {
|
||||||
|
|
||||||
|
public static File getCacheDir() {
|
||||||
|
return Init.context().getExternalCacheDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getCacheFile(String fileName) {
|
||||||
|
return new File(getCacheDir(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(File file, String data) {
|
||||||
|
write(file, data.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(File file, byte[] data) {
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
fos.write(data);
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String read(File file) {
|
||||||
|
try {
|
||||||
|
return read(new FileInputStream(file));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String read(InputStream is) {
|
||||||
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String text;
|
||||||
|
while ((text = br.readLine()) != null) sb.append(text).append("\n");
|
||||||
|
br.close();
|
||||||
|
return Utils.substring(sb.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -144,15 +144,6 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeView(View view) {
|
|
||||||
try {
|
|
||||||
ViewGroup group = Init.getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
|
|
||||||
group.removeView(view);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadWebView(String url, WebViewClient client) {
|
public static void loadWebView(String url, WebViewClient client) {
|
||||||
Init.run(() -> {
|
Init.run(() -> {
|
||||||
WebView webView = new WebView(Init.context());
|
WebView webView = new WebView(Init.context());
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
3943d051cc917b936cbfa116baf94a74
|
14916e05a5fabbc24aad217565c93f7b
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue