Clean thunder code

pull/137/head
FongMi 2 years ago
parent facc90e115
commit 084315191b
  1. 1
      app/build.gradle
  2. 8
      thunder/build.gradle
  3. 62
      thunder/src/main/java/com/xunlei/downloadlib/XLTaskHelper.java
  4. 8
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java
  5. 106
      thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskInfo.java

@ -84,6 +84,7 @@ dependencies {
implementation project(':tvbus')
implementation project(':catvod')
implementation project(':quickjs')
implementation project(':thunder')
implementation project(':jianpian')
implementation project(':forcetech')
implementation project(':ijkplayer')

@ -8,11 +8,3 @@ android {
targetSdkVersion 28
}
}
dependencies {
implementation 'androidx.annotation:annotation:' + annotationVersion
implementation 'com.google.code.gson:gson:' + gsonVersion
}

@ -6,8 +6,6 @@ import android.os.Handler;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.Nullable;
import com.xunlei.downloadlib.parameter.BtIndexSet;
import com.xunlei.downloadlib.parameter.BtSubTaskDetail;
import com.xunlei.downloadlib.parameter.BtTaskParam;
@ -66,7 +64,7 @@ public class XLTaskHelper {
downloadManager.setSpeedLimit(-1, -1);
}
public synchronized long addThunderTask(String url, String savePath, @Nullable String fileName) {
public synchronized long addThunderTask(String url, String savePath, String fileName) {
if (url.startsWith("thunder://")) url = downloadManager.parserThunderUrl(url);
GetTaskId getTaskId = new GetTaskId();
if (TextUtils.isEmpty(fileName)) {
@ -106,29 +104,6 @@ public class XLTaskHelper {
return getTaskId.getTaskId();
}
public void addHeader(String key, String value) {
requestHeaders.add(Pair.create(key, value));
}
private Collection<Pair<String, String>> getHeaders() {
return Collections.unmodifiableList(this.requestHeaders);
}
private void addRequestHeadersToXlEngine(long taskId) {
for (Pair<String, String> pair : this.getHeaders()) {
if (!(pair.first == null || pair.second == null)) {
downloadManager.setHttpHeaderProperty(taskId, pair.first, pair.second);
}
}
}
public synchronized String getFileName(String url) {
if (url.startsWith("thunder://")) url = downloadManager.parserThunderUrl(url);
GetFileName getFileName = new GetFileName();
downloadManager.getFileNameFromUrl(url, getFileName);
return getFileName.getFileName();
}
public synchronized long addMagnetTask(String url, String savePath, String fileName) throws Exception {
if (url.startsWith("magnet:?")) {
if (TextUtils.isEmpty(fileName)) {
@ -151,12 +126,6 @@ public class XLTaskHelper {
}
}
public synchronized TorrentInfo getTorrentInfo(String torrentPath) {
TorrentInfo torrentInfo = new TorrentInfo();
downloadManager.getTorrentInfo(torrentPath, torrentInfo);
return torrentInfo;
}
public synchronized long addTorrentTask(String torrentPath, String savePath, int index) {
TorrentInfo torrentInfo = new TorrentInfo();
downloadManager.getTorrentInfo(torrentPath, torrentInfo);
@ -186,6 +155,35 @@ public class XLTaskHelper {
return getTaskId.getTaskId();
}
public void addHeader(String key, String value) {
requestHeaders.add(Pair.create(key, value));
}
private Collection<Pair<String, String>> getHeaders() {
return Collections.unmodifiableList(this.requestHeaders);
}
private void addRequestHeadersToXlEngine(long taskId) {
for (Pair<String, String> pair : this.getHeaders()) {
if (!(pair.first == null || pair.second == null)) {
downloadManager.setHttpHeaderProperty(taskId, pair.first, pair.second);
}
}
}
public synchronized String getFileName(String url) {
if (url.startsWith("thunder://")) url = downloadManager.parserThunderUrl(url);
GetFileName getFileName = new GetFileName();
downloadManager.getFileNameFromUrl(url, getFileName);
return getFileName.getFileName();
}
public synchronized TorrentInfo getTorrentInfo(String torrentPath) {
TorrentInfo torrentInfo = new TorrentInfo();
downloadManager.getTorrentInfo(torrentPath, torrentInfo);
return torrentInfo;
}
public synchronized String getLocalUrl(String filePath) {
XLTaskLocalUrl localUrl = new XLTaskLocalUrl();
downloadManager.getLocalUrl(filePath, localUrl);

@ -1,5 +1,7 @@
package com.xunlei.downloadlib.parameter;
import android.text.TextUtils;
public class TorrentFileInfo {
public int mFileIndex;
@ -17,7 +19,7 @@ public class TorrentFileInfo {
}
public String getFileName() {
return mFileName;
return TextUtils.isEmpty(mFileName) ? "" : mFileName;
}
public long getFileSize() {
@ -47,4 +49,8 @@ public class TorrentFileInfo {
public boolean isSelected() {
return isSelected;
}
public String getExt() {
return getFileName().contains(".") ? getFileName().substring(getFileName().lastIndexOf(".") + 1) : "";
}
}

@ -74,10 +74,107 @@ public class XLTaskInfo implements Parcelable {
this.mScdnRecvBytes = parcel.readLong();
}
public int describeContents() {
return 0;
public int getAdditionalResCount() {
return mAdditionalResCount;
}
public long getAdditionalResPeerBytes() {
return mAdditionalResPeerBytes;
}
public long getAdditionalResPeerSpeed() {
return mAdditionalResPeerSpeed;
}
public int getAdditionalResType() {
return mAdditionalResType;
}
public long getAdditionalResVipRecvBytes() {
return mAdditionalResVipRecvBytes;
}
public long getAdditionalResVipSpeed() {
return mAdditionalResVipSpeed;
}
public String getCid() {
return mCid;
}
public long getDownloadSize() {
return mDownloadSize;
}
public long getDownloadSpeed() {
return mDownloadSpeed;
}
public int getErrorCode() {
return mErrorCode;
}
public String getFileName() {
return mFileName;
}
public long getFileSize() {
return mFileSize;
}
public String getGcid() {
return mGcid;
}
public int getInfoLen() {
return mInfoLen;
}
public long getOriginRecvBytes() {
return mOriginRecvBytes;
}
public long getOriginSpeed() {
return mOriginSpeed;
}
public long getP2PRecvBytes() {
return mP2PRecvBytes;
}
public long getP2PSpeed() {
return mP2PSpeed;
}
public long getP2SRecvBytes() {
return mP2SRecvBytes;
}
public long getP2SSpeed() {
return mP2SSpeed;
}
public int getQueryIndexStatus() {
return mQueryIndexStatus;
}
public long getScdnRecvBytes() {
return mScdnRecvBytes;
}
public long getScdnSpeed() {
return mScdnSpeed;
}
public long getTaskId() {
return mTaskId;
}
public int getTaskStatus() {
return mTaskStatus;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(this.mTaskId);
parcel.writeString(this.mFileName);
@ -105,4 +202,9 @@ public class XLTaskInfo implements Parcelable {
parcel.writeLong(this.mScdnSpeed);
parcel.writeLong(this.mScdnRecvBytes);
}
@Override
public int describeContents() {
return 0;
}
}

Loading…
Cancel
Save