diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/ProxyHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ProxyHelper.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/upload/ProxyHelper.java rename to Aria/src/main/java/com/arialyy/aria/core/ProxyHelper.java index 7162301a..c1d1236f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/ProxyHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ProxyHelper.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload; +package com.arialyy.aria.core; -import com.arialyy.aria.core.AriaManager; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Set; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index e77e1c06..90f6c7c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -207,10 +207,11 @@ public class DownloadGroupTarget if (!newName.equals(entity.getFileName())) { String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); String newPath = mEntity.getDirPath() + "/" + newName; - File file = new File(oldPath); - if (file.exists()) { - file.renameTo(new File(newPath)); + File oldFile = new File(oldPath); + if (oldFile.exists()) { + oldFile.renameTo(new File(newPath)); } + CommonUtil.renameDownloadConfig(oldFile.getName(), newName); DbEntity.exeSql( "UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'"); entity.setDownloadPath(newPath); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index ff289bd7..94bc57d9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -24,7 +24,7 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; -import com.arialyy.aria.core.upload.ProxyHelper; +import com.arialyy.aria.core.ProxyHelper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index c77e853c..68cbcd5e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -21,6 +21,7 @@ import com.arialyy.aria.core.inf.AbsNormalTarget; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.CommonUtil; import java.io.File; /** @@ -48,7 +49,7 @@ public class DownloadTarget if (mTaskEntity.entity == null) { mTaskEntity.entity = entity; } - mEntity = entity; + mEntity = mTaskEntity.entity; } /** @@ -102,42 +103,32 @@ public class DownloadTarget } /** - * 设置文件存储路径 + * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 + * 如:原文件路径 /mnt/sdcard/test.zip + * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip + * + * @param downloadPath 路径必须为文件路径,不能为文件夹路径 */ public DownloadTarget setDownloadPath(@NonNull String downloadPath) { if (TextUtils.isEmpty(downloadPath)) { throw new IllegalArgumentException("文件保持路径不能为null"); } File file = new File(downloadPath); - mEntity.setDownloadPath(downloadPath); - mEntity.setFileName(file.getName()); - mTaskEntity.key = downloadPath; - mEntity.update(); - mTaskEntity.update(); - return this; - } - - /** - * 设置文件名 - * - * @deprecated {@link #setFileName(String)} - */ - @Deprecated public DownloadTarget setDownloadName(@NonNull String downloadName) { - if (TextUtils.isEmpty(downloadName)) { - throw new IllegalArgumentException("文件名不能为null"); + if (file.isDirectory()) { + throw new IllegalArgumentException("文件不能为文件夹"); } - mEntity.setFileName(downloadName); - return this; - } - - /** - * 设置文件名 - */ - public DownloadTarget setFileName(@NonNull String fileName) { - if (TextUtils.isEmpty(fileName)) { - throw new IllegalArgumentException("文件名不能为null"); + if (!downloadPath.equals(mEntity.getDownloadPath())) { + File oldFile = new File(mEntity.getDownloadPath()); + File newFile = new File(downloadPath); + if (TextUtils.isEmpty(mEntity.getDownloadPath()) || oldFile.renameTo(newFile)) { + mEntity.setDownloadPath(downloadPath); + mEntity.setFileName(newFile.getName()); + mTaskEntity.key = downloadPath; + mEntity.update(); + mTaskEntity.update(); + CommonUtil.renameDownloadConfig(oldFile.getName(), newFile.getName()); + } } - mEntity.setFileName(fileName); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index eab63b7c..9df0a8b9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.upload; import android.support.annotation.NonNull; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.ProxyHelper; import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsReceiver; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java index dd372289..690ebc4c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java @@ -82,14 +82,6 @@ public class UploadTarget extends AbsNormalTarget keys = pro.keySet(); + Set newKeys = new LinkedHashSet<>(); + Set values = new LinkedHashSet<>(); + for (Object key : keys) { + String oldKey = String.valueOf(key); + if (oldKey.contains(oldName)) { + values.add(pro.getProperty(oldKey)); + newKeys.add(oldKey.replace(oldName, newName)); + } + } + + pro.clear(); + Iterator next = values.iterator(); + for (String key : newKeys) { + pro.setProperty(key, next.next()); + } + + CommonUtil.saveConfig(oldFile, pro); + } + + oldFile.renameTo(newFile); + } + } + /** * 读取下载配置文件 */ diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 48b61d35..b9a32817 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -20,7 +20,7 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java b/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java index 39cc5d8e..15c0fa88 100644 --- a/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java +++ b/app/src/main/java/com/arialyy/simple/download/SimpleNotification.java @@ -56,7 +56,6 @@ public class SimpleNotification { public void start() { Aria.download(mContext) .load(DOWNLOAD_URL) - .setDownloadName("notification_test.apk") .setDownloadPath( Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk") .start(); diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 5e4612fa..aaab2bb9 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -186,19 +186,25 @@ public class SingleTaskActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { case R.id.start: - String text = ((TextView) view).getText().toString(); - if (text.equals("重新开始?") || text.equals("开始")) { - Aria.download(this) - .load(DOWNLOAD_URL) - .addHeader("groupName", "value") - .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") - .start(); - } else if (text.equals("恢复")) { - Aria.download(this).load(DOWNLOAD_URL).resume(); - } + //String text = ((TextView) view).getText().toString(); + //if (text.equals("重新开始?") || text.equals("开始")) { + // Aria.download(this) + // .load(DOWNLOAD_URL) + // .addHeader("groupName", "value") + // .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") + // .setFileName("hehe.apk") + // .start(); + //} else if (text.equals("恢复")) { + // Aria.download(this).load(DOWNLOAD_URL).resume(); + //} + Aria.download(this) + .load(DOWNLOAD_URL) + .addHeader("groupName", "value") + .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk") + .start(); break; case R.id.stop: - Aria.download(this).load(DOWNLOAD_URL).pause(); + Aria.download(this).load(DOWNLOAD_URL).stop(); break; case R.id.cancel: Aria.download(this).load(DOWNLOAD_URL).cancel(); diff --git a/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java b/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java index 221212e4..d9821643 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java +++ b/app/src/main/java/com/arialyy/simple/download/group/GroupModule.java @@ -43,12 +43,4 @@ public class GroupModule extends BaseModule { Collections.addAll(names, str); return names; } - - //NormalList convertPath(NormalList urls){ - // NormalList paths = new ArrayList<>(); - // - // for (String url : urls){ - // - // } - //} } diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java index 750e2b2a..e423f79a 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.java @@ -68,7 +68,6 @@ final class FileListAdapter extends AbsRVAdapter