Clean code
This commit is contained in:
parent
cbd9f797eb
commit
8c869e2e62
|
|
@ -1,60 +0,0 @@
|
|||
package com.github.catvod.bean.ali;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Code {
|
||||
|
||||
@SerializedName("data")
|
||||
private Data data;
|
||||
@SerializedName("pds_login_result")
|
||||
private Data result;
|
||||
|
||||
public static Code objectFrom(String str) {
|
||||
try {
|
||||
return new Gson().fromJson(str, Code.class);
|
||||
} catch (Exception e) {
|
||||
return new Code();
|
||||
}
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data == null ? new Data() : data;
|
||||
}
|
||||
|
||||
public Data getResult() {
|
||||
return result == null ? new Data() : result;
|
||||
}
|
||||
|
||||
public boolean hasToken() {
|
||||
return getResult().getRefreshToken().length() > 0;
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
|
||||
@SerializedName("t")
|
||||
private String t;
|
||||
@SerializedName("ck")
|
||||
private String ck;
|
||||
@SerializedName("codeContent")
|
||||
private String codeContent;
|
||||
@SerializedName("refreshToken")
|
||||
private String refreshToken;
|
||||
|
||||
public String getT() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public String getCk() {
|
||||
return ck;
|
||||
}
|
||||
|
||||
public String getCodeContent() {
|
||||
return codeContent == null ? "" : codeContent;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken == null ? "" : refreshToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.github.catvod.bean.ali;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Data {
|
||||
|
||||
@SerializedName(value = "data", alternate = "pds_login_result")
|
||||
private Data data;
|
||||
@SerializedName("t")
|
||||
private String t;
|
||||
@SerializedName("ck")
|
||||
private String ck;
|
||||
@SerializedName("codeContent")
|
||||
private String codeContent;
|
||||
@SerializedName("refreshToken")
|
||||
private String refreshToken;
|
||||
|
||||
public static Data objectFrom(String str) {
|
||||
try {
|
||||
return new Gson().fromJson(str, Data.class);
|
||||
} catch (Exception e) {
|
||||
return new Data();
|
||||
}
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data == null ? new Data() : data;
|
||||
}
|
||||
|
||||
public boolean hasToken() {
|
||||
return getData().getRefreshToken().length() > 0;
|
||||
}
|
||||
|
||||
public String getT() {
|
||||
return t == null ? "" : t;
|
||||
}
|
||||
|
||||
public String getCk() {
|
||||
return ck == null ? "" : ck;
|
||||
}
|
||||
|
||||
public String getCodeContent() {
|
||||
return codeContent == null ? "" : codeContent;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken == null ? "" : refreshToken;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import android.widget.ImageView;
|
|||
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.Vod;
|
||||
import com.github.catvod.bean.ali.Code;
|
||||
import com.github.catvod.bean.ali.Data;
|
||||
import com.github.catvod.bean.ali.Item;
|
||||
import com.github.catvod.net.OkHttpUtil;
|
||||
import com.github.catvod.utils.Misc;
|
||||
|
|
@ -178,7 +178,7 @@ public class Ali {
|
|||
accessToken = null;
|
||||
e.printStackTrace();
|
||||
checkService();
|
||||
getToken();
|
||||
getQRCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -280,31 +280,31 @@ public class Ali {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void getToken() {
|
||||
Code code = Code.objectFrom(OkHttpUtil.string("https://easy-token.cooluc.com/qr"));
|
||||
Init.run(() -> showQRCode(code.getData().getCodeContent()));
|
||||
service = Executors.newScheduledThreadPool(1);
|
||||
service.scheduleAtFixedRate(() -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("t", code.getData().getT());
|
||||
params.addProperty("ck", code.getData().getCk());
|
||||
Code result = Code.objectFrom(OkHttpUtil.postJson("https://easy-token.cooluc.com/ck", params.toString()));
|
||||
if (result.hasToken()) saveToken(result.getResult().getRefreshToken());
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void checkService() {
|
||||
if (service != null) service.shutdownNow();
|
||||
if (view != null) Init.run(() -> Misc.removeView(view));
|
||||
}
|
||||
|
||||
private void saveToken(String value) {
|
||||
private void getQRCode() {
|
||||
Data data = Data.objectFrom(OkHttpUtil.string("https://easy-token.cooluc.com/qr"));
|
||||
Init.run(() -> showCode(data.getData().getCodeContent()));
|
||||
service = Executors.newScheduledThreadPool(1);
|
||||
service.scheduleAtFixedRate(() -> {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("t", data.getData().getT());
|
||||
params.addProperty("ck", data.getData().getCk());
|
||||
Data result = Data.objectFrom(OkHttpUtil.postJson("https://easy-token.cooluc.com/ck", params.toString()));
|
||||
if (result.hasToken()) setToken(result.getData().getRefreshToken());
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void setToken(String value) {
|
||||
Prefers.put("token", refreshToken = value);
|
||||
Init.show("請重新進入播放頁");
|
||||
checkService();
|
||||
}
|
||||
|
||||
private void showQRCode(String text) {
|
||||
private void showCode(String text) {
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
params.gravity = Gravity.CENTER;
|
||||
Misc.addView(view = create(text), params);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
3972c08cf395106d2d7d58cf1076b5e0
|
||||
012fedf8372acec517e0d3f2cfdc4d6b
|
||||
|
|
|
|||
Loading…
Reference in New Issue