Clean code

This commit is contained in:
FongMi 2022-11-30 23:20:48 +08:00
parent 42fa76afef
commit d3dfc82c1d
2 changed files with 8 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package com.github.catvod.bean.alist;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.bean.Class; import com.github.catvod.bean.Class;
import com.github.catvod.net.OkHttpUtil;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -47,6 +48,7 @@ public class Drive {
} }
public int getVersion() { public int getVersion() {
checkVersion();
return version; return version;
} }
@ -82,6 +84,10 @@ public class Drive {
return getServer() + "/search?box=" + param + "&url="; return getServer() + "/search?box=" + param + "&url=";
} }
private void checkVersion() {
if (getVersion() == 0) setVersion(OkHttpUtil.string(settingsApi()).contains("v3.") ? 3 : 2);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) return true; if (this == obj) return true;

View File

@ -47,14 +47,8 @@ public class AList extends Spider {
drives = Drive.objectFrom(ext).getDrives(); drives = Drive.objectFrom(ext).getDrives();
} }
private Drive checkVersion(Drive drive) {
if (drive.getVersion() == 0) drive.setVersion(OkHttpUtil.string(drive.settingsApi()).contains("v3.") ? 3 : 2);
return drive;
}
private Drive getDrive(String name) { private Drive getDrive(String name) {
Drive drive = drives.get(drives.indexOf(new Drive(name))); return drives.get(drives.indexOf(new Drive(name)));
return checkVersion(drive);
} }
@Override @Override
@ -125,7 +119,7 @@ public class AList extends Spider {
fetchRule(); fetchRule();
List<Vod> list = new ArrayList<>(); List<Vod> list = new ArrayList<>();
CountDownLatch cd = new CountDownLatch(drives.size()); CountDownLatch cd = new CountDownLatch(drives.size());
for (Drive drive : drives) new Thread(() -> search(cd, list, checkVersion(drive), keyword)).start(); for (Drive drive : drives) new Thread(() -> search(cd, list, drive, keyword)).start();
cd.await(); cd.await();
return Result.string(list); return Result.string(list);
} }