From 3707a23af730fe24e6edc6b1a795f9e503b5569b Mon Sep 17 00:00:00 2001 From: lijian Date: Fri, 11 Aug 2017 11:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=99=AE=E9=80=9A=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- .../com/codyy/downloader/MultiDownloadActivity.java | 3 +-- downloadlibrary/build.gradle | 6 +++--- .../com/codyy/download/service/DownloadService.java | 12 +++++++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fe42702..e18dc8f 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java index 97c18a5..fb0f1bf 100644 --- a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java +++ b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java @@ -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()))); } diff --git a/downloadlibrary/build.gradle b/downloadlibrary/build.gradle index fccc0a1..cf2ef79 100644 --- a/downloadlibrary/build.gradle +++ b/downloadlibrary/build.gradle @@ -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" @@ -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) diff --git a/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java b/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java index 635c5e6..9533e50 100644 --- a/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java +++ b/downloadlibrary/src/main/java/com/codyy/download/service/DownloadService.java @@ -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); } @@ -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]; @@ -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); @@ -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;