├── README.md ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── layout │ │ │ │ ├── download_fragment_layout.xml │ │ │ │ ├── download_list_item.xml │ │ │ │ ├── home_layout.xml │ │ │ │ └── activity_main.xml │ │ │ └── values-zh-rCN │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ghost │ │ │ │ └── thunder │ │ │ │ ├── ui │ │ │ │ ├── UserFragment.java │ │ │ │ ├── DownLoadListFragment.java │ │ │ │ └── HomeFragment.java │ │ │ │ ├── data │ │ │ │ ├── DownLoadDataBaseColumns.java │ │ │ │ ├── DownLoadDataBase.java │ │ │ │ └── DownLoadDBUtil.java │ │ │ │ ├── download │ │ │ │ ├── DownLoadProgressListener.java │ │ │ │ └── DownLoadUtil.java │ │ │ │ ├── utils │ │ │ │ ├── UrlUtils.java │ │ │ │ ├── UrlType.java │ │ │ │ ├── FragmentUtils.java │ │ │ │ ├── LogPrinter.java │ │ │ │ └── StorageUtils.java │ │ │ │ ├── adapter │ │ │ │ ├── MyPageAdapter.java │ │ │ │ └── DownLoadListAdapter.java │ │ │ │ ├── MyApp.java │ │ │ │ └── app │ │ │ │ ├── MainActivity.java │ │ │ │ ├── PermissionActivity.java │ │ │ │ └── BaseActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ghost │ │ │ └── thunder │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ghost │ │ └── thunder │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── thunder ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── jniLibs │ │ │ └── armeabi │ │ │ │ ├── libxl_stat.so │ │ │ │ ├── libxluagc.so │ │ │ │ └── libxl_thunder_sdk.so │ │ ├── java │ │ │ └── com │ │ │ │ └── xunlei │ │ │ │ └── downloadlib │ │ │ │ ├── parameter │ │ │ │ ├── XLTaskLocalUrl.java │ │ │ │ ├── MaxDownloadSpeedParam.java │ │ │ │ ├── GetDownloadLibVersion.java │ │ │ │ ├── XLSessionInfo.java │ │ │ │ ├── GetDownloadHead.java │ │ │ │ ├── GetTaskId.java │ │ │ │ ├── BtSubTaskDetail.java │ │ │ │ ├── BtIndexSet.java │ │ │ │ ├── BtTaskStatus.java │ │ │ │ ├── GetFileName.java │ │ │ │ ├── UrlQuickInfo.java │ │ │ │ ├── ThunderUrlInfo.java │ │ │ │ ├── XLProductInfo.java │ │ │ │ ├── XLTaskInfoEx.java │ │ │ │ ├── TorrentFileInfo.java │ │ │ │ ├── InitParam.java │ │ │ │ ├── MagnetTaskParam.java │ │ │ │ ├── TorrentInfo.java │ │ │ │ ├── ServerResourceParam.java │ │ │ │ ├── EmuleTaskParam.java │ │ │ │ ├── BtTaskParam.java │ │ │ │ ├── CIDTaskParam.java │ │ │ │ ├── P2spTaskParam.java │ │ │ │ ├── PeerResourceParam.java │ │ │ │ ├── XLTaskInfo.java │ │ │ │ ├── ErrorCodeToMsg.java │ │ │ │ └── XLConstant.java │ │ │ │ ├── BlockingItem.java │ │ │ │ ├── android │ │ │ │ ├── LogLevel.java │ │ │ │ ├── XLLog.java │ │ │ │ ├── LogConfig.java │ │ │ │ ├── XLLogInternal.java │ │ │ │ └── XLUtil.java │ │ │ │ ├── Daemon.java │ │ │ │ ├── LinuxFileCommand.java │ │ │ │ ├── XLAppKeyChecker.java │ │ │ │ ├── XLLoader.java │ │ │ │ └── XLTaskHelper.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ghost │ │ │ └── thunder │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ghost │ │ └── thunder │ │ └── ExampleInstrumentedTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── runConfigurations.xml ├── compiler.xml ├── modules.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── gradlew └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # BtPlayer 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /thunder/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':thunder' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BtPlayer 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /thunder/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | thunder 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /thunder/src/main/jniLibs/armeabi/libxl_stat.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxl_stat.so -------------------------------------------------------------------------------- /thunder/src/main/jniLibs/armeabi/libxluagc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxluagc.so -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /thunder/src/main/jniLibs/armeabi/libxl_thunder_sdk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuntaoWei/BtPlayer/HEAD/thunder/src/main/jniLibs/armeabi/libxl_thunder_sdk.so -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskLocalUrl.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class XLTaskLocalUrl { 4 | public String mStrUrl; 5 | } 6 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/MaxDownloadSpeedParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class MaxDownloadSpeedParam { 4 | public long mSpeed; 5 | } 6 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/GetDownloadLibVersion.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class GetDownloadLibVersion { 4 | public String mVersion = null; 5 | } 6 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/XLSessionInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class XLSessionInfo { 4 | public long mSendByte; 5 | public long mStartTime; 6 | } 7 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/GetDownloadHead.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class GetDownloadHead { 4 | public String mHttpResponse = null; 5 | public int mHttpState = -1; 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/ui/UserFragment.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.ui; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | /** 6 | * Created by wyt on 2018/8/9. 7 | */ 8 | 9 | public class UserFragment extends Fragment { 10 | } 11 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/GetTaskId.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class GetTaskId { 4 | private long mTaskId; 5 | 6 | public long getTaskId() { 7 | return this.mTaskId; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/BtSubTaskDetail.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class BtSubTaskDetail { 4 | public int mFileIndex; 5 | public boolean mIsSelect; 6 | public XLTaskInfo mTaskInfo = new XLTaskInfo(); 7 | } 8 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/BtIndexSet.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class BtIndexSet { 4 | public int[] mIndexSet; 5 | 6 | public BtIndexSet(int i) { 7 | this.mIndexSet = new int[i]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/BtTaskStatus.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class BtTaskStatus { 4 | public int[] mStatus; 5 | 6 | public BtTaskStatus(int i) { 7 | this.mStatus = new int[i]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/GetFileName.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class GetFileName { 4 | private String mFileName; 5 | 6 | public String getFileName() { 7 | return this.mFileName; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 09 19:25:00 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/UrlQuickInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class UrlQuickInfo { 4 | public String mContentType; 5 | public String mFileNameAdvice; 6 | public long mFileSize; 7 | public int mState; 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #CCCCCC 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 57dp 5 | 6 | 15sp 7 | 8 | 18sp 9 | 10 | 21sp 11 | 12 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/ThunderUrlInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class ThunderUrlInfo { 4 | public String mUrl; 5 | 6 | public ThunderUrlInfo() { 7 | } 8 | 9 | public ThunderUrlInfo(String str) { 10 | this.mUrl = str; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/XLProductInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class XLProductInfo { 4 | public String mProductKey; 5 | public String mProductName; 6 | 7 | public XLProductInfo(String str, String str2) { 8 | this.mProductKey = str; 9 | this.mProductName = str2; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskInfoEx.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class XLTaskInfoEx { 4 | public int mErrorCode; 5 | public int mInfoLen; 6 | public int mOriginResState; 7 | public int mP2pAbandonTotal; 8 | public int mP2pUsedTotal; 9 | public int mP2sAbandonTotal; 10 | public int mP2sUsedTotal; 11 | public long mTaskId; 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/download_fragment_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/ghost/thunder/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /thunder/src/test/java/com/ghost/thunder/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/data/DownLoadDataBaseColumns.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.data; 2 | 3 | /** 4 | * Created by yuntao.wei on 2018/8/15. 5 | * github:https://github.com/YuntaoWei 6 | * blog:http://blog.csdn.net/qq_17541215 7 | */ 8 | 9 | public class DownLoadDataBaseColumns { 10 | 11 | public static final String ID = "_id"; 12 | public static final String NAME = "file_name"; 13 | public static final String SAVE_PATH = "_path"; 14 | public static final String URL = "_url"; 15 | public static final String PROGRESS = "_progress"; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/download/DownLoadProgressListener.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.download; 2 | 3 | /** 4 | * Created by yuntao.wei on 2018/8/9. 5 | * github:https://github.com/YuntaoWei 6 | * blog:http://blog.csdn.net/qq_17541215 7 | */ 8 | 9 | public interface DownLoadProgressListener { 10 | 11 | void onProgressChange(String totalSize, String downloadedSize, String downSpeed); 12 | 13 | void onProgressChangeRealSize(long totalSize, long downloadedSize, long downSpeed); 14 | 15 | void onDonwloadEnd(String filePath); 16 | 17 | void onTaskStart(String fileName); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/utils/UrlUtils.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.utils; 2 | 3 | /** 4 | * Created by yuntao.wei on 2018/8/9. 5 | * github:https://github.com/YuntaoWei 6 | * blog:http://blog.csdn.net/qq_17541215 7 | */ 8 | 9 | public class UrlUtils { 10 | 11 | public static boolean isValidUrl(String url) { 12 | if (url.startsWith(UrlType.TYPE_THUNDER_URL)) 13 | return true; 14 | else if(url.startsWith(UrlType.TYPE_MAGNET_URL)) 15 | return true; 16 | else if(url.endsWith(UrlType.TYPE_TORRENT_FILE)) 17 | return true; 18 | 19 | return false; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | "BtPlayer" 5 | 6 | "请输入thunder/magnet/ftp/torrent链接" 7 | 8 | "无法解析这种类型的链接" 9 | 10 | "开始下载" 11 | 12 | "添加torrent" 13 | 14 | "主页" 15 | 16 | "下载列表" 17 | 18 | "用户" 19 | 20 | "请输入链接再进行下载" 21 | 22 | "解析异常" 23 | 24 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class TorrentFileInfo { 4 | public int mFileIndex; 5 | public String mFileName; 6 | public long mFileSize; 7 | public int mRealIndex; 8 | public String mSubPath; 9 | public String playUrl; 10 | public String hash; 11 | 12 | @Override 13 | public String toString() { 14 | return "File index : " + mFileIndex + "\n" 15 | + "File name : " + mFileName + "\n" 16 | + "File size : " + mFileSize + "\n" 17 | + "Real index : " + mRealIndex + "\n" 18 | + "Sub path : " + mSubPath + "\n" 19 | + "Play url : " + playUrl + "\n" 20 | + "hash value : " + hash; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /thunder/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/adapter/MyPageAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by wyt on 2018/8/9. 11 | */ 12 | 13 | public class MyPageAdapter extends FragmentPagerAdapter { 14 | 15 | private List fragments; 16 | 17 | public MyPageAdapter(FragmentManager fm) { 18 | super(fm); 19 | } 20 | 21 | public void setFragment(List fragments) { 22 | this.fragments = fragments; 23 | } 24 | 25 | @Override 26 | public Fragment getItem(int position) { 27 | return fragments.get(position); 28 | } 29 | 30 | @Override 31 | public int getCount() { 32 | return fragments.size(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ghost/thunder/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ghost.thunder", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /thunder/src/androidTest/java/com/ghost/thunder/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ghost.thunder.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/InitParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class InitParam { 4 | public String mAppKey; 5 | public String mAppVersion; 6 | public int mPermissionLevel; 7 | public String mStatCfgSavePath; 8 | public String mStatSavePath; 9 | 10 | public InitParam(String str, String str2, String str3, String str4, int i) { 11 | this.mAppKey = str; 12 | this.mAppVersion = str2; 13 | this.mStatSavePath = str3; 14 | this.mStatCfgSavePath = str4; 15 | this.mPermissionLevel = i; 16 | } 17 | 18 | public InitParam() { 19 | } 20 | 21 | public boolean checkMemberVar() { 22 | if (this.mAppKey == null || this.mAppVersion == null || this.mStatSavePath == null || this.mStatCfgSavePath == null) { 23 | return false; 24 | } 25 | return true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Thu Aug 09 14:04:18 CST 2018 16 | systemProp.http.proxyHost=mirrors.neusoft.edu.cn 17 | org.gradle.jvmargs=-Xmx1536m 18 | systemProp.http.proxyPort=80 19 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/MagnetTaskParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class MagnetTaskParam { 4 | public String mFileName; 5 | public String mFilePath; 6 | public String mUrl; 7 | 8 | public MagnetTaskParam(String str, String str2, String str3) { 9 | this.mFileName = str; 10 | this.mFilePath = str2; 11 | this.mUrl = str3; 12 | } 13 | 14 | public MagnetTaskParam() { 15 | } 16 | 17 | public void setUrl(String str) { 18 | this.mUrl = str; 19 | } 20 | 21 | public void setFileName(String str) { 22 | this.mFileName = str; 23 | } 24 | 25 | public void setFilePath(String str) { 26 | this.mFilePath = str; 27 | } 28 | 29 | 30 | 31 | public boolean checkMemberVar() { 32 | if (this.mFileName == null || this.mFilePath == null || this.mUrl == null) { 33 | return false; 34 | } 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /thunder/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:25.3.1' 29 | compile 'io.reactivex:rxandroid:1.1.0' 30 | compile 'io.reactivex:rxjava:1.1.0' 31 | testCompile 'junit:junit:4.12' 32 | } 33 | -------------------------------------------------------------------------------- /thunder/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentInfo.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class TorrentInfo { 4 | public int mFileCount; 5 | public String mInfoHash; 6 | public boolean mIsMultiFiles; 7 | public String mMultiFileBaseFolder; 8 | public TorrentFileInfo[] mSubFileInfo; 9 | 10 | @Override 11 | public String toString() { 12 | StringBuilder childFileInfo = new StringBuilder(); 13 | childFileInfo.append("["); 14 | for (TorrentFileInfo info : mSubFileInfo 15 | ) { 16 | childFileInfo.append(info.toString() + "\n"); 17 | childFileInfo.append("------------------------"); 18 | } 19 | childFileInfo.append("]"); 20 | 21 | return "file count : " + mFileCount + "\n" 22 | + "Info Hash : " + mInfoHash + "\n" 23 | + "is muti files : " + mIsMultiFiles + "\n" 24 | + "muti file base folder : " + mMultiFileBaseFolder + "\n" 25 | + childFileInfo.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/MyApp.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder; 2 | 3 | import android.app.Application; 4 | import android.content.pm.PackageManager; 5 | import android.util.Log; 6 | 7 | /** 8 | * Created by oceanzhang on 2017/9/28. 9 | */ 10 | 11 | public class MyApp extends Application { 12 | 13 | public static MyApp instance = null; 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | instance = this; 19 | } 20 | 21 | public static MyApp appInstance() { 22 | return instance; 23 | } 24 | 25 | @Override 26 | public String getPackageName() { 27 | if (Log.getStackTraceString(new Throwable()).contains("com.xunlei.downloadlib")) { 28 | return "com.xunlei.downloadprovider"; 29 | } 30 | return super.getPackageName(); 31 | } 32 | 33 | @Override 34 | public PackageManager getPackageManager() { 35 | if (Log.getStackTraceString(new Throwable()).contains("com.xunlei.downloadlib")) { 36 | return new DelegateApplicationPackageManager(super.getPackageManager()); 37 | } 38 | return super.getPackageManager(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.ghost.thunder.demo" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':thunder') 31 | 32 | implementation 'com.jakewharton:butterknife:8.8.1' 33 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 34 | } 35 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/ServerResourceParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class ServerResourceParam { 4 | public String mCookie; 5 | public String mRefUrl; 6 | public int mResType; 7 | public int mStrategy; 8 | public String mUrl; 9 | 10 | public ServerResourceParam(String str, String str2, String str3, int i, int i2) { 11 | this.mUrl = str; 12 | this.mRefUrl = str2; 13 | this.mCookie = str3; 14 | this.mResType = i; 15 | this.mStrategy = i2; 16 | } 17 | 18 | public void setUrl(String str) { 19 | this.mUrl = str; 20 | } 21 | 22 | public void setRefUrl(String str) { 23 | this.mRefUrl = str; 24 | } 25 | 26 | public void setCookie(String str) { 27 | this.mCookie = str; 28 | } 29 | 30 | public void setRestype(int i) { 31 | this.mResType = i; 32 | } 33 | 34 | public void setStrategy(int i) { 35 | this.mStrategy = i; 36 | } 37 | 38 | public boolean checkMemberVar() { 39 | if (this.mUrl == null || this.mRefUrl == null || this.mCookie == null) { 40 | return false; 41 | } 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/EmuleTaskParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class EmuleTaskParam { 4 | public int mCreateMode; 5 | public String mFileName; 6 | public String mFilePath; 7 | public int mSeqId; 8 | public String mUrl; 9 | 10 | public EmuleTaskParam() { 11 | } 12 | 13 | public EmuleTaskParam(String str, String str2, String str3, int i, int i2) { 14 | this.mFileName = str; 15 | this.mFilePath = str2; 16 | this.mUrl = str3; 17 | this.mCreateMode = i; 18 | this.mSeqId = i2; 19 | } 20 | 21 | public void setFileName(String str) { 22 | this.mFileName = str; 23 | } 24 | 25 | public void setFilePath(String str) { 26 | this.mFilePath = str; 27 | } 28 | 29 | public void setUrl(String str) { 30 | this.mUrl = str; 31 | } 32 | 33 | public void setCreateMode(int i) { 34 | this.mCreateMode = i; 35 | } 36 | 37 | public void setSeqId(int i) { 38 | this.mSeqId = i; 39 | } 40 | 41 | public boolean checkMemberVar() { 42 | if (this.mFileName == null || this.mFilePath == null || this.mUrl == null) { 43 | return false; 44 | } 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/BtTaskParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class BtTaskParam { 4 | public int mCreateMode; 5 | public String mFilePath; 6 | public int mMaxConcurrent; 7 | public int mSeqId; 8 | public String mTorrentPath; 9 | 10 | public BtTaskParam() { 11 | } 12 | 13 | public BtTaskParam(String str, String str2, int i, int i2, int i3) { 14 | this.mTorrentPath = str; 15 | this.mFilePath = str2; 16 | this.mMaxConcurrent = i; 17 | this.mCreateMode = i2; 18 | this.mSeqId = i3; 19 | } 20 | 21 | public void setTorrentPath(String str) { 22 | this.mTorrentPath = str; 23 | } 24 | 25 | public void setFilePath(String str) { 26 | this.mFilePath = str; 27 | } 28 | 29 | public void setMaxConcurrent(int i) { 30 | this.mMaxConcurrent = i; 31 | } 32 | 33 | public void setCreateMode(int i) { 34 | this.mCreateMode = i; 35 | } 36 | 37 | public void setSeqId(int i) { 38 | this.mSeqId = i; 39 | } 40 | 41 | public boolean checkMemberVar() { 42 | if (this.mTorrentPath == null || this.mFilePath == null) { 43 | return false; 44 | } 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/app/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.app; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.ghost.thunder.demo.R; 6 | import com.ghost.thunder.utils.FragmentUtils; 7 | 8 | import butterknife.OnClick; 9 | 10 | public class MainActivity extends BaseActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | } 16 | 17 | @OnClick(R.id.btn_home) 18 | public void onHomeButtonClicked() { 19 | if(currentType == FragmentUtils.TYPE_HOME) 20 | return; 21 | 22 | changePage(FragmentUtils.TYPE_HOME); 23 | } 24 | 25 | @OnClick(R.id.btn_download_list) 26 | public void onDownloadListButtonClicked() { 27 | if(currentType == FragmentUtils.TYPE_FILE_LIST) 28 | return; 29 | 30 | changePage(FragmentUtils.TYPE_FILE_LIST); 31 | } 32 | 33 | @OnClick(R.id.btn_user) 34 | public void onUserButtonClicked() { 35 | if(currentType == FragmentUtils.TYPE_USER) 36 | return; 37 | 38 | changePage(FragmentUtils.TYPE_USER); 39 | } 40 | 41 | public void changePage(int type) { 42 | currentType = type; 43 | FragmentUtils.getFragment(type); 44 | 45 | changeButtonStyle(type); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/data/DownLoadDataBase.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.data; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | /** 8 | * Created by yuntao.wei on 2018/8/15. 9 | * github:https://github.com/YuntaoWei 10 | * blog:http://blog.csdn.net/qq_17541215 11 | */ 12 | 13 | public class DownLoadDataBase extends SQLiteOpenHelper { 14 | 15 | private static final String DB_NAME = "download.db"; 16 | public static final String DOWNLOAD_TABLE_NAME = "download"; 17 | 18 | public DownLoadDataBase(Context context) { 19 | super(context, DB_NAME, null, 1); 20 | } 21 | 22 | @Override 23 | public void onCreate(SQLiteDatabase db) { 24 | String createTableSQL = "create table "+ DOWNLOAD_TABLE_NAME +" (" + 25 | DownLoadDataBaseColumns.ID + " integer primary key autoincrement,"+ 26 | DownLoadDataBaseColumns.NAME + " varchar(40),"+ 27 | DownLoadDataBaseColumns.SAVE_PATH + " varchar(50),"+ 28 | DownLoadDataBaseColumns.URL + " varchar(50),"+ 29 | DownLoadDataBaseColumns.PROGRESS + " integer"+ 30 | ")"; 31 | db.execSQL(createTableSQL); 32 | } 33 | 34 | @Override 35 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/utils/UrlType.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.utils; 2 | 3 | /** 4 | * Created by yuntao.wei on 2018/8/9. 5 | * github:https://github.com/YuntaoWei 6 | * blog:http://blog.csdn.net/qq_17541215 7 | */ 8 | 9 | public class UrlType { 10 | 11 | public static final String TYPE_THUNDER_URL = "thunder://"; 12 | public static final String TYPE_THUNDER_URL_1 = "ed2k://"; 13 | 14 | 15 | public static final String TYPE_MAGNET_URL = "magnet:?"; 16 | 17 | public static final String TYPE_TORRENT_FILE = ".torrent"; 18 | 19 | public static final String TYPE_FTP_URL = "ftp://"; 20 | 21 | public static final String TYPE_HTTP_URL = "http://"; 22 | 23 | public static final String TYPE_HTTPS_URL = "https://"; 24 | 25 | public static boolean isMagnetUrl(String url) { 26 | return url.startsWith(TYPE_MAGNET_URL); 27 | } 28 | 29 | public static boolean isThunderUrl(String url) { 30 | return url.startsWith(TYPE_THUNDER_URL) || url.startsWith(TYPE_THUNDER_URL_1); 31 | } 32 | 33 | public static boolean isTorrentUrl(String url) { 34 | return url.endsWith(TYPE_TORRENT_FILE); 35 | } 36 | 37 | public static boolean isFTPUrl(String url) { 38 | return url.startsWith(TYPE_FTP_URL); 39 | } 40 | 41 | public static boolean isHttpOrHttpsUrl(String url) { 42 | return url.startsWith(TYPE_HTTP_URL) || url.startsWith(TYPE_HTTPS_URL); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/download_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 19 | 20 | 26 | 27 | 33 | 34 | 35 | 36 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/BlockingItem.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.Condition; 5 | import java.util.concurrent.locks.Lock; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | 8 | public class BlockingItem { 9 | final Lock lock = new ReentrantLock(); 10 | final Condition notEmpty = lock.newCondition(); 11 | 12 | private volatile T item; 13 | 14 | public void put(T x) { 15 | lock.lock(); 16 | try { 17 | item = x; 18 | if (x != null) 19 | notEmpty.signal(); 20 | } finally { 21 | lock.unlock(); 22 | } 23 | } 24 | 25 | public T take() throws InterruptedException { 26 | lock.lock(); 27 | try { 28 | while (item == null) 29 | notEmpty.await(); 30 | T t = item; 31 | item = null; 32 | return t; 33 | } finally { 34 | lock.unlock(); 35 | } 36 | } 37 | 38 | public T tryTake(long waitMs) throws InterruptedException { 39 | lock.lock(); 40 | try { 41 | while (item == null) 42 | if (!notEmpty.await(waitMs, TimeUnit.MILLISECONDS)) 43 | return null; 44 | T t = item; 45 | item = null; 46 | return t; 47 | } finally { 48 | lock.unlock(); 49 | } 50 | } 51 | 52 | public T peek() { 53 | return item; 54 | } 55 | } -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/android/LogLevel.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.android; 2 | 3 | 4 | /* compiled from: XLLog */ 5 | enum LogLevel { 6 | LOG_LEVEL_VERBOSE(2), 7 | LOG_LEVEL_DEBUG(3), 8 | LOG_LEVEL_INFO(4), 9 | LOG_LEVEL_WARN(5), 10 | LOG_LEVEL_ERROR(6); 11 | 12 | private final int logLevel; 13 | 14 | private LogLevel(int i) { 15 | this.logLevel = i; 16 | } 17 | 18 | static LogLevel parseLevel(String str) { 19 | if (str.equals("e") || str.equals("error")) { 20 | return LOG_LEVEL_ERROR; 21 | } 22 | if (str.equals("w") || str.equals("warn")) { 23 | return LOG_LEVEL_WARN; 24 | } 25 | if (str.equals("i") || str.equals("info")) { 26 | return LOG_LEVEL_INFO; 27 | } 28 | if (str.equals("d") || str.equals("debug")) { 29 | return LOG_LEVEL_DEBUG; 30 | } 31 | return LOG_LEVEL_VERBOSE; 32 | } 33 | 34 | public final int getValue() { 35 | return this.logLevel; 36 | } 37 | 38 | public final String toString() { 39 | return toString(true); 40 | } 41 | 42 | public final String toString(boolean z) { 43 | switch (this) { 44 | case LOG_LEVEL_DEBUG: 45 | return z ? "D" : "DEBUG"; 46 | case LOG_LEVEL_INFO: 47 | return z ? "I" : "INFO"; 48 | case LOG_LEVEL_WARN: 49 | return z ? "W" : "WARN"; 50 | case LOG_LEVEL_ERROR: 51 | return z ? "E" : "ERROR"; 52 | default: 53 | if (z) { 54 | return "V"; 55 | } 56 | return "VERBOSE"; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/parameter/CIDTaskParam.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib.parameter; 2 | 3 | public class CIDTaskParam { 4 | public String mBcid; 5 | public String mCid; 6 | public int mCreateMode; 7 | public String mFileName; 8 | public String mFilePath; 9 | public long mFileSize; 10 | public String mGcid; 11 | public int mSeqId; 12 | 13 | public CIDTaskParam(String str, String str2, String str3, String str4, String str5, long j, int i, int i2) { 14 | this.mCid = str; 15 | this.mGcid = str2; 16 | this.mBcid = str3; 17 | this.mFilePath = str4; 18 | this.mFileName = str5; 19 | this.mFileSize = j; 20 | this.mCreateMode = i; 21 | this.mSeqId = i2; 22 | } 23 | 24 | public void setCid(String str) { 25 | this.mCid = str; 26 | } 27 | 28 | public void setGcid(String str) { 29 | this.mGcid = str; 30 | } 31 | 32 | public void setBcid(String str) { 33 | this.mBcid = str; 34 | } 35 | 36 | public void setFilePath(String str) { 37 | this.mFilePath = str; 38 | } 39 | 40 | public void setFileName(String str) { 41 | this.mFileName = str; 42 | } 43 | 44 | public void setFileSize(long j) { 45 | this.mFileSize = j; 46 | } 47 | 48 | public void setCreateMode(int i) { 49 | this.mCreateMode = i; 50 | } 51 | 52 | public void setSeqId(int i) { 53 | this.mSeqId = i; 54 | } 55 | 56 | public boolean checkMemberVar() { 57 | if (this.mCid == null || this.mGcid == null || this.mBcid == null || this.mFilePath == null || this.mFileName == null) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/ghost/thunder/utils/FragmentUtils.java: -------------------------------------------------------------------------------- 1 | package com.ghost.thunder.utils; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | import com.ghost.thunder.ui.DownLoadListFragment; 6 | import com.ghost.thunder.ui.HomeFragment; 7 | import com.ghost.thunder.ui.UserFragment; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.WeakHashMap; 12 | 13 | /** 14 | * Created by wyt on 2018/8/9. 15 | */ 16 | 17 | public class FragmentUtils { 18 | 19 | public static final int TYPE_HOME = 1; 20 | public static final int TYPE_FILE_LIST = 2; 21 | public static final int TYPE_USER = 3; 22 | 23 | private static WeakHashMap fragments = new WeakHashMap<>(); 24 | 25 | public static Fragment getFragment(int type) { 26 | Fragment fragment = fragments.get("fragment:" + type); 27 | if(fragment != null) { 28 | return fragment; 29 | } 30 | 31 | switch (type) { 32 | 33 | case TYPE_HOME : 34 | fragment = new HomeFragment(); 35 | break; 36 | 37 | case TYPE_FILE_LIST : 38 | fragment = new DownLoadListFragment(); 39 | break; 40 | 41 | case TYPE_USER : 42 | fragment = new UserFragment(); 43 | break; 44 | 45 | } 46 | 47 | if(fragment != null) { 48 | fragments.put("fragment:" + type, fragment); 49 | return fragment; 50 | } 51 | 52 | return null; 53 | } 54 | 55 | public static List getAllFragment() { 56 | List fragments = new ArrayList<>(); 57 | fragments.add(getFragment(TYPE_HOME)); 58 | fragments.add(getFragment(TYPE_FILE_LIST)); 59 | fragments.add(getFragment(TYPE_USER)); 60 | return fragments; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /thunder/src/main/java/com/xunlei/downloadlib/Daemon.java: -------------------------------------------------------------------------------- 1 | package com.xunlei.downloadlib; 2 | 3 | import android.os.Looper; 4 | 5 | /** 6 | * 常驻的后台线程,用于处理一个消息循环 7 | *

8 | * 一般用于处理运算密集型任务、磁盘IO任务等执行时间小于1秒的任务 9 | * 10 | */ 11 | public class Daemon { 12 | private static volatile boolean shouldStop; 13 | private static Thread thread = null; 14 | private static Looper looper = null; 15 | 16 | public static synchronized void start() { 17 | if (thread == null) { 18 | final BlockingItem bl = new BlockingItem(); 19 | thread = new Thread(new Runnable() { 20 | @Override 21 | public void run() { 22 | Looper.prepare(); 23 | Looper l = Looper.myLooper(); 24 | bl.put(l); 25 | 26 | while (!shouldStop) { 27 | try { 28 | Looper.loop(); 29 | } catch (Exception e) { 30 | } 31 | } 32 | } 33 | }, "daemon"); 34 | 35 | shouldStop = false; 36 | thread.start(); 37 | try { 38 | looper = bl.take(); 39 | } catch (InterruptedException e) { 40 | } 41 | } 42 | } 43 | 44 | public static synchronized void stop() { 45 | shouldStop = true; 46 | 47 | if (thread != null && looper != null) { 48 | looper.quit(); 49 | try { 50 | thread.join(); 51 | } catch (Exception e) { 52 | } 53 | thread = null; 54 | looper = null; 55 | } 56 | } 57 | 58 | public static Looper looper() { 59 | if (looper == null) { 60 | start(); 61 | } 62 | return looper == null ? Looper.getMainLooper() : looper; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/home_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 20 | 21 |