AriaLyy 7 years ago
parent e20ab6a3c9
commit 0399eed2f3
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/ProxyHelper.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  4. 49
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  5. 1
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  6. 8
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  7. 63
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  8. 2
      app/src/main/assets/aria_config.xml
  9. 1
      app/src/main/java/com/arialyy/simple/download/SimpleNotification.java
  10. 28
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  11. 8
      app/src/main/java/com/arialyy/simple/download/group/GroupModule.java
  12. 1
      app/src/main/java/com/arialyy/simple/download/multi_download/FileListAdapter.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;

@ -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);

@ -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;

@ -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;
}

@ -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;

@ -82,14 +82,6 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
return this;
}
/**
* 设置文件名
*/
public UploadTarget setFileName(String fileName) {
mEntity.setFileName(fileName);
return this;
}
/**
* 设置上传文件类型
*

@ -44,8 +44,12 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
@ -595,6 +599,65 @@ public class CommonUtil {
return err.toString();
}
/**
* 重命名下载配置文件
* 如果旧的配置文件名不存在则使用新的配置文件名新创建一个文件否则将旧的配置文件重命名为新的位置文件名
* 除了重命名配置文件名外还会将文件中的记录重命名为新的记录如果没有记录则不做处理
*
* @param oldName 旧的下载文件名
* @param newName 新的下载文件名
*/
public static void renameDownloadConfig(String oldName, String newName) {
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.DOWNLOAD_TEMP_DIR, oldName,
newName);
}
/**
* 重命名上传配置文件
* 如果旧的配置文件名不存在则使用新的配置文件名新创建一个文件否则将旧的配置文件重命名为新的位置文件名
* 除了重命名配置文件名外还会将文件中的记录重命名为新的记录如果没有记录则不做处理
*
* @param oldName 旧的上传文件名
* @param newName 新的上传文件名
*/
public static void renameUploadConfig(String oldName, String newName) {
renameConfig(AriaManager.APP.getFilesDir().getPath() + AriaManager.UPLOAD_TEMP_DIR, oldName,
newName);
}
private static void renameConfig(String basePath, String oldName, String newName) {
if (oldName.equals(newName)) return;
File oldFile = new File(basePath + oldName + ".properties");
File newFile = new File(basePath + newName + ".properties");
if (!oldFile.exists()) {
createFile(newFile.getPath());
} else {
Properties pro = CommonUtil.loadConfig(oldFile);
if (!pro.isEmpty()) {
Set<Object> keys = pro.keySet();
Set<String> newKeys = new LinkedHashSet<>();
Set<String> 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<String> next = values.iterator();
for (String key : newKeys) {
pro.setProperty(key, next.next());
}
CommonUtil.saveConfig(oldFile, pro);
}
oldFile.renameTo(newFile);
}
}
/**
* 读取下载配置文件
*/

@ -20,7 +20,7 @@
<connectTimeOut value="1000"/>
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
<iOTimeOut value="2000"/>
<iOTimeOut value="200"/>
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
<buffSize value="8192"/>

@ -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();

@ -186,19 +186,25 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
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();

@ -43,12 +43,4 @@ public class GroupModule extends BaseModule {
Collections.addAll(names, str);
return names;
}
//NormalList<String> convertPath(NormalList<String> urls){
// NormalList<String> paths = new ArrayList<>();
//
// for (String url : urls){
//
// }
//}
}

@ -68,7 +68,6 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
Aria.download(getContext())
.load(item.downloadUrl)
.setFileName(item.name)
.setDownloadPath(item.downloadPath)
.start();
}

Loading…
Cancel
Save