[modile] clean code

pull/137/head
FongMi 2 years ago
parent fe0bddb687
commit 0724564966
  1. 17
      app/src/main/java/com/fongmi/android/tv/bean/Episode.java
  2. 6
      app/src/main/java/com/fongmi/android/tv/bean/Result.java
  3. 9
      app/src/main/java/com/fongmi/android/tv/bean/Url.java
  4. 4
      app/src/main/java/com/fongmi/android/tv/bean/Value.java
  5. 2
      app/src/main/java/com/fongmi/android/tv/gson/UrlAdapter.java
  6. 15
      app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java
  7. 16
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java
  8. 1
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentInfo.java

@ -8,10 +8,6 @@ import com.github.catvod.utils.Trans;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Episode implements Parcelable {
@SerializedName("name")
@ -139,17 +135,4 @@ public class Episode implements Parcelable {
return new Episode[size];
}
};
public static class Sorter implements Comparator<Episode> {
public static List<Episode> sort(List<Episode> items) {
if (items.size() > 1) Collections.sort(items, new Sorter());
return items;
}
@Override
public int compare(Episode o1, Episode o2) {
return Integer.compare(o1.getNumber(), o2.getNumber());
}
}
}

@ -208,13 +208,17 @@ public class Result implements Parcelable {
}
public Url getUrl() {
return url == null ? new Url() : url;
return url == null ? Url.create() : url;
}
public void setUrl(Url url) {
this.url = url;
}
public void setUrl(String url) {
this.url = getUrl().replace(url);
}
public String getKey() {
return TextUtils.isEmpty(key) ? "" : key;
}

@ -10,6 +10,10 @@ public class Url {
private List<Value> values;
private int position;
public static Url create() {
return new Url();
}
public List<Value> getValues() {
return values = values == null ? new ArrayList<>() : values;
}
@ -40,6 +44,11 @@ public class Url {
return this;
}
public Url replace(String url) {
getValues().get(getPosition()).setV(url);
return this;
}
public Url set(int position) {
this.position = Math.min(position, getValues().size() - 1);
return this;

@ -32,6 +32,10 @@ public class Value implements Parcelable {
return TextUtils.isEmpty(v) ? "" : v;
}
public void setV(String v) {
this.v = v;
}
public boolean isActivated() {
return activated;
}

@ -13,7 +13,7 @@ public class UrlAdapter implements JsonDeserializer<Url> {
@Override
public Url deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Url url = new Url();
Url url = Url.create();
if (!json.isJsonArray()) return url.add(json.getAsString());
JsonArray array = json.getAsJsonArray();
for (int i = 0; i < array.size(); i += 2) url.add(array.get(i).getAsString(), array.get(i + 1).getAsString());

@ -15,6 +15,7 @@ import com.fongmi.android.tv.bean.Episode;
import com.fongmi.android.tv.bean.Flag;
import com.fongmi.android.tv.bean.Result;
import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.bean.Url;
import com.fongmi.android.tv.bean.Vod;
import com.fongmi.android.tv.exception.ExtractException;
import com.fongmi.android.tv.player.Source;
@ -154,7 +155,7 @@ public class SiteViewModel extends ViewModel {
ApiConfig.get().setRecent(site);
Result result = Result.fromJson(playerContent);
if (result.getFlag().isEmpty()) result.setFlag(flag);
result.setUrl(Source.get().fetch(result.getUrl()));
result.setUrl(Source.get().fetch(result.getUrl().v()));
result.setKey(key);
return result;
} else if (site.getType() == 4) {
@ -167,23 +168,23 @@ public class SiteViewModel extends ViewModel {
SpiderDebug.log(body);
Result result = Result.fromJson(body);
if (result.getFlag().isEmpty()) result.setFlag(flag);
result.setUrl(Source.get().fetch(result.getUrl()));
result.setUrl(Source.get().fetch(result.getUrl().v()));
return result;
} else if (site.isEmpty() && key.equals("push_agent")) {
Result result = new Result();
result.setParse(0);
result.setFlag(flag);
result.setUrl(Source.get().fetch(id));
result.setUrl(Source.get().fetch(result.getUrl().v()));
return result;
} else {
String url = id;
String type = Uri.parse(url).getQueryParameter("type");
Url url = Url.create().add(id);
String type = Uri.parse(id).getQueryParameter("type");
if (type != null && type.equals("json")) url = Result.fromJson(OkHttp.newCall(id).execute().body().string()).getUrl();
Result result = new Result();
result.setUrl(url);
result.setFlag(flag);
result.setPlayUrl(site.getPlayUrl());
result.setParse(Sniffer.isVideoFormat(url) && result.getPlayUrl().isEmpty() ? 0 : 1);
result.setParse(Sniffer.isVideoFormat(url.v()) && result.getPlayUrl().isEmpty() ? 0 : 1);
return result;
}
});
@ -246,7 +247,7 @@ public class SiteViewModel extends ViewModel {
private void checkThunder(List<Flag> flags) throws Exception {
for (Flag flag : flags) {
ExecutorService executor = Executors.newFixedThreadPool(Constant.THREAD_POOL * 2);
for (Future<List<Episode>> future : executor.invokeAll(flag.getMagnet(), 30, TimeUnit.SECONDS)) flag.getEpisodes().addAll(Episode.Sorter.sort(future.get()));
for (Future<List<Episode>> future : executor.invokeAll(flag.getMagnet(), 30, TimeUnit.SECONDS)) flag.getEpisodes().addAll(future.get());
executor.shutdownNow();
}
}

@ -5,6 +5,9 @@ import android.text.TextUtils;
import com.github.catvod.utils.Util;
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class TorrentFileInfo {
@ -48,4 +51,17 @@ public class TorrentFileInfo {
public String getExt() {
return getFileName().contains(".") ? getFileName().substring(getFileName().lastIndexOf(".") + 1).toLowerCase() : "";
}
public static class Sorter implements Comparator<TorrentFileInfo> {
public static List<TorrentFileInfo> sort(List<TorrentFileInfo> items) {
if (items.size() > 1) Collections.sort(items, new Sorter());
return items;
}
@Override
public int compare(TorrentFileInfo o1, TorrentFileInfo o2) {
return o1.getFileName().compareTo(o2.getFileName());
}
}
}

@ -30,6 +30,7 @@ public class TorrentInfo {
public List<TorrentFileInfo> getMedias(List<String> ads) {
List<TorrentFileInfo> items = new ArrayList<>();
for (TorrentFileInfo item : getSubFileInfo()) if (Util.isMedia(item.getExt()) && Util.notAd(ads, item.getFileName())) items.add(item.file(getFile()));
TorrentFileInfo.Sorter.sort(items);
return items;
}
}

Loading…
Cancel
Save