From 76e47e2df087fae493cb1655bee78e255a259f3c Mon Sep 17 00:00:00 2001 From: lijian Date: Fri, 4 Aug 2017 14:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3update,=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E4=B8=9A=E5=8A=A1=E5=8F=AF=E4=BD=BF=E7=94=A8=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++-- .../downloader/MultiDownloadActivity.java | 20 ++++++++++-- .../res/layout/activity_multi_download.xml | 5 +++ downloadlibrary/build.gradle | 6 ++-- .../java/com/codyy/download/Downloader.java | 9 +++++- .../com/codyy/download/db/DownloadDao.java | 5 +++ .../codyy/download/db/DownloadDaoImpl.java | 31 +++++++++++++++++-- .../download/service/DownloadService.java | 7 +++++ 8 files changed, 76 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f42998b..fe42702 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ allprojects { ``` dependencies { //如果项目中已有com.android.support.*包,则从Downloader中剔除; - compile('com.github.CodyyAndroid:Downloader:1.1.8') { + compile('com.github.CodyyAndroid:Downloader:1.1.9') { exclude group: 'com.android.support' } //如果项目中无com.android.support.*包,则保留; - compile('com.github.CodyyAndroid:Downloader:1.1.8') + compile('com.github.CodyyAndroid:Downloader:1.1.9') } ``` -## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.8/javadoc/) +## [API](https://jitpack.io/com/github/CodyyAndroid/Downloader/1.1.9/javadoc/) diff --git a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java index d29b5ca..97c18a5 100644 --- a/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java +++ b/app/src/main/java/com/codyy/downloader/MultiDownloadActivity.java @@ -74,9 +74,10 @@ public boolean onKey(View view, int i, KeyEvent keyEvent) { 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()))); + mEditText.setText(Formatter.formatFileSize(getBaseContext(), getAvailableStore(getExternalStoragePath())) + "/" + Formatter.formatFileSize(getBaseContext(), getTotalStore(getExternalStoragePath()))); } + // 获取SD卡路径 public static String getExternalStoragePath() { // 获取SdCard状态 @@ -98,6 +99,7 @@ public static String getExternalStoragePath() { return null; } + private String getAvailMemory() {// 获取android当前可用内存大小 ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); @@ -107,6 +109,7 @@ private String getAvailMemory() {// 获取android当前可用内存大小 return Formatter.formatFileSize(getBaseContext(), mi.availMem);// 将获取的内存大小规格化 } + public static long getAvailableStore(String filePath) { // 取得sdcard文件路径 @@ -132,6 +135,7 @@ public static long getAvailableStore(String filePath) { return availableSpare; } + public static long getTotalStore(String filePath) { // 取得sdcard文件路径 @@ -144,16 +148,17 @@ public static long getTotalStore(String filePath) { // 获取BLOCK数量 - long totalBlocks = statFs.getBlockCount(); + long totalBlocks = statFs.getBlockCount(); // 可使用的Block的数量 - long total = totalBlocks * blocSize; + long total = totalBlocks * blocSize; return total; } + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { /*if (keyCode == KeyEvent.KEYCODE_DEL) { @@ -217,6 +222,14 @@ public void queryAll(View view) { } } + public void update(View view) { + DownloadEntity entity = Downloader.getInstance(this).getDownloadRecord(getString(R.string.url_small_file)); + if (entity != null && entity.getExtra2() != null) { + entity.setExtra2(new StringBuilder(entity.getExtra2()).append("\u0003").append("sultan").toString()); + Downloader.getInstance(this).update(entity); + } + } + class FileViewHolder extends RecyclerViewHolder { TextView tvName; TextView tvUrl; @@ -240,6 +253,7 @@ public void onClick(View v) { DownloadEntity entity = new DownloadEntity(); entity.setId(tvUrl.getText().toString()); entity.setUrl(tvUrl.getText().toString()); + entity.setExtra2("lijian"); Downloader.getInstance(itemView.getContext()).download(entity); } else if ("暂停".equals(btn.getText().toString())) { btn.setText("下载"); diff --git a/app/src/main/res/layout/activity_multi_download.xml b/app/src/main/res/layout/activity_multi_download.xml index fee8cf8..2db989c 100644 --- a/app/src/main/res/layout/activity_multi_download.xml +++ b/app/src/main/res/layout/activity_multi_download.xml @@ -50,6 +50,11 @@ android:layout_height="wrap_content" android:onClick="queryAll" android:text="queryAll"/> +