Skip to content
This repository has been archived by the owner on Mar 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #29 from CodyyAndroid/dev
Browse files Browse the repository at this point in the history
支持普通下载
  • Loading branch information
eachann authored Aug 11, 2017
2 parents 8ffc02e + 3707a23 commit e6afc5f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ allprojects {
```
dependencies {
//如果项目中已有com.android.support.*包,则从Downloader中剔除;
compile('com.github.CodyyAndroid:Downloader:1.1.9') {
compile('com.github.CodyyAndroid:Downloader:1.2.0') {
exclude group: 'com.android.support'
}
//如果项目中无com.android.support.*包,则保留;
compile('com.github.CodyyAndroid:Downloader:1.1.9')
compile('com.github.CodyyAndroid:Downloader:1.2.0')
}
```
## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.9/javadoc/)
## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.2.0/javadoc/)


Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ public boolean onKey(View view, int i, KeyEvent keyEvent) {
// mFileEntities.add(new FileEntity("resource", "http://reserver.jxd.9itest.com:8091/res/view/mobile/download/video/e74f91af5dd74767b8ad96753b5fb3ee/19632d7b5cfe458b9fcfaef7811f88bb.do"));
mFileEntities.add(new FileEntity("resource", "http://reserver.jxd.9itest.com:8091/res/view/mobile/download/video/08ca41aeeb7b4e4c9801d0e8b1408890/27254357585042d9b4950332aa7a36a9.do"));
mFileEntities.add(new FileEntity("AndroidPDF", getString(R.string.url_small_file)));
mFileEntities.add(new FileEntity("OSP","http://srv.codyy.cn/images/9059e96d-98e5-44dc-b509-a46d11716960.apk/app.apk"));
recyclerView.setAdapter(new FileAdapter(mFileEntities));
// Downloader.getInstance(getApplicationContext()).download(getString(R.string.url_apk_file));
// Downloader.getInstance(getApplicationContext()).download(getString(R.string.url_small_file));
mEditText.setText(Formatter.formatFileSize(getBaseContext(), getAvailableStore(getExternalStoragePath())) + "/" + Formatter.formatFileSize(getBaseContext(), getTotalStore(getExternalStoragePath())));

}
Expand Down
6 changes: 3 additions & 3 deletions downloadlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 52
versionName "1.1.9"
versionCode 53
versionName "1.2.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -56,7 +56,7 @@ javadoc {
author true
version true
links "http://docs.oracle.com/javase/7/docs/api"
title "下载库1.1.9"
title "下载库1.2.0"
}
}
// 制作文档(Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ private void start(long range) {
new File(savePath).delete();
String contentDisposition = new String(conn.getHeaderField("Content-Disposition").getBytes("UTF-8"), "UTF-8");
String filename = contentDisposition.substring(contentDisposition.indexOf("=") + 1);
// Cog.e("filename", filename.trim());
savePath = savePath.replace(".do", filename);
mDownloadDao.updatePath(id, savePath);
}
Expand All @@ -484,9 +483,9 @@ private void start(long range) {
currentPart = new RandomAccessFile(savePath, DownloadExtra.RANDOM_ACCESS_FILE_MODE);
currentPart.setLength(totalSize);
currentPart.close();
if (conn.getResponseCode() == 206) {
if (conn.getResponseCode() == 206 || conn.getResponseCode() == 200) {
currentPart = new RandomAccessFile(savePath, DownloadExtra.RANDOM_ACCESS_FILE_MODE);
currentPart.seek(range);
currentPart.seek(conn.getResponseCode() == 200 ? 0 : range);
sendStartOrCompleteMessage(DownloadFlag.NORMAL, id);
inStream = conn.getInputStream();
byte[] buffer = new byte[4096];
Expand All @@ -499,7 +498,11 @@ private void start(long range) {
} else {
sRates = 0;
}
mDownloadStatus = range == 0 ? new DownloadStatus(length, totalSize) : new DownloadStatus((length + mDownloadEntity.getCurrent()), totalSize);
if (conn.getResponseCode() != 200) {
mDownloadStatus = range == 0 ? new DownloadStatus(length, totalSize) : new DownloadStatus((length + mDownloadEntity.getCurrent()), totalSize);
} else {
mDownloadStatus = new DownloadStatus(length, totalSize);
}
sendProgressMessage(mDownloadStatus, id);
if (mDownloadStatus.getPercentNumber() >= 100 && mHandler != null) {
mDownloadDao.updateProgress(id, mDownloadStatus.getDownloadSize(), mDownloadStatus.getTotalSize(), DownloadFlag.COMPLETED);
Expand Down Expand Up @@ -692,7 +695,6 @@ public boolean handleMessage(Message msg) {
break;
case DownloadFlag.RATE:
if (mRateListener != null) {
// Cog.d(TAG, "Download Rating" + msg.getData().getString(DownloadExtra.EXTRA_ID) + msg.getData().getString(DownloadExtra.EXTRA_RATE) + msg.getData().getInt(DownloadExtra.EXTRA_COUNT, 0));
mRateListener.onRate(msg.getData().getString(DownloadExtra.EXTRA_RATE), msg.getData().getInt(DownloadExtra.EXTRA_COUNT, 0));
}
break;
Expand Down

0 comments on commit e6afc5f

Please sign in to comment.