Ver código fonte

remove unusage code

billyyoyo 5 anos atrás
pai
commit
e42f579c3f
100 arquivos alterados com 0 adições e 10284 exclusões
  1. 0 3
      Aria/.gitignore
  2. 0 12
      Aria/bintray-release.gradle
  3. 0 28
      Aria/build.gradle
  4. 0 143
      Aria/jcenter.gradle
  5. 0 17
      Aria/proguard-rules.pro
  6. 0 30
      Aria/src/androidTest/java/com/arialyy/downloadutil/ApplicationTest.java
  7. 0 10
      Aria/src/main/AndroidManifest.xml
  8. 0 223
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  9. 0 368
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  10. 0 251
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  11. 0 344
      Aria/src/main/java/com/arialyy/aria/core/Configuration.java
  12. 0 111
      Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java
  13. 0 35
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  14. 0 31
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java
  15. 0 27
      Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java
  16. 0 46
      Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java
  17. 0 35
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java
  18. 0 71
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java
  19. 0 72
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java
  20. 0 35
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java
  21. 0 149
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  22. 0 44
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java
  23. 0 68
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  24. 0 45
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  25. 0 57
      Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java
  26. 0 108
      Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java
  27. 0 90
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  28. 0 73
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  29. 0 20
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java
  30. 0 51
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java
  31. 0 398
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  32. 0 204
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  33. 0 66
      Aria/src/main/java/com/arialyy/aria/core/common/IUtil.java
  34. 0 78
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  35. 0 31
      Aria/src/main/java/com/arialyy/aria/core/common/QueueMod.java
  36. 0 31
      Aria/src/main/java/com/arialyy/aria/core/common/RequestEnum.java
  37. 0 75
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  38. 0 25
      Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java
  39. 0 152
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  40. 0 202
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  41. 0 165
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  42. 0 102
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java
  43. 0 65
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  44. 0 71
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  45. 0 107
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  46. 0 31
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java
  47. 0 35
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java
  48. 0 273
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  49. 0 153
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  50. 0 178
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  51. 0 46
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java
  52. 0 102
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  53. 0 120
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  54. 0 155
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java
  55. 0 399
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  56. 0 145
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  57. 0 127
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  58. 0 100
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  59. 0 118
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpClientHelp.java
  60. 0 68
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java
  61. 0 68
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java
  62. 0 30
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java
  63. 0 151
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  64. 0 170
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  65. 0 128
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  66. 0 59
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java
  67. 0 17
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/OnFileInfoCallback.java
  68. 0 125
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
  69. 0 150
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsDownloadTarget.java
  70. 0 182
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  71. 0 70
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java
  72. 0 31
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java
  73. 0 110
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java
  74. 0 44
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java
  75. 0 27
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java
  76. 0 239
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  77. 0 172
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  78. 0 130
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  79. 0 80
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java
  80. 0 35
      Aria/src/main/java/com/arialyy/aria/core/inf/IDownloadListener.java
  81. 0 60
      Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java
  82. 0 63
      Aria/src/main/java/com/arialyy/aria/core/inf/IEventListener.java
  83. 0 60
      Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
  84. 0 86
      Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java
  85. 0 95
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  86. 0 26
      Aria/src/main/java/com/arialyy/aria/core/inf/IUploadListener.java
  87. 0 211
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  88. 0 80
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  89. 0 143
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  90. 0 143
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  91. 0 119
      Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java
  92. 0 111
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  93. 0 78
      Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java
  94. 0 154
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java
  95. 0 196
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  96. 0 83
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java
  97. 0 43
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadSharePool.java
  98. 0 68
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java
  99. 0 28
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java
  100. 0 0
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadSharePool.java

+ 0 - 3
Aria/.gitignore

@@ -1,3 +0,0 @@
-/build
-gradle.properties
-downloadutil.iml

+ 0 - 12
Aria/bintray-release.gradle

@@ -1,12 +0,0 @@
-apply plugin: 'bintray-release'
-publish {
-  artifactId = 'aria-core'
-  userOrg = rootProject.userOrg
-  groupId = rootProject.groupId
-  //  uploadName = rootProject.uploadName
-  uploadName = 'AriaApi'
-  publishVersion = rootProject.publishVersion
-  description = rootProject.description
-  website = rootProject.website
-  licences = rootProject.licences
-}

+ 0 - 28
Aria/build.gradle

@@ -1,28 +0,0 @@
-apply plugin: 'com.android.library'
-
-android {
-  compileSdkVersion androidConfigs.compileSdkVersion
-  buildToolsVersion androidConfigs.buildToolsVersion
-
-  defaultConfig {
-    minSdkVersion 18
-    targetSdkVersion 27
-    versionCode 329
-    versionName "3.2.9"
-  }
-  buildTypes {
-    release {
-      minifyEnabled false
-      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
-    }
-  }
-}
-
-dependencies {
-  compile 'com.android.support:appcompat-v7:27.1.0'
-  compile project(':AriaAnnotations')
-  compile 'com.arialyy.aria:aria-ftp-plug:1.0.0'
-//  compile project(':AriaFtpPlug')
-
-}
-apply from: 'bintray-release.gradle'

+ 0 - 143
Aria/jcenter.gradle

@@ -1,143 +0,0 @@
-group = PROJ_GROUP_ID
-version = PROJ_VERSION
-project.archivesBaseName = PROJ_ARTIFACT_ID
-apply plugin: 'com.jfrog.bintray'
-apply plugin: 'com.github.dcendents.android-maven'
-//输入:gradlew bintray 执行
-
-//############################## jar、sources、doc 打包 start #######################################
-task sourcesJar(type: Jar) {
-  from android.sourceSets.main.java.srcDirs
-  classifier = 'sources'
-}
-
-task javadoc(type: Javadoc) {
-  source = android.sourceSets.main.java.srcDirs
-  classpath += configurations.compile
-  classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
-  classifier = 'javadoc'
-  from javadoc.destinationDir
-}
-
-javadoc {
-  options {
-    encoding "UTF-8"
-    charSet 'UTF-8'
-    author true
-    version true
-    links "http://docs.oracle.com/javase/7/docs/api"
-    title PROJ_ARTIFACT_ID
-  }
-}
-
-//添加以下信息避免JAVADOC打包时引用其它类库而出现问题,比如出现以下错误
-// xxxx.java:20: 错误: 找不到符号
-// public static <T> T create(JsonElement json, Class<T> classOfModel) {
-//    ^
-//    符号:   类 JsonElement
-//    位置: 类 xxxx
-android.libraryVariants.all { variant ->
-  println variant.javaCompile.classpath.files
-  if (variant.name == 'release') {
-    //我们只需 release 的 javadoc
-    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
-      // title = ''
-      // description = ''
-      source = variant.javaCompile.source
-      classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
-      options {
-        encoding "utf-8"
-        links "http://docs.oracle.com/javase/7/docs/api/"
-        linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
-      }
-      exclude '**/BuildConfig.java'
-      exclude '**/R.java'
-    }
-    task("javadoc${variant.name.capitalize()}Jar", type: Jar,
-        dependsOn: "generate${variant.name.capitalize()}Javadoc") {
-      classifier = 'javadoc'
-      from tasks.getByName("generate${variant.name.capitalize()}Javadoc").destinationDir
-    }
-    artifacts {
-      archives tasks.getByName("javadoc${variant.name.capitalize()}Jar")
-    }
-  }
-}
-
-artifacts {
-  archives javadocJar
-  archives sourcesJar
-}
-//############################## jar、sources、doc 打包 end #######################################
-
-//################################# jcenter 上传配置 start #########################################
-bintray {
-//  user = hasProperty("bintrayUser") ? getProperty("bintrayUser") : getProperty("BINTRAY_USER")
-//  groupName = hasProperty("bintrayKey") ? getProperty("bintrayKey") : getProperty("BINTRAY_KEY")
-  user = BINTRAY_USER
-  key = BINTRAY_KEY
-  configurations = ['archives']
-
-  pkg {
-    repo = PROJ_REPO
-    name = PROJ_NAME
-    desc = PROJ_DESCRIPTION
-    websiteUrl = PROJ_WEB_SITE_URL
-    issueTrackerUrl = PROJ_ISSUE_TRACKER_URL
-    vcsUrl = PROJ_VCS_URL
-    publish = true
-    publicDownloadNumbers = true
-    licenses = LICENSES
-//    version {
-//      desc = libraryDescription
-//      gpg {
-//        sign = true //Determines whether to GPG sign the files. The default is false
-//        passphrase = properties.getProperty("bintray.gpg.password")
-//        //Optional. The passphrase for GPG signing'
-//      }
-//    }
-  }
-}
-
-//install
-install {
-  repositories.mavenInstaller {
-    // This generates POM.xml with proper parameters
-    pom {
-      project {
-        packaging 'aar'
-        groupId PROJ_GROUP_ID
-        artifactId PROJ_ARTIFACT_ID
-
-        // Add your description here
-        name PROJ_NAME
-        description PROJ_DESCRIPTION
-        url PROJ_WEB_SITE_URL
-
-        // Set your license
-        licenses {
-          license {
-            name LICENSE_NAME
-            url LICENSE_URL
-          }
-        }
-        developers {
-          developer {
-            id DEVELOPER_ID
-            name DEVELOPER_NAME
-            email DEVELOPER_EMAIL
-          }
-        }
-        scm {
-          connection PROJ_WEB_SITE_URL
-          developerConnection PROJ_WEB_SITE_URL
-          url PROJ_VCS_URL
-        }
-      }
-    }
-  }
-}
-//################################# jcenter 上传配置 end #########################################

+ 0 - 17
Aria/proguard-rules.pro

@@ -1,17 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in D:\sdk/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-#   http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-#   public *;
-#}

+ 0 - 30
Aria/src/androidTest/java/com/arialyy/downloadutil/ApplicationTest.java

@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package com.arialyy.downloadutil;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
- */
-public class ApplicationTest extends ApplicationTestCase<Application> {
-  public ApplicationTest() {
-    super(Application.class);
-  }
-}

+ 0 - 10
Aria/src/main/AndroidManifest.xml

@@ -1,10 +0,0 @@
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.arialyy.aria">
-
-  <application
-      android:allowBackup="true"
-      android:supportsRtl="true">
-
-  </application>
-
-</manifest>

+ 0 - 223
Aria/src/main/java/com/arialyy/aria/core/Aria.java

@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core;
-
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.app.Application;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.app.Fragment;
-import android.app.Service;
-import android.content.Context;
-import android.os.Build;
-import android.widget.PopupWindow;
-import com.arialyy.annotations.Download;
-import com.arialyy.annotations.Upload;
-import com.arialyy.aria.core.download.DownloadReceiver;
-import com.arialyy.aria.core.scheduler.IDownloadSchedulerListener;
-import com.arialyy.aria.core.scheduler.ISchedulerListener;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.upload.UploadReceiver;
-import com.arialyy.aria.core.upload.UploadTask;
-
-/**
- * Created by lyy on 2016/12/1.
- * https://github.com/AriaLyy/Aria
- * Aria启动,管理全局任务
- * <pre>
- *   <code>
- *   //下载
- *   Aria.download(this)
- *       .load(URL)     //下载地址,必填
- *       //文件保存路径,必填
- *       .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
- *       .start();
- *   </code>
- *   <code>
- *    //上传
- *    Aria.upload(this)
- *        .load(filePath)     //文件路径,必填
- *        .setUploadUrl(uploadUrl)  //上传路径,必填
- *        .setAttachment(fileKey)   //服务器读取文件的key,必填
- *        .start();
- *   </code>
- * </pre>
- */
-@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) public class Aria {
-
-  private Aria() {
-  }
-
-  /**
-   * 初始化下载
-   *
-   * @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
-   */
-  public static DownloadReceiver download(Object obj) {
-    return get(obj).download(obj);
-  }
-
-  /**
-   * 初始化上传
-   *
-   * @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
-   */
-  public static UploadReceiver upload(Object obj) {
-    return get(obj).upload(obj);
-  }
-
-  /**
-   * 处理通用事件
-   *
-   * @param obj 支持类型有【Activity、Service、Application、DialogFragment、Fragment、PopupWindow、Dialog】
-   */
-  public static AriaManager get(Object obj) {
-    if (obj instanceof Activity || obj instanceof Service || obj instanceof Application) {
-      return AriaManager.getInstance((Context) obj);
-    } else if (obj instanceof DialogFragment) {
-      DialogFragment dialog = (DialogFragment) obj;
-      return AriaManager.getInstance(
-          Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? dialog.getContext()
-              : dialog.getActivity());
-    } else if (obj instanceof android.support.v4.app.Fragment) {
-      android.support.v4.app.Fragment fragment = (android.support.v4.app.Fragment) obj;
-      return AriaManager.getInstance(
-          Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
-              : fragment.getActivity());
-    } else if (obj instanceof Fragment) {
-      Fragment fragment = (Fragment) obj;
-      return AriaManager.getInstance(
-          Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? fragment.getContext()
-              : fragment.getActivity());
-    } else if (obj instanceof PopupWindow) {
-      PopupWindow popupWindow = (PopupWindow) obj;
-      return AriaManager.getInstance(popupWindow.getContentView().getContext());
-    } else if (obj instanceof Dialog) {
-      Dialog dialog = (Dialog) obj;
-      return AriaManager.getInstance(dialog.getContext());
-    } else {
-      throw new IllegalArgumentException("不支持的类型");
-    }
-  }
-
-  /**
-   * 上传任务状态监听
-   *
-   * @see Upload
-   * @deprecated 请使用注解函数的方式来实现事件的获取
-   */
-  @Deprecated public static class UploadSchedulerListener
-      implements ISchedulerListener<UploadTask> {
-
-    /**
-     * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态。
-     *
-     * @param task 上传文物实体
-     */
-    @Override public void onPre(UploadTask task) {
-
-    }
-
-    @Override public void onTaskPre(UploadTask task) {
-
-    }
-
-    @Override public void onTaskResume(UploadTask task) {
-
-    }
-
-    @Override public void onTaskStart(UploadTask task) {
-
-    }
-
-    @Override public void onTaskStop(UploadTask task) {
-
-    }
-
-    @Override public void onTaskCancel(UploadTask task) {
-
-    }
-
-    @Override public void onTaskFail(UploadTask task) {
-
-    }
-
-    @Override public void onTaskComplete(UploadTask task) {
-
-    }
-
-    @Override public void onTaskRunning(UploadTask task) {
-
-    }
-  }
-
-  /**
-   * 下载任务状态监听
-   *
-   * @see Download
-   * @deprecated 请使用注解函数的方式来实现事件的获取
-   */
-  @Deprecated public static class DownloadSchedulerListener
-      implements IDownloadSchedulerListener<DownloadTask> {
-    /**
-     * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态。
-     * 需要注意的是,在该回调中,是得不到文件长度的,如果需要获取文件长度,需要在onTaskPre中获取
-     *
-     * @param task 下载任务
-     */
-    @Override public void onPre(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskPre(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskResume(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskStart(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskStop(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskCancel(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskFail(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskComplete(DownloadTask task) {
-
-    }
-
-    @Override public void onTaskRunning(DownloadTask task) {
-
-    }
-
-    @Override public void onNoSupportBreakPoint(DownloadTask task) {
-
-    }
-  }
-}

+ 0 - 368
Aria/src/main/java/com/arialyy/aria/core/AriaManager.java

@@ -1,368 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core;
-
-import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.app.Application;
-import android.app.Dialog;
-import android.app.Service;
-import android.content.Context;
-import android.os.Build;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.text.TextUtils;
-import android.util.Log;
-import android.widget.PopupWindow;
-import com.arialyy.aria.core.common.QueueMod;
-import com.arialyy.aria.core.download.DownloadReceiver;
-import com.arialyy.aria.core.command.ICmd;
-import com.arialyy.aria.core.inf.IReceiver;
-import com.arialyy.aria.core.upload.UploadReceiver;
-import com.arialyy.aria.orm.DbUtil;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.xml.sax.SAXException;
-
-/**
- * Created by lyy on 2016/12/1.
- * https://github.com/AriaLyy/Aria
- * Aria管理器,任务操作在这里执行
- */
-@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
-  private static final String TAG = "AriaManager";
-  private static final String DOWNLOAD = "_download";
-  private static final String UPLOAD = "_upload";
-  public static final Object LOCK = new Object();
-  public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/";
-  public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/";
-  @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null;
-  private Map<String, IReceiver> mReceivers = new ConcurrentHashMap<>();
-  public static Context APP;
-  private List<ICmd> mCommands = new ArrayList<>();
-  private Configuration.DownloadConfig mDConfig;
-  private Configuration.UploadConfig mUConfig;
-
-  private AriaManager(Context context) {
-    DbUtil.init(context.getApplicationContext());
-    APP = context.getApplicationContext();
-    regAppLifeCallback(context);
-    initConfig();
-  }
-
-  public static AriaManager getInstance(Context context) {
-    if (INSTANCE == null) {
-      synchronized (LOCK) {
-        INSTANCE = new AriaManager(context);
-      }
-    }
-    return INSTANCE;
-  }
-
-  public Map<String, IReceiver> getReceiver() {
-    return mReceivers;
-  }
-
-  /**
-   * 设置上传任务的执行队列类型
-   *
-   * @param mod {@link QueueMod}
-   */
-  public AriaManager setUploadQueueMod(QueueMod mod) {
-    mUConfig.setQueueMod(mod.tag);
-    return this;
-  }
-
-  /**
-   * 设置下载任务的执行队列类型
-   *
-   * @param mod {@link QueueMod}
-   */
-  public AriaManager setDownloadQueueMod(QueueMod mod) {
-    mDConfig.setQueueMod(mod.tag);
-    return this;
-  }
-
-  /**
-   * 如果需要在代码中修改下载配置,请使用以下方法
-   * <pre>
-   *   <code>
-   *     //修改最大任务队列数
-   *     Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
-   *   </code>
-   * </pre>
-   */
-  public Configuration.DownloadConfig getDownloadConfig() {
-    return mDConfig;
-  }
-
-  /**
-   * 如果需要在代码中修改下载配置,请使用以下方法
-   * <pre>
-   *   <code>
-   *     //修改最大任务队列数
-   *     Aria.get(this).getUploadConfig().setMaxTaskNum(3);
-   *   </code>
-   * </pre>
-   */
-  public Configuration.UploadConfig getUploadConfig() {
-    return mUConfig;
-  }
-
-  /**
-   * 设置命令
-   */
-  public AriaManager setCmd(ICmd command) {
-    mCommands.add(command);
-    return this;
-  }
-
-  /**
-   * 设置一组命令
-   */
-  public <T extends ICmd> AriaManager setCmds(List<T> commands) {
-    if (commands != null && commands.size() > 0) {
-      mCommands.addAll(commands);
-    }
-    return this;
-  }
-
-  /**
-   * 执行所有设置的命令
-   */
-  public synchronized void exe() {
-    for (ICmd command : mCommands) {
-      command.executeCmd();
-    }
-    mCommands.clear();
-  }
-
-  /**
-   * 处理下载操作
-   */
-  DownloadReceiver download(Object obj) {
-    IReceiver receiver = mReceivers.get(getKey(true, obj));
-    if (receiver == null) {
-      receiver = putReceiver(true, obj);
-    }
-    return (receiver instanceof DownloadReceiver) ? (DownloadReceiver) receiver : null;
-  }
-
-  /**
-   * 处理上传操作
-   */
-  UploadReceiver upload(Object obj) {
-    IReceiver receiver = mReceivers.get(getKey(false, obj));
-    if (receiver == null) {
-      receiver = putReceiver(false, obj);
-    }
-    return (receiver instanceof UploadReceiver) ? (UploadReceiver) receiver : null;
-  }
-
-  private IReceiver putReceiver(boolean isDownload, Object obj) {
-    final String key = getKey(isDownload, obj);
-    IReceiver receiver = mReceivers.get(key);
-    final WidgetLiftManager widgetLiftManager = new WidgetLiftManager();
-    if (obj instanceof Dialog) {
-      widgetLiftManager.handleDialogLift((Dialog) obj);
-    } else if (obj instanceof PopupWindow) {
-      widgetLiftManager.handlePopupWindowLift((PopupWindow) obj);
-    }
-
-    if (receiver == null) {
-      if (isDownload) {
-        DownloadReceiver dReceiver = new DownloadReceiver();
-        dReceiver.targetName = obj.getClass().getName();
-        dReceiver.obj = obj;
-        mReceivers.put(key, dReceiver);
-        receiver = dReceiver;
-      } else {
-        UploadReceiver uReceiver = new UploadReceiver();
-        uReceiver.targetName = obj.getClass().getName();
-        uReceiver.obj = obj;
-        mReceivers.put(key, uReceiver);
-        receiver = uReceiver;
-      }
-    }
-    return receiver;
-  }
-
-  /**
-   * 根据功能类型和控件类型获取对应的key
-   */
-  private String getKey(boolean isDownload, Object obj) {
-    String clsName = obj.getClass().getName();
-    String key = "";
-    if (!(obj instanceof Activity)) {
-      if (obj instanceof android.support.v4.app.Fragment) {
-        key = clsName + "_" + ((Fragment) obj).getActivity().getClass().getName();
-      } else if (obj instanceof android.app.Fragment) {
-        key = clsName + "_" + ((android.app.Fragment) obj).getActivity().getClass().getName();
-      } else if (obj instanceof Dialog) {
-        Activity activity = ((Dialog) obj).getOwnerActivity();
-        if (activity != null) {
-          key = clsName + "_" + activity.getClass().getName();
-        } else {
-          key = clsName;
-        }
-      } else if (obj instanceof PopupWindow) {
-        Context context = ((PopupWindow) obj).getContentView().getContext();
-        if (context instanceof Activity) {
-          key = clsName + "_" + context.getClass().getName();
-        } else {
-          key = clsName;
-        }
-      } else if (obj instanceof Service) {
-        key = clsName;
-      } else if (obj instanceof Application) {
-        key = clsName;
-      }
-    }
-    if (obj instanceof Activity || obj instanceof Service) {
-      key = clsName;
-    } else if (obj instanceof Application) {
-      key = clsName;
-    }
-    if (TextUtils.isEmpty(key)) {
-      throw new IllegalArgumentException("未知类型");
-    }
-    key += isDownload ? DOWNLOAD : UPLOAD;
-    return key;
-  }
-
-  /**
-   * 初始化配置文件
-   */
-  private void initConfig() {
-    File xmlFile = new File(APP.getFilesDir().getPath() + Configuration.XML_FILE);
-    File tempDir = new File(APP.getFilesDir().getPath() + "/temp");
-    if (!xmlFile.exists()) {
-      loadConfig();
-    } else {
-      try {
-        String md5Code = CommonUtil.getFileMD5(xmlFile);
-        File file = new File(APP.getFilesDir().getPath() + "temp.xml");
-        if (file.exists()) {
-          file.delete();
-        }
-        CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"),
-            file.getPath());
-        if (!CommonUtil.checkMD5(md5Code, file)) {
-          loadConfig();
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-    mDConfig = Configuration.DownloadConfig.getInstance();
-    mUConfig = Configuration.UploadConfig.getInstance();
-    if (tempDir.exists()) {
-      File newDir = new File(APP.getFilesDir().getPath() + DOWNLOAD_TEMP_DIR);
-      newDir.mkdirs();
-      tempDir.renameTo(newDir);
-    }
-  }
-
-  /**
-   * 加载配置文件
-   */
-  private void loadConfig() {
-    try {
-      ConfigHelper helper = new ConfigHelper();
-      SAXParserFactory factory = SAXParserFactory.newInstance();
-      SAXParser parser = factory.newSAXParser();
-      parser.parse(APP.getAssets().open("aria_config.xml"), helper);
-      CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"),
-          APP.getFilesDir().getPath() + Configuration.XML_FILE);
-    } catch (ParserConfigurationException | IOException | SAXException e) {
-      Log.e(TAG, e.toString());
-    }
-  }
-
-  /**
-   * 注册APP生命周期回调
-   */
-  private void regAppLifeCallback(Context context) {
-    Context app = context.getApplicationContext();
-    if (app instanceof Application) {
-      LifeCallback mLifeCallback = new LifeCallback();
-      ((Application) app).registerActivityLifecycleCallbacks(mLifeCallback);
-    }
-  }
-
-  /**
-   * onDestroy
-   */
-  void destroySchedulerListener(Object obj) {
-    String clsName = obj.getClass().getName();
-    for (Iterator<Map.Entry<String, IReceiver>> iter = mReceivers.entrySet().iterator();
-        iter.hasNext(); ) {
-      Map.Entry<String, IReceiver> entry = iter.next();
-      String key = entry.getKey();
-      if (key.contains(clsName)) {
-        IReceiver receiver = mReceivers.get(key);
-        receiver.removeSchedulerListener();
-        receiver.unRegister();
-        receiver.destroy();
-        iter.remove();
-      }
-    }
-  }
-
-  /**
-   * Activity生命周期
-   */
-  private class LifeCallback implements Application.ActivityLifecycleCallbacks {
-
-    @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
-
-    }
-
-    @Override public void onActivityStarted(Activity activity) {
-
-    }
-
-    @Override public void onActivityResumed(Activity activity) {
-
-    }
-
-    @Override public void onActivityPaused(Activity activity) {
-
-    }
-
-    @Override public void onActivityStopped(Activity activity) {
-
-    }
-
-    @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
-
-    }
-
-    @Override public void onActivityDestroyed(Activity activity) {
-      destroySchedulerListener(activity);
-    }
-  }
-}

+ 0 - 251
Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java

@@ -1,251 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core;
-
-import android.text.TextUtils;
-import android.util.Log;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Created by lyy on 2017/5/22.
- * 读取配置文件
- */
-class ConfigHelper extends DefaultHandler {
-  private final String TAG = "ConfigHelper";
-
-  private boolean isDownloadConfig = false, isUploadConfig;
-  private Configuration.DownloadConfig mDownloadConfig = Configuration.DownloadConfig.getInstance();
-  private Configuration.UploadConfig mUploadConfig = Configuration.UploadConfig.getInstance();
-
-  @Override public void startDocument() throws SAXException {
-    super.startDocument();
-  }
-
-  @Override
-  public void startElement(String uri, String localName, String qName, Attributes attributes)
-      throws SAXException {
-    super.startElement(uri, localName, qName, attributes);
-    if (qName.equals("download")) {
-      isDownloadConfig = true;
-      isUploadConfig = false;
-    } else if (qName.equals("upload")) {
-      isUploadConfig = true;
-      isDownloadConfig = false;
-    }
-    if (isDownloadConfig || isUploadConfig) {
-
-      String value = attributes.getValue("value");
-      switch (qName) {
-        case "threadNum":
-          loadThreadNum(value);
-          break;
-        case "maxTaskNum":
-          loadMaxQueue(value);
-          break;
-        case "reTryNum":
-          loadReTry(value);
-          break;
-        case "connectTimeOut":
-          loadConnectTime(value);
-          break;
-        case "iOTimeOut":
-          loadIOTimeout(value);
-          break;
-        case "reTryInterval":
-          loadReTryInterval(value);
-          break;
-        case "buffSize":
-          loadBuffSize(value);
-          break;
-        case "ca":
-          String caName = attributes.getValue("name");
-          String caPath = attributes.getValue("path");
-          loadCA(caName, caPath);
-          break;
-        case "convertSpeed":
-          loadConvertSpeed(value);
-          break;
-        case "maxSpeed":
-          loadMaxSpeed(value);
-          break;
-        case "queueMod":
-          loadQueueMod(value);
-          break;
-      }
-    }
-  }
-
-  private void loadQueueMod(String value) {
-    String mod = "now";
-    if (!TextUtils.isEmpty(value) && (value.equalsIgnoreCase("now") || value.equalsIgnoreCase(
-        "wait"))) {
-      mod = value;
-    }
-    if (isDownloadConfig) {
-      mDownloadConfig.queueMod = mod;
-    }
-    if (isUploadConfig) {
-      mUploadConfig.queueMod = mod;
-    }
-  }
-
-  private void loadMaxSpeed(String value) {
-    double maxSpeed = 0.0;
-    if (!TextUtils.isEmpty(value)) {
-      maxSpeed = Double.parseDouble(value);
-    }
-    if (isDownloadConfig) {
-      mDownloadConfig.msxSpeed = maxSpeed;
-    }
-  }
-
-  private void loadConvertSpeed(String value) {
-    boolean open = Boolean.parseBoolean(value);
-    if (isDownloadConfig) {
-      mDownloadConfig.isConvertSpeed = open;
-    }
-    if (isUploadConfig) {
-      mUploadConfig.isConvertSpeed = open;
-    }
-  }
-
-  private void loadReTryInterval(String value) {
-    int time = 2 * 1000;
-    if (!TextUtils.isEmpty(value)) {
-      time = Integer.parseInt(value);
-    }
-
-    if (time < 2 * 1000) {
-      time = 2 * 1000;
-    }
-
-    if (isDownloadConfig) {
-      mDownloadConfig.reTryInterval = time;
-    }
-  }
-
-  private void loadCA(String name, String path) {
-    if (isDownloadConfig) {
-      mDownloadConfig.caName = name;
-      mDownloadConfig.caPath = path;
-    }
-  }
-
-  private void loadBuffSize(String value) {
-    int buffSize = 8192;
-    if (!TextUtils.isEmpty(value)) {
-      buffSize = Integer.parseInt(value);
-    }
-
-    if (buffSize < 2048) {
-      buffSize = 2048;
-    }
-
-    if (isDownloadConfig) {
-      mDownloadConfig.buffSize = buffSize;
-    }
-  }
-
-  private void loadIOTimeout(String value) {
-    int time = 10 * 1000;
-    if (!TextUtils.isEmpty(value)) {
-      time = Integer.parseInt(value);
-    }
-
-    if (time < 10 * 1000) {
-      time = 10 * 1000;
-    }
-
-    if (isDownloadConfig) {
-      mDownloadConfig.iOTimeOut = time;
-    }
-  }
-
-  private void loadConnectTime(String value) {
-    int time = 5 * 1000;
-    if (!TextUtils.isEmpty(value)) {
-      time = Integer.parseInt(value);
-    }
-
-    if (isDownloadConfig) {
-      mDownloadConfig.connectTimeOut = time;
-    }
-    if (isUploadConfig) {
-      mUploadConfig.connectTimeOut = time;
-    }
-  }
-
-  private void loadReTry(String value) {
-    int num = 0;
-    if (!TextUtils.isEmpty(value)) {
-      num = Integer.parseInt(value);
-    }
-
-    if (isDownloadConfig) {
-      mDownloadConfig.reTryNum = num;
-    }
-    if (isUploadConfig) {
-      mUploadConfig.reTryNum = num;
-    }
-  }
-
-  private void loadMaxQueue(String value) {
-    int num = 2;
-    if (!TextUtils.isEmpty(value)) {
-      num = Integer.parseInt(value);
-    }
-    if (num < 1) {
-      Log.e(TAG, "任务队列数不能小于 1");
-      num = 2;
-    }
-    if (isDownloadConfig) {
-      mDownloadConfig.maxTaskNum = num;
-    }
-    if (isUploadConfig) {
-      mUploadConfig.maxTaskNum = num;
-    }
-  }
-
-  private void loadThreadNum(String value) {
-    int num = 3;
-    if (!TextUtils.isEmpty(value)) {
-      num = Integer.parseInt(value);
-    }
-    if (num < 1) {
-      Log.e(TAG, "下载线程数不能小于 1");
-      num = 1;
-    }
-    if (isDownloadConfig) {
-      mDownloadConfig.threadNum = num;
-    }
-  }
-
-  @Override public void characters(char[] ch, int start, int length) throws SAXException {
-    super.characters(ch, start, length);
-  }
-
-  @Override public void endElement(String uri, String localName, String qName) throws SAXException {
-    super.endElement(uri, localName, qName);
-  }
-
-  @Override public void endDocument() throws SAXException {
-    super.endDocument();
-    mDownloadConfig.saveAll();
-    mUploadConfig.saveAll();
-  }
-}

+ 0 - 344
Aria/src/main/java/com/arialyy/aria/core/Configuration.java

@@ -1,344 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.common.QueueMod;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Created by lyy on 2016/12/8.
- * 信息配置
- */
-class Configuration {
-  static final String DOWNLOAD_CONFIG_FILE = "/Aria/DownloadConfig.properties";
-  static final String UPLOAD_CONFIG_FILE = "/Aria/UploadConfig.properties";
-  static final String XML_FILE = "/Aria/aria_config.xml";
-
-  /**
-   * 通用配置
-   */
-  public static class BaseConfig {
-    /**
-     * 旧任务数
-     */
-    public int oldMaxTaskNum = 2;
-
-    /**
-     * 任务队列最大任务数, 默认为2
-     */
-    int maxTaskNum = 2;
-    /**
-     * 下载失败,重试次数,默认为10
-     */
-    int reTryNum = 10;
-    /**
-     * 设置重试间隔,单位为毫秒,默认2000毫秒
-     */
-    int reTryInterval = 2000;
-    /**
-     * 设置url连接超时时间,单位为毫秒,默认5000毫秒
-     */
-    int connectTimeOut = 5000;
-
-    /**
-     * 是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度
-     */
-    boolean isConvertSpeed = false;
-
-    /**
-     * 执行队列类型
-     *
-     * @see QueueMod
-     */
-    String queueMod = "now";
-
-    public String getQueueMod() {
-      return queueMod;
-    }
-
-    public BaseConfig setQueueMod(String queueMod) {
-      this.queueMod = queueMod;
-      saveKey("queueMod", queueMod);
-      return this;
-    }
-
-    public int getMaxTaskNum() {
-      return maxTaskNum;
-    }
-
-    public BaseConfig setMaxTaskNum(int maxTaskNum) {
-      oldMaxTaskNum = this.maxTaskNum;
-      this.maxTaskNum = maxTaskNum;
-      saveKey("maxTaskNum", maxTaskNum + "");
-      DownloadTaskQueue.getInstance().setMaxTaskNum(maxTaskNum);
-      return this;
-    }
-
-    public int getReTryNum() {
-      return reTryNum;
-    }
-
-    public BaseConfig setReTryNum(int reTryNum) {
-      this.reTryNum = reTryNum;
-      saveKey("reTryNum", reTryNum + "");
-      return this;
-    }
-
-    public int getReTryInterval() {
-      return reTryInterval;
-    }
-
-    public BaseConfig setReTryInterval(int reTryInterval) {
-      this.reTryInterval = reTryInterval;
-      saveKey("reTryInterval", reTryInterval + "");
-      return this;
-    }
-
-    public boolean isConvertSpeed() {
-      return isConvertSpeed;
-    }
-
-    public BaseConfig setConvertSpeed(boolean convertSpeed) {
-      isConvertSpeed = convertSpeed;
-      saveKey("isConvertSpeed", isConvertSpeed + "");
-      return this;
-    }
-
-    public int getConnectTimeOut() {
-      return connectTimeOut;
-    }
-
-    public BaseConfig setConnectTimeOut(int connectTimeOut) {
-      this.connectTimeOut = connectTimeOut;
-      saveKey("connectTimeOut", connectTimeOut + "");
-      return this;
-    }
-
-    /**
-     * 保存key
-     */
-    void saveKey(String key, String value) {
-      boolean isDownload = this instanceof DownloadConfig;
-      File file = new File(
-          AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
-              : UPLOAD_CONFIG_FILE));
-      if (file.exists()) {
-        Properties properties = CommonUtil.loadConfig(file);
-        properties.setProperty(key, value);
-        CommonUtil.saveConfig(file, properties);
-      }
-    }
-
-    /**
-     * 加载配置
-     */
-    void loadConfig() {
-      boolean isDownload = this instanceof DownloadConfig;
-      File file = new File(
-          AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
-              : UPLOAD_CONFIG_FILE));
-      if (file.exists()) {
-        Properties properties = CommonUtil.loadConfig(file);
-        List<Field> fields = CommonUtil.getAllFields(getClass());
-        try {
-          for (Field field : fields) {
-            int m = field.getModifiers();
-            if (field.getName().equals("oldMaxTaskNum") || Modifier.isFinal(m) || Modifier.isStatic(
-                m)) {
-              continue;
-            }
-            field.setAccessible(true);
-            String value = properties.getProperty(field.getName());
-            if (TextUtils.isEmpty(value) || value.equalsIgnoreCase("null")) continue;
-            Class<?> type = field.getType();
-            if (type == String.class) {
-              field.set(this, value);
-            } else if (type == int.class || type == Integer.class) {
-              field.setInt(this, Integer.parseInt(value));
-            } else if (type == float.class || type == Float.class) {
-              field.setFloat(this, Float.parseFloat(value));
-            } else if (type == double.class || type == Double.class) {
-              if (TextUtils.isEmpty(value)) {
-                value = "0.0";
-              }
-              field.setDouble(this, Double.parseDouble(value));
-            } else if (type == long.class || type == Long.class) {
-              field.setLong(this, Long.parseLong(value));
-            } else if (type == boolean.class || type == Boolean.class) {
-              field.setBoolean(this, Boolean.parseBoolean(value));
-            }
-          }
-        } catch (IllegalAccessException e) {
-          e.printStackTrace();
-        }
-      }
-    }
-
-    /**
-     * 保存配置
-     */
-    void saveAll() {
-      List<Field> fields = CommonUtil.getAllFields(getClass());
-      boolean isDownload = this instanceof DownloadConfig;
-      try {
-        File file = new File(
-            AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
-                : UPLOAD_CONFIG_FILE));
-        Properties properties = CommonUtil.loadConfig(file);
-        for (Field field : fields) {
-          int m = field.getModifiers();
-          if (Modifier.isFinal(m) || Modifier.isStatic(m)) {
-            continue;
-          }
-          field.setAccessible(true);
-          properties.setProperty(field.getName(), field.get(this) + "");
-        }
-        CommonUtil.saveConfig(file, properties);
-      } catch (IllegalAccessException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * 下载配置
-   */
-  public static class DownloadConfig extends BaseConfig {
-    /**
-     * 设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒
-     */
-    int iOTimeOut = 20 * 1000;
-    /**
-     * 设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢
-     */
-    int buffSize = 8192;
-    /**
-     * 设置https ca 证书信息;path 为assets目录下的CA证书完整路径
-     */
-    String caPath;
-    /**
-     * name 为CA证书名
-     */
-    String caName;
-    /**
-     * 下载线程数,下载线程数不能小于1
-     */
-    int threadNum = 3;
-
-    /**
-     * 设置最大下载速度,单位:kb, 为0表示不限速
-     */
-    double msxSpeed = 0.0;
-
-    public int getIOTimeOut() {
-      return iOTimeOut;
-    }
-
-    public double getMsxSpeed() {
-      return msxSpeed;
-    }
-
-    public DownloadConfig setMsxSpeed(double msxSpeed) {
-      this.msxSpeed = msxSpeed;
-      saveKey("msxSpeed", String.valueOf(msxSpeed));
-      DownloadTaskQueue.getInstance().setMaxSpeed(msxSpeed);
-      return this;
-    }
-
-    public DownloadConfig setIOTimeOut(int iOTimeOut) {
-      this.iOTimeOut = iOTimeOut;
-      saveKey("iOTimeOut", iOTimeOut + "");
-      return this;
-    }
-
-    public int getBuffSize() {
-      return buffSize;
-    }
-
-    public DownloadConfig setBuffSize(int buffSize) {
-      this.buffSize = buffSize;
-      saveKey("buffSize", buffSize + "");
-      return this;
-    }
-
-    public String getCaPath() {
-      return caPath;
-    }
-
-    public DownloadConfig setCaPath(String caPath) {
-      this.caPath = caPath;
-      saveKey("caPath", caPath);
-      return this;
-    }
-
-    public String getCaName() {
-      return caName;
-    }
-
-    public DownloadConfig setCaName(String caName) {
-      this.caName = caName;
-      saveKey("caName", caName);
-      return this;
-    }
-
-    public int getThreadNum() {
-      return threadNum;
-    }
-
-    private DownloadConfig() {
-      loadConfig();
-    }
-
-    private static DownloadConfig INSTANCE = null;
-
-    static DownloadConfig getInstance() {
-      if (INSTANCE == null) {
-        synchronized (DownloadConfig.class) {
-          INSTANCE = new DownloadConfig();
-        }
-      }
-      return INSTANCE;
-    }
-  }
-
-  /**
-   * 上传配置
-   */
-  public static class UploadConfig extends BaseConfig {
-
-    private UploadConfig() {
-      loadConfig();
-    }
-
-    private static UploadConfig INSTANCE = null;
-
-    static UploadConfig getInstance() {
-      if (INSTANCE == null) {
-        synchronized (DownloadConfig.class) {
-          INSTANCE = new UploadConfig();
-        }
-      }
-      return INSTANCE;
-    }
-  }
-}

+ 0 - 111
Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java

@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core;
-
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Message;
-import android.util.Log;
-import android.widget.PopupWindow;
-import com.arialyy.aria.util.CommonUtil;
-import java.lang.reflect.Field;
-
-/**
- * Created by lyy on 2017/2/7.
- * 为组件添加生命周期
- */
-final class WidgetLiftManager {
-  private final String TAG = "WidgetLiftManager";
-
-  /**
-   * 处理悬浮框取消或dismiss事件
-   */
-  void handlePopupWindowLift(PopupWindow popupWindow) {
-    try {
-      Field dismissField = CommonUtil.getField(popupWindow.getClass(), "mOnDismissListener");
-      PopupWindow.OnDismissListener listener =
-          (PopupWindow.OnDismissListener) dismissField.get(popupWindow);
-      if (listener != null) {
-        Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露,"
-            + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
-      } else {
-        popupWindow.setOnDismissListener(createPopupWindowListener(popupWindow));
-      }
-    } catch (IllegalAccessException e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
-   * 创建popupWindow dismiss事件
-   */
-  private PopupWindow.OnDismissListener createPopupWindowListener(final PopupWindow popupWindow) {
-    return new PopupWindow.OnDismissListener() {
-      @Override public void onDismiss() {
-        AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(popupWindow);
-      }
-    };
-  }
-
-  /**
-   * 处理对话框取消或dismiss
-   */
-  void handleDialogLift(Dialog dialog) {
-    try {
-      Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage");
-      Message dismissMsg = (Message) dismissField.get(dialog);
-      //如果Dialog已经设置Dismiss事件,则查找cancel事件
-      if (dismissMsg != null) {
-        Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage");
-        Message cancelMsg = (Message) cancelField.get(dialog);
-        if (cancelMsg != null) {
-          Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
-              + "请在dismiss方法中调用Aria.download(this).removeSchedulerListener();来注销事件");
-        } else {
-          dialog.setOnCancelListener(createCancelListener());
-        }
-      } else {
-        dialog.setOnDismissListener(createDismissListener());
-      }
-    } catch (IllegalAccessException e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
-   * 创建Dialog取消事件
-   */
-  private Dialog.OnCancelListener createCancelListener() {
-    return new Dialog.OnCancelListener() {
-
-      @Override public void onCancel(DialogInterface dialog) {
-        AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(dialog);
-      }
-    };
-  }
-
-  /**
-   * 创建Dialog dismiss取消事件
-   */
-  private Dialog.OnDismissListener createDismissListener() {
-    return new Dialog.OnDismissListener() {
-
-      @Override public void onDismiss(DialogInterface dialog) {
-        AriaManager.getInstance(AriaManager.APP).destroySchedulerListener(dialog);
-      }
-    };
-  }
-}

+ 0 - 35
Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java

@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.queue.ITaskQueue;
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-public abstract class AbsCmd<T extends AbsTaskEntity> implements ICmd{
-  protected ITaskQueue mQueue;
-  protected T mTaskEntity;
-  protected String TAG;
-  protected String mTargetName;
-  /**
-   * 是否是下载任务的命令
-   * {@code true} 下载任务的命令,{@code false} 上传任务的命令
-   */
-  protected boolean isDownloadCmd = true;
-}

+ 0 - 31
Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java

@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 抽象命令工厂
- */
-public abstract class AbsCmdFactory<CMD extends AbsCmd> {
-
-  /**
-   * @param target 创建任务的对象
-   * @param entity 下载实体
-   */
-  public abstract <T extends AbsTaskEntity> CMD createCmd(String target, T entity, int type);
-}

+ 0 - 27
Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java

@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command;
-
-/**
- * Created by lyy on 2017/2/9.
- */
-
-public interface ICmd {
-  /**
-   * 执行命令
-   */
-  void executeCmd();
-}

+ 0 - 46
Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java

@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.group;
-
-import com.arialyy.aria.core.command.AbsCmd;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-import com.arialyy.aria.core.queue.UploadTaskQueue;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 任务组命令
- */
-abstract class AbsGroupCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
-
-  /**
-   * @param targetName 创建任务的对象名
-   */
-  AbsGroupCmd(String targetName, T entity) {
-    mTargetName = targetName;
-    mTaskEntity = entity;
-    TAG = CommonUtil.getClassName(this);
-    if (entity instanceof DownloadGroupTaskEntity) {
-      mQueue = DownloadGroupTaskQueue.getInstance();
-      isDownloadCmd = true;
-    }
-  }
-}

+ 0 - 35
Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java

@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.group;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 删除任务组
- */
-class GroupCancelCmd<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
-  /**
-   * @param targetName 创建任务的对象名
-   */
-  GroupCancelCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-
-  }
-}

+ 0 - 71
Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java

@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.group;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.command.AbsCmdFactory;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-class GroupCmdFactory extends AbsCmdFactory<AbsGroupCmd> {
-  /**
-   * 启动任务
-   */
-  public static final int TASK_START = 0xa1;
-  /**
-   * 停止任务
-   */
-  public static final int TASK_STOP = 0xa2;
-  /**
-   * 取消任务
-   */
-  public static final int TASK_CANCEL = 0xa3;
-
-  private static volatile GroupCmdFactory INSTANCE = null;
-
-  private GroupCmdFactory() {
-
-  }
-
-  public static GroupCmdFactory getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new GroupCmdFactory();
-      }
-    }
-    return INSTANCE;
-  }
-
-  /**
-   * @param target 创建任务的对象
-   * @param entity 下载实体
-   * @param type 命令类型{@link #TASK_START}、{@link #TASK_CANCEL}、{@link #TASK_STOP}
-   */
-  public <T extends AbsTaskEntity> AbsGroupCmd<T> createCmd(String target, T entity, int type) {
-    switch (type) {
-      case TASK_START:
-        return new GroupStartCmd<>(target, entity);
-      case TASK_STOP:
-        return new GroupStopCmd<>(target, entity);
-      case TASK_CANCEL:
-        return new GroupCancelCmd<>(target, entity);
-      default:
-        return null;
-    }
-  }
-}

+ 0 - 72
Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java

@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.group;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.QueueMod;
-import com.arialyy.aria.core.inf.AbsGroupTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IEntity;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 任务组开始命令,该命令负责开始下载或恢复下载的操作
- */
-class GroupStartCmd<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
-  /**
-   * @param targetName 创建任务的对象名
-   */
-  GroupStartCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    String mod;
-    int maxTaskNum;
-    AriaManager manager = AriaManager.getInstance(AriaManager.APP);
-    if (isDownloadCmd) {
-      mod = manager.getDownloadConfig().getQueueMod();
-      maxTaskNum = manager.getDownloadConfig().getMaxTaskNum();
-    } else {
-      mod = manager.getUploadConfig().getQueueMod();
-      maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
-    }
-
-    AbsGroupTask task = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity());
-    if (task == null) {
-      task = (AbsGroupTask) mQueue.createTask(mTargetName, mTaskEntity);
-      if (!TextUtils.isEmpty(mTargetName)) {
-        task.setTargetName(mTargetName);
-      }
-      // 任务不存在时,根据配置不同,对任务执行操作
-      if (mod.equals(QueueMod.NOW.getTag())) {
-        mQueue.startTask(task);
-      } else if (mod.equals(QueueMod.WAIT.getTag())) {
-        if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
-          mQueue.startTask(task);
-        }
-      }
-    } else {
-      // 任务不存在时,根据配置不同,对任务执行操作
-      if (!task.isRunning()
-          && mod.equals(QueueMod.WAIT.getTag())
-          && task.getState() == IEntity.STATE_WAIT) {
-        mQueue.startTask(task);
-      }
-    }
-  }
-}

+ 0 - 35
Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java

@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.group;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 停止任务组的命令
- */
-class GroupStopCmd<T extends AbsTaskEntity> extends AbsGroupCmd<T>{
-  /**
-   * @param targetName 创建任务的对象名
-   */
-  GroupStopCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-
-  }
-}

+ 0 - 149
Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java

@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import com.arialyy.aria.core.command.AbsCmd;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-import com.arialyy.aria.core.queue.UploadTaskQueue;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-
-/**
- * Created by lyy on 2016/8/22.
- * 下载命令
- */
-public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
-  /**
-   * 能否执行命令
-   */
-  boolean canExeCmd = true;
-
-  private AbsTask tempTask = null;
-
-  /**
-   * @param targetName 产生任务的对象名
-   */
-  AbsNormalCmd(String targetName, T entity) {
-    //canExeCmd = CheckUtil.checkCmdEntity(entity,
-    //    !(this instanceof CancelCmd) || !(this instanceof StopCmd));
-    mTargetName = targetName;
-    mTaskEntity = entity;
-    TAG = CommonUtil.getClassName(this);
-    if (entity instanceof DownloadTaskEntity) {
-      mQueue = DownloadTaskQueue.getInstance();
-      isDownloadCmd = true;
-    } else if (entity instanceof UploadTaskEntity) {
-      mQueue = UploadTaskQueue.getInstance();
-      isDownloadCmd = false;
-    } else if (entity instanceof DownloadGroupTaskEntity) {
-      mQueue = DownloadGroupTaskQueue.getInstance();
-      isDownloadCmd = true;
-    }
-  }
-
-  /**
-   * 删除所有任务
-   */
-  void removeAll() {
-    mQueue.removeAllTask();
-  }
-
-  /**
-   * 停止所有任务
-   */
-  void stopAll() {
-    mQueue.stopAllTask();
-  }
-
-  /**
-   * 停止任务
-   */
-  void stopTask() {
-    if (tempTask == null) createTask();
-    mQueue.stopTask(tempTask);
-  }
-
-  /**
-   * 删除任务
-   */
-  void removeTask() {
-    if (tempTask == null) createTask();
-    mQueue.removeTask(tempTask);
-  }
-
-  /**
-   * 启动任务
-   */
-  void startTask() {
-    mQueue.startTask(tempTask);
-  }
-
-  /**
-   * 启动指定任务
-   *
-   * @param task 指定任务
-   */
-  void startTask(AbsTask task) {
-    mQueue.startTask(task);
-  }
-
-  /**
-   * 从队列中获取任务
-   *
-   * @return 执行任务
-   */
-  AbsTask getTask() {
-    tempTask = mQueue.getTask(mTaskEntity.getEntity());
-    return tempTask;
-  }
-
-  /**
-   * 从队列中获取任务
-   *
-   * @return 执行任务
-   */
-  AbsTask getTask(AbsEntity entity) {
-    tempTask = mQueue.getTask(entity);
-    return tempTask;
-  }
-
-  /**
-   * 创建任务
-   *
-   * @return 创建的任务
-   */
-  AbsTask createTask() {
-    tempTask = mQueue.createTask(mTargetName, mTaskEntity);
-    return tempTask;
-  }
-
-  /**
-   * 创建指定实体的任务
-   *
-   * @param taskEntity 特定的任务实体
-   * @return 创建的任务
-   */
-  AbsTask createTask(AbsTaskEntity taskEntity) {
-    return mQueue.createTask(mTargetName, taskEntity);
-  }
-}

+ 0 - 44
Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java

@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import android.util.Log;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by lyy on 2016/8/22.
- * 添加任务的命令
- */
-class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-
-  AddCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (!canExeCmd) return;
-    AbsTask task = getTask();
-    if (task == null) {
-      mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
-      createTask();
-    } else {
-      Log.w(TAG, "添加命令执行失败,【该任务已经存在】");
-    }
-  }
-}

+ 0 - 68
Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java

@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.List;
-
-/**
- * Created by AriaL on 2017/6/27.
- * 删除所有任务,并且删除所有回掉
- */
-final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-  /**
-   * @param targetName 产生任务的对象名
-   */
-  CancelAllCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    removeAll();
-    if (mTaskEntity instanceof DownloadTaskEntity) {
-      handleDownloadRemove();
-    } else if (mTaskEntity instanceof UploadTaskEntity){
-      handleUploadRemove();
-    }
-  }
-
-  /**
-   * 处理上传的删除
-   */
-  private void handleUploadRemove() {
-    List<UploadTaskEntity> allEntity = DbEntity.findAllData(UploadTaskEntity.class);
-    if (allEntity == null || allEntity.size() == 0) return;
-    for (UploadTaskEntity entity : allEntity) {
-      CommonUtil.delUploadTaskConfig(mTaskEntity.removeFile, entity);
-    }
-  }
-
-  /**
-   * 处理下载的删除
-   */
-  private void handleDownloadRemove() {
-    List<DownloadTaskEntity> allEntity = DbEntity.findAllData(DownloadTaskEntity.class);
-    if (allEntity == null || allEntity.size() == 0) return;
-    for (DownloadTaskEntity entity : allEntity) {
-      CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, entity);
-    }
-  }
-}

+ 0 - 45
Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java

@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by lyy on 2016/9/20.
- * 取消命令
- */
-class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-  CancelCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (!canExeCmd) return;
-    AbsTask task = getTask();
-    if (task == null) {
-      task = createTask();
-    }
-    if (task != null) {
-      if (!TextUtils.isEmpty(mTargetName)) {
-        task.setTargetName(mTargetName);
-      }
-      removeTask();
-    }
-  }
-}

+ 0 - 57
Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java

@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.command.normal;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.inf.AbsNormalTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-
-/**
- * Created by lyy on 2017/6/2.
- * 最高优先级命令,最高优先级命令有以下属性
- * 1、在下载队列中,有且只有一个最高优先级任务
- * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
- * 3、任务调度器不会暂停最高优先级任务
- * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
- * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行
- * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
- *
- * 目前只只支持单下载任务的最高优先级任务
- */
-final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-  /**
-   * @param targetName 产生任务的对象名
-   */
-  HighestPriorityCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (!canExeCmd) return;
-    DownloadTask task = (DownloadTask) getTask();
-    if (task == null) {
-      task = (DownloadTask) createTask();
-    }
-    if (task != null) {
-      if (!TextUtils.isEmpty(mTargetName)) {
-        task.setTargetName(mTargetName);
-      }
-      ((DownloadTaskQueue) mQueue).setTaskHighestPriority(task);
-    }
-  }
-}

+ 0 - 108
Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java

@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.command.AbsCmdFactory;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by Lyy on 2016/9/23.
- * 命令工厂
- */
-public class NormalCmdFactory extends AbsCmdFactory<AbsNormalCmd> {
-  /**
-   * 创建任务
-   */
-  public static final int TASK_CREATE = 0x122;
-  /**
-   * 启动任务
-   */
-  public static final int TASK_START = 0x123;
-  /**
-   * 恢复任务
-   */
-  public static final int TASK_RESUME = 0x127;
-  /**
-   * 取消任务
-   */
-  public static final int TASK_CANCEL = 0x124;
-  /**
-   * 停止任务
-   */
-  public static final int TASK_STOP = 0x125;
-  /**
-   * 设置任务为最高优先级
-   */
-  public static final int TASK_HIGHEST_PRIORITY = 0x128;
-  /**
-   * 停止所有任务
-   */
-  public static final int TASK_STOP_ALL = 0x129;
-  /**
-   * 恢复所有停止的任务
-   */
-  public static final int TASK_RESUME_ALL = 0x130;
-  /**
-   * 删除所有任务,
-   */
-  public static final int TASK_CANCEL_ALL = 0x131;
-  private static volatile NormalCmdFactory INSTANCE = null;
-
-  private NormalCmdFactory() {
-
-  }
-
-  public static NormalCmdFactory getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new NormalCmdFactory();
-      }
-    }
-    return INSTANCE;
-  }
-
-  /**
-   * @param target 创建任务的对象
-   * @param entity 下载实体
-   * @param type 命令类型{@link #TASK_CREATE}、{@link #TASK_START}、{@link #TASK_CANCEL}、{@link
-   * #TASK_STOP}、{@link #TASK_HIGHEST_PRIORITY}、{@link #TASK_STOP_ALL}、{@link #TASK_RESUME_ALL}
-   */
-  public <T extends AbsTaskEntity> AbsNormalCmd<T> createCmd(String target, T entity, int type) {
-    switch (type) {
-      case TASK_CREATE:
-        return new AddCmd<>(target, entity);
-      case TASK_RESUME:
-      case TASK_START:
-        return new StartCmd<>(target, entity);
-      case TASK_CANCEL:
-        return new CancelCmd<>(target, entity);
-      case TASK_STOP:
-        return new StopCmd<>(target, entity);
-      case TASK_HIGHEST_PRIORITY:
-        return new HighestPriorityCmd<>(target, entity);
-      case TASK_STOP_ALL:
-        return new StopAllCmd<>(target, entity);
-      case TASK_RESUME_ALL:
-        return new ResumeAllCmd<>(target, entity);
-      case TASK_CANCEL_ALL:
-        return new CancelAllCmd<>(target, entity);
-      default:
-        return null;
-    }
-  }
-}

+ 0 - 90
Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java

@@ -1,90 +0,0 @@
-package com.arialyy.aria.core.command.normal;
-
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
-import com.arialyy.aria.core.queue.DownloadTaskQueue;
-import com.arialyy.aria.core.queue.UploadTaskQueue;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.orm.DbEntity;
-import java.util.List;
-
-/**
- * Created by AriaL on 2017/6/13.
- * 恢复所有停止的任务
- * 1.如果执行队列没有满,则开始下载任务,直到执行队列满
- * 2.如果队列执行队列已经满了,则将所有任务添加到等待队列中
- */
-final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-  /**
-   * @param targetName 产生任务的对象名
-   */
-  ResumeAllCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (isDownloadCmd) {
-      resumeDownload();
-    } else {
-      resumeUpload();
-    }
-  }
-
-  /**
-   * 恢复下载,包括普通任务和任务组
-   */
-  private void resumeDownload() {
-    List<DownloadTaskEntity> dTaskEntity =
-        DbEntity.findDatas(DownloadTaskEntity.class, "isGroupTask=?", "false");
-    for (DownloadTaskEntity te : dTaskEntity) {
-      int state = te.getState();
-      if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
-      resumeEntity(te);
-    }
-
-    List<DownloadGroupTaskEntity> groupTask = DbEntity.findAllData(DownloadGroupTaskEntity.class);
-    for (DownloadGroupTaskEntity te : groupTask) {
-      int state = te.getState();
-      if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
-      resumeEntity(te);
-    }
-  }
-
-  /**
-   * 恢复上传,包括普通任务和任务组
-   */
-  private void resumeUpload() {
-    List<UploadTaskEntity> dTaskEntity =
-        DbEntity.findDatas(UploadTaskEntity.class, "isGroupTask=?", "false");
-    for (UploadTaskEntity te : dTaskEntity) {
-      int state = te.getState();
-      if (state == IEntity.STATE_COMPLETE || state == IEntity.STATE_FAIL) continue;
-      resumeEntity(te);
-    }
-  }
-
-  /**
-   * 恢复实体任务
-   *
-   * @param te 任务实体
-   */
-  private void resumeEntity(AbsTaskEntity te) {
-    if (te instanceof DownloadTaskEntity) {
-      mQueue = DownloadTaskQueue.getInstance();
-    } else if (te instanceof UploadTaskEntity) {
-      mQueue = UploadTaskQueue.getInstance();
-    } else if (te instanceof DownloadGroupTaskEntity) {
-      mQueue = DownloadGroupTaskQueue.getInstance();
-    }
-    int exeNum = mQueue.getCurrentExePoolNum();
-    if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) {
-      startTask(createTask(te));
-    } else {
-      te.getEntity().setState(IEntity.STATE_WAIT);
-      createTask(te);
-    }
-  }
-}

+ 0 - 73
Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java

@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.QueueMod;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by lyy on 2016/8/22.
- * 开始命令
- * 队列模型{@link QueueMod#NOW}、{@link QueueMod#WAIT}
- */
-class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-
-  StartCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (!canExeCmd) return;
-    String mod;
-    int maxTaskNum;
-    AriaManager manager = AriaManager.getInstance(AriaManager.APP);
-    if (isDownloadCmd) {
-      mod = manager.getDownloadConfig().getQueueMod();
-      maxTaskNum = manager.getDownloadConfig().getMaxTaskNum();
-    } else {
-      mod = manager.getUploadConfig().getQueueMod();
-      maxTaskNum = manager.getUploadConfig().getMaxTaskNum();
-    }
-
-    AbsTask task = getTask();
-    if (task == null) {
-      task = createTask();
-      if (!TextUtils.isEmpty(mTargetName)) {
-        task.setTargetName(mTargetName);
-      }
-      // 任务不存在时,根据配置不同,对任务执行操作
-      if (mod.equals(QueueMod.NOW.getTag())) {
-        startTask();
-      } else if (mod.equals(QueueMod.WAIT.getTag())) {
-        if (mQueue.getCurrentExePoolNum() < maxTaskNum
-            || task.getState() == IEntity.STATE_STOP
-            || task.getState() == IEntity.STATE_COMPLETE) {
-          startTask();
-        }
-      }
-    } else {
-      // 任务不存在时,根据配置不同,对任务执行操作
-      if (!task.isRunning()) {
-        startTask();
-      }
-    }
-  }
-}

+ 0 - 20
Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java

@@ -1,20 +0,0 @@
-package com.arialyy.aria.core.command.normal;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by AriaL on 2017/6/13.
- * 停止所有任务的命令,并清空所有等待队列
- */
-final class StopAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-  /**
-   * @param targetName 产生任务的对象名
-   */
-  StopAllCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    stopAll();
-  }
-}

+ 0 - 51
Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java

@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.command.normal;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by lyy on 2016/9/20.
- * 停止命令
- */
-class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
-
-  StopCmd(String targetName, T entity) {
-    super(targetName, entity);
-  }
-
-  @Override public void executeCmd() {
-    if (!canExeCmd) return;
-    AbsTask task = getTask();
-    if (task == null) {
-      if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) {
-        stopTask();
-      } else {
-        Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】");
-      }
-    } else {
-      if (!TextUtils.isEmpty(mTargetName)) {
-        task.setTargetName(mTargetName);
-      }
-      stopTask();
-    }
-  }
-}

+ 0 - 398
Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java

@@ -1,398 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.common;
-
-import android.content.Context;
-import android.util.Log;
-import android.util.SparseArray;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsNormalEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.core.inf.IEventListener;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * Created by AriaL on 2017/7/1.
- * 文件下载器
- */
-public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
-    implements Runnable, IUtil {
-  private final String TAG = "Downloader";
-  protected IEventListener mListener;
-  protected TASK_ENTITY mTaskEntity;
-  protected ENTITY mEntity;
-  protected File mConfigFile;//信息配置文件
-  protected Context mContext;
-  protected File mTempFile; //下载的文件
-  protected boolean isNewTask = true;
-  protected StateConstance mConstance;
-  private ExecutorService mFixedThreadPool;
-  private int mThreadNum, mRealThreadNum;
-  private SparseArray<AbsThreadTask> mTask = new SparseArray<>();
-
-  /**
-   * 小于1m的文件不启用多线程
-   */
-  private static final long SUB_LEN = 1024 * 1024;
-  private Timer mTimer;
-
-  protected AbsFileer(IEventListener listener, TASK_ENTITY taskEntity) {
-    mListener = listener;
-    mTaskEntity = taskEntity;
-    mEntity = mTaskEntity.getEntity();
-    mContext = AriaManager.APP;
-    mConstance = new StateConstance();
-  }
-
-  @Override public void setMaxSpeed(double maxSpeed) {
-    for (int i = 0; i < mThreadNum; i++) {
-      AbsThreadTask task = mTask.get(i);
-      if (task != null) {
-        task.setMaxSpeed(maxSpeed);
-      }
-    }
-  }
-
-  public StateConstance getConstance() {
-    return mConstance;
-  }
-
-  @Override public void run() {
-    startFlow();
-  }
-
-  /**
-   * 开始下载流程
-   */
-  private void startFlow() {
-    checkTask();
-    if (mListener instanceof IDownloadListener) {
-      ((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
-    }
-    mConstance.cleanState();
-    mConstance.isRunning = true;
-    if (!mTaskEntity.isSupportBP) {
-      mThreadNum = 1;
-      mConstance.THREAD_NUM = mThreadNum;
-      handleNoSupportBP();
-    } else {
-      mThreadNum = isNewTask ? (getNewTaskThreadNum()) : mRealThreadNum;
-      mConstance.THREAD_NUM = mThreadNum;
-      handleBreakpoint();
-    }
-    startTimer();
-  }
-
-  /**
-   * 设置新任务的最大线程数
-   */
-  protected int getNewTaskThreadNum() {
-    return mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.FTP_DIR ? 1
-        : AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
-  }
-
-  /**
-   * 启动进度获取定时器
-   */
-  private void startTimer() {
-    mTimer = new Timer(true);
-    mTimer.schedule(new TimerTask() {
-      @Override public void run() {
-        if (mConstance.isComplete() || !mConstance.isRunning) {
-          closeTimer();
-        } else if (mConstance.CURRENT_LOCATION >= 0) {
-          mListener.onProgress(mConstance.CURRENT_LOCATION);
-        }
-      }
-    }, 0, 1000);
-  }
-
-  private void closeTimer() {
-    if (mTimer != null) {
-      mTimer.purge();
-      mTimer.cancel();
-    }
-  }
-
-  @Override public long getFileSize() {
-    return mEntity.getFileSize();
-  }
-
-  /**
-   * 获取当前下载位置
-   */
-  @Override public long getCurrentLocation() {
-    return mConstance.CURRENT_LOCATION;
-  }
-
-  @Override public boolean isRunning() {
-    return mConstance.isRunning;
-  }
-
-  @Override public void cancel() {
-    closeTimer();
-    mConstance.isRunning = false;
-    mConstance.isCancel = true;
-    if (mFixedThreadPool != null) {
-      mFixedThreadPool.shutdown();
-    }
-    for (int i = 0; i < mThreadNum; i++) {
-      AbsThreadTask task = mTask.get(i);
-      if (task != null) {
-        task.cancel();
-      }
-    }
-    if (mTaskEntity instanceof DownloadTaskEntity) {
-      CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, (DownloadTaskEntity) mTaskEntity);
-    } else if (mTaskEntity instanceof UploadTaskEntity) {
-      CommonUtil.delUploadTaskConfig(mTaskEntity.removeFile, (UploadTaskEntity) mTaskEntity);
-    }
-  }
-
-  @Override public void stop() {
-    closeTimer();
-    if (mConstance.isComplete()) return;
-    mConstance.isStop = true;
-    mConstance.isRunning = false;
-    if (mFixedThreadPool != null) {
-      mFixedThreadPool.shutdown();
-    }
-    for (int i = 0; i < mThreadNum; i++) {
-      AbsThreadTask task = mTask.get(i);
-      if (task != null) {
-        task.stop();
-      }
-    }
-  }
-
-  /**
-   * 直接调用的时候会自动启动线程执行
-   */
-  @Override public void start() {
-    new Thread(this).start();
-  }
-
-  @Override public void resume() {
-    start();
-  }
-
-  /**
-   * 返回该下载器的
-   */
-  public IEventListener getListener() {
-    return mListener;
-  }
-
-  /**
-   * 检查任务是否是新任务,新任务条件:
-   * 1、文件不存在
-   * 2、下载记录文件不存在
-   * 3、下载记录文件缺失或不匹配
-   * 4、数据库记录不存在
-   * 5、不支持断点,则是新任务
-   */
-  protected abstract void checkTask();
-
-  /**
-   * 检查记录文件,如果是新任务返回{@code true},否则返回{@code false}
-   */
-  protected boolean checkConfigFile() {
-    Properties pro = CommonUtil.loadConfig(mConfigFile);
-    if (pro.isEmpty()) {
-      return true;
-    }
-    Set<Object> keys = pro.keySet();
-    int num = 0;
-    for (Object key : keys) {
-      if (String.valueOf(key).contains("_record_")) {
-        num++;
-      }
-    }
-    if (num == 0) {
-      return true;
-    }
-    mRealThreadNum = num;
-    for (int i = 0; i < mRealThreadNum; i++) {
-      if (pro.getProperty(mTempFile.getName() + "_record_" + i) == null) {
-        Object state = pro.getProperty(mTempFile.getName() + "_state_" + i);
-        if (state != null && Integer.parseInt(state + "") == 1) {
-          continue;
-        }
-        return true;
-      }
-    }
-    return false;
-  }
-
-  /**
-   * 恢复记录地址
-   *
-   * @return true 表示下载完成
-   */
-  private boolean resumeRecordLocation(int i, long startL, long endL) {
-    mConstance.CURRENT_LOCATION += endL - startL;
-    Log.d(TAG, "++++++++++ 线程_" + i + "_已经下载完成 ++++++++++");
-    mConstance.COMPLETE_THREAD_NUM++;
-    mConstance.STOP_NUM++;
-    mConstance.CANCEL_NUM++;
-    if (mConstance.isComplete()) {
-      if (mConfigFile.exists()) {
-        mConfigFile.delete();
-      }
-      mListener.onComplete();
-      mConstance.isRunning = false;
-      return true;
-    }
-    return false;
-  }
-
-  /**
-   * 启动断点任务时,创建单线程任务
-   *
-   * @param i 线程id
-   * @param startL 该任务起始位置
-   * @param endL 该任务结束位置
-   * @param fileLength 该任务需要处理的文件长度
-   */
-  private AbsThreadTask createSingThreadTask(int i, long startL, long endL, long fileLength) {
-    SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
-    config.FILE_SIZE = fileLength;
-    config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
-    config.TEMP_FILE = mTempFile;
-    config.THREAD_ID = i;
-    config.START_LOCATION = startL;
-    config.END_LOCATION = endL;
-    config.CONFIG_FILE_PATH = mConfigFile.getPath();
-    config.SUPPORT_BP = mTaskEntity.isSupportBP;
-    config.TASK_ENTITY = mTaskEntity;
-    return selectThreadTask(config);
-  }
-
-  /**
-   * 处理断点
-   */
-  private void handleBreakpoint() {
-    long fileLength = mEntity.getFileSize();
-    Properties pro = CommonUtil.loadConfig(mConfigFile);
-    int blockSize = (int) (fileLength / mThreadNum);
-    int[] recordL = new int[mThreadNum];
-    for (int i = 0; i < mThreadNum; i++) {
-      recordL[i] = -1;
-    }
-    int rl = 0;
-    if (isNewTask) {
-      handleNewTask();
-    }
-    for (int i = 0; i < mThreadNum; i++) {
-      long startL = i * blockSize, endL = (i + 1) * blockSize;
-      Object state = pro.getProperty(mTempFile.getName() + "_state_" + i);
-      if (state != null && Integer.parseInt(state + "") == 1) {  //该线程已经完成
-        if (resumeRecordLocation(i, startL, endL)) return;
-        continue;
-      }
-      //分配下载位置
-      Object record = pro.getProperty(mTempFile.getName() + "_record_" + i);
-      //如果有记录,则恢复下载
-      if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) {
-        Long r = Long.parseLong(record + "");
-        mConstance.CURRENT_LOCATION += r - startL;
-        Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载");
-        startL = r;
-        recordL[rl] = i;
-        rl++;
-      } else {
-        recordL[rl] = i;
-        rl++;
-      }
-      if (i == (mThreadNum - 1)) {
-        //最后一个线程的结束位置即为文件的总长度
-        endL = fileLength;
-      }
-      AbsThreadTask task = createSingThreadTask(i, startL, endL, fileLength);
-      if (task == null) return;
-      mTask.put(i, task);
-    }
-    startSingleTask(recordL);
-  }
-
-  /**
-   * 启动单线程下载任务
-   */
-  private void startSingleTask(int[] recordL) {
-    if (mConstance.CURRENT_LOCATION > 0) {
-      mListener.onResume(mConstance.CURRENT_LOCATION);
-    } else {
-      mListener.onStart(mConstance.CURRENT_LOCATION);
-    }
-    mFixedThreadPool = Executors.newFixedThreadPool(recordL.length);
-    for (int l : recordL) {
-      if (l == -1) continue;
-      Runnable task = mTask.get(l);
-      if (task != null) {
-        mFixedThreadPool.execute(task);
-      }
-    }
-  }
-
-  /**
-   * 处理新任务
-   */
-  protected abstract void handleNewTask();
-
-  /**
-   * 处理不支持断点的下载
-   */
-  private void handleNoSupportBP() {
-    SubThreadConfig<TASK_ENTITY> config = new SubThreadConfig<>();
-    config.FILE_SIZE = mEntity.getFileSize();
-    config.URL = mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getUrl();
-    config.TEMP_FILE = mTempFile;
-    config.THREAD_ID = 0;
-    config.START_LOCATION = 0;
-    config.END_LOCATION = config.FILE_SIZE;
-    config.CONFIG_FILE_PATH = mConfigFile.getPath();
-    config.SUPPORT_BP = mTaskEntity.isSupportBP;
-    config.TASK_ENTITY = mTaskEntity;
-    AbsThreadTask task = selectThreadTask(config);
-    if (task == null) return;
-    mTask.put(0, task);
-    mFixedThreadPool = Executors.newFixedThreadPool(1);
-    mFixedThreadPool.execute(task);
-    mListener.onStart(0);
-  }
-
-  /**
-   * 选择单任务线程的类型
-   */
-  protected abstract AbsThreadTask selectThreadTask(SubThreadConfig<TASK_ENTITY> config);
-
-  protected void failDownload(String errorMsg) {
-    closeTimer();
-    Log.e(TAG, errorMsg);
-    mConstance.isRunning = false;
-    mListener.onFail();
-  }
-}

+ 0 - 204
Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java

@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.common;
-
-import android.os.Build;
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IEventListener;
-import com.arialyy.aria.core.upload.UploadEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.Properties;
-
-/**
- * Created by lyy on 2017/1/18.
- * 下载线程
- */
-public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
-    implements Runnable {
-  private final String TAG = "AbsThreadTask";
-  protected long mChildCurrentLocation = 0, mSleepTime = 0;
-  protected int mBufSize;
-  protected String mConfigFPath;
-  protected IEventListener mListener;
-  protected StateConstance STATE;
-  protected SubThreadConfig<TASK_ENTITY> mConfig;
-  protected ENTITY mEntity;
-  protected TASK_ENTITY mTaskEntity;
-  /**
-   * FTP 服务器编码
-   */
-  public static String SERVER_CHARSET = "ISO-8859-1";
-
-  protected AbsThreadTask(StateConstance constance, IEventListener listener,
-      SubThreadConfig<TASK_ENTITY> info) {
-    AriaManager manager = AriaManager.getInstance(AriaManager.APP);
-    STATE = constance;
-    STATE.CONNECT_TIME_OUT = manager.getDownloadConfig().getConnectTimeOut();
-    STATE.READ_TIME_OUT = manager.getDownloadConfig().getIOTimeOut();
-    mListener = listener;
-    mConfig = info;
-    mTaskEntity = mConfig.TASK_ENTITY;
-    mEntity = mTaskEntity.getEntity();
-    if (mConfig.SUPPORT_BP) {
-      mConfigFPath = info.CONFIG_FILE_PATH;
-    }
-    mBufSize = manager.getDownloadConfig().getBuffSize();
-    setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed());
-  }
-
-  public void setMaxSpeed(double maxSpeed) {
-    if (-0.9999 < maxSpeed && maxSpeed < 0.00001) {
-      mSleepTime = 0;
-    } else {
-      BigDecimal db = new BigDecimal(
-          ((mBufSize / 1024) * (filterVersion() ? 1 : STATE.THREAD_NUM) / maxSpeed) * 1000);
-      mSleepTime = db.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
-    }
-  }
-
-  private boolean filterVersion() {
-    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
-  }
-
-  /**
-   * 停止下载
-   */
-  public void stop() {
-    synchronized (AriaManager.LOCK) {
-      try {
-        if (mConfig.SUPPORT_BP) {
-          STATE.STOP_NUM++;
-          Log.d(TAG, "任务【"
-              + mConfig.TEMP_FILE.getName()
-              + "】thread__"
-              + mConfig.THREAD_ID
-              + "__停止, stop location ==> "
-              + mChildCurrentLocation);
-          writeConfig(false, mChildCurrentLocation);
-          if (STATE.isStop()) {
-            Log.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】已停止");
-            STATE.isRunning = false;
-            mListener.onStop(STATE.CURRENT_LOCATION);
-          }
-        } else {
-          Log.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】已停止");
-          STATE.isRunning = false;
-          mListener.onStop(STATE.CURRENT_LOCATION);
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * 下载中
-   */
-  protected void progress(long len) {
-    synchronized (AriaManager.LOCK) {
-      mChildCurrentLocation += len;
-      STATE.CURRENT_LOCATION += len;
-    }
-  }
-
-  /**
-   * 取消下载
-   */
-  public void cancel() {
-    synchronized (AriaManager.LOCK) {
-      if (mConfig.SUPPORT_BP) {
-        STATE.CANCEL_NUM++;
-        Log.d(TAG,
-            "任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__取消下载");
-        if (STATE.isCancel()) {
-          File configFile = new File(mConfigFPath);
-          if (configFile.exists()) {
-            configFile.delete();
-          }
-          if (mConfig.TEMP_FILE.exists() && !(mEntity instanceof UploadEntity)) {
-            mConfig.TEMP_FILE.delete();
-          }
-          Log.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】已取消");
-          STATE.isRunning = false;
-          mListener.onCancel();
-        }
-      } else {
-        Log.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】已取消");
-        STATE.isRunning = false;
-        mListener.onCancel();
-      }
-    }
-  }
-
-  /**
-   * 任务失败
-   */
-  protected void fail(long currentLocation, String msg, Exception ex) {
-    synchronized (AriaManager.LOCK) {
-      try {
-        STATE.FAIL_NUM++;
-        STATE.isRunning = false;
-        STATE.isStop = true;
-        if (ex != null) {
-          Log.e(TAG, msg + "\n" + CommonUtil.getPrintException(ex));
-        } else {
-          Log.e(TAG, msg);
-        }
-        if (mConfig.SUPPORT_BP) {
-          writeConfig(false, currentLocation);
-          if (STATE.isFail()) {
-            Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
-            mListener.onFail();
-          }
-        } else {
-          Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败");
-          mListener.onFail();
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * 将记录写入到配置文件
-   */
-  protected void writeConfig(boolean isComplete, long record) throws IOException {
-    synchronized (AriaManager.LOCK) {
-      String key = null, value = null;
-      if (0 < record && record < mConfig.END_LOCATION) {
-        key = mConfig.TEMP_FILE.getName() + "_record_" + mConfig.THREAD_ID;
-        value = String.valueOf(record);
-      } else if (record >= mConfig.END_LOCATION || isComplete) {
-        key = mConfig.TEMP_FILE.getName() + "_state_" + mConfig.THREAD_ID;
-        value = "1";
-      }
-      if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
-        File configFile = new File(mConfigFPath);
-        Properties pro = CommonUtil.loadConfig(configFile);
-        pro.setProperty(key, value);
-        CommonUtil.saveConfig(configFile, pro);
-      }
-    }
-  }
-}

+ 0 - 66
Aria/src/main/java/com/arialyy/aria/core/common/IUtil.java

@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.common;
-
-/**
- * Created by lyy on 2016/10/31.
- * 抽象的下载接口
- */
-public interface IUtil {
-
-  /**
-   * 获取文件大小
-   */
-  long getFileSize();
-
-  /**
-   * 获取当前下载位置
-   */
-  long getCurrentLocation();
-
-  /**
-   * 是否正在下载
-   *
-   * @return true, 正在下载
-   */
-  boolean isRunning();
-
-  /**
-   * 取消下载
-   */
-  void cancel();
-
-  /**
-   * 停止下载
-   */
-  void stop();
-
-  /**
-   * 开始下载
-   */
-  void start();
-
-  /**
-   * 从上次断点恢复下载
-   */
-  void resume();
-
-  /**
-   * 设置最大下载速度
-   */
-  void setMaxSpeed(double maxSpeed);
-}

+ 0 - 78
Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java

@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.common;
-
-import com.arialyy.aria.core.AriaManager;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Set;
-
-import static java.util.Collections.unmodifiableSet;
-
-/**
- * Created by Aria.Lao on 2017/7/10.
- * 代理参数获取
- */
-public class ProxyHelper {
-  public Set<String> downloadCounter, uploadCounter, downloadGroupCounter;
-
-  public static volatile ProxyHelper INSTANCE = null;
-
-  private ProxyHelper() {
-    init();
-  }
-
-  public static ProxyHelper getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new ProxyHelper();
-      }
-    }
-    return INSTANCE;
-  }
-
-  private void init() {
-    try {
-      Class clazz = Class.forName("com.arialyy.aria.ProxyClassCounter");
-      Method download = clazz.getMethod("getDownloadCounter");
-      Method downloadGroup = clazz.getMethod("getDownloadGroupCounter");
-      Method upload = clazz.getMethod("getUploadCounter");
-      Object object = clazz.newInstance();
-      Object dc = download.invoke(object);
-      if (dc != null) {
-        downloadCounter = unmodifiableSet((Set<String>) dc);
-      }
-      Object dgc = downloadGroup.invoke(object);
-      if (dgc != null) {
-        downloadGroupCounter = unmodifiableSet((Set<String>) dgc);
-      }
-      Object uc = upload.invoke(object);
-      if (uc != null) {
-        uploadCounter = unmodifiableSet((Set<String>) uc);
-      }
-    } catch (ClassNotFoundException e) {
-      e.printStackTrace();
-    } catch (InstantiationException e) {
-      e.printStackTrace();
-    } catch (IllegalAccessException e) {
-      e.printStackTrace();
-    } catch (NoSuchMethodException e) {
-      e.printStackTrace();
-    } catch (InvocationTargetException e) {
-      e.printStackTrace();
-    }
-  }
-}

+ 0 - 31
Aria/src/main/java/com/arialyy/aria/core/common/QueueMod.java

@@ -1,31 +0,0 @@
-package com.arialyy.aria.core.common;
-
-/**
- * Created by Aria.Lao on 2017/6/21.
- * 执行队列类型
- */
-public enum QueueMod {
-  /**
-   * 等待模式,
-   * 如果执行队列已经满了,再对其它任务(TASK_A)使用start命令执行任务时
-   * 1、TASK_A添加到缓存队列中,当执行队列中的任务完成时,系统会将自动执行缓存队列中的TASK_A
-   * 2、如果再次对TASK_A使用start命令,TASK_A将会立刻执行
-   */
-  WAIT("wait"),
-
-  /**
-   * 立刻执行模式
-   * 如果执行队列已经满了,再次使用start命令执行任务时,该任务会添加到执行队列队尾,而原来执行队列的队首任务会停止
-   */
-  NOW("now");
-
-  public String tag;
-
-  public String getTag() {
-    return tag;
-  }
-
-  QueueMod(String tag) {
-    this.tag = tag;
-  }
-}

+ 0 - 31
Aria/src/main/java/com/arialyy/aria/core/common/RequestEnum.java

@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.common;
-
-/**
- * Created by lyy on 2017/1/23.
- * url请求方式,目前支持GET、POST
- */
-public enum RequestEnum {
-  GET("GET"), POST("POST");
-
-  public String name;
-
-  RequestEnum(String name) {
-    this.name = name;
-  }
-
-}

+ 0 - 75
Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java

@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.common;
-
-/**
- * Created by lyy on 2017/1/18.
- * 下载状态常量
- */
-public class StateConstance {
-  public int CANCEL_NUM = 0;
-  public int STOP_NUM = 0;
-  public int FAIL_NUM = 0;
-  public int CONNECT_TIME_OUT; //连接超时时间
-  public int READ_TIME_OUT; //流读取的超时时间
-  public int COMPLETE_THREAD_NUM = 0;
-  public int THREAD_NUM;
-  public long CURRENT_LOCATION = 0;
-  public boolean isRunning = false;
-  public boolean isCancel = false;
-  public boolean isStop = false;
-
-  public StateConstance() {
-  }
-
-  public void cleanState() {
-    isCancel = false;
-    isStop = false;
-    isRunning = true;
-    CURRENT_LOCATION = 0;
-    CANCEL_NUM = 0;
-    STOP_NUM = 0;
-    FAIL_NUM = 0;
-  }
-
-  /**
-   * 所有子线程是否都已经停止下载
-   */
-  public boolean isStop() {
-    return STOP_NUM == THREAD_NUM;
-  }
-
-  /**
-   * 所有子线程是否都已经下载失败
-   */
-  public boolean isFail() {
-    return FAIL_NUM == THREAD_NUM;
-  }
-
-  /**
-   * 所有子线程是否都已经完成下载
-   */
-  public boolean isComplete() {
-    return COMPLETE_THREAD_NUM == THREAD_NUM;
-  }
-
-  /**
-   * 所有子线程是否都已经取消下载
-   */
-  public boolean isCancel() {
-    return CANCEL_NUM == THREAD_NUM;
-  }
-}

+ 0 - 25
Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java

@@ -1,25 +0,0 @@
-package com.arialyy.aria.core.common;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import java.io.File;
-
-/**
- * 子线程下载信息类
- */
-public class SubThreadConfig<TASK_ENTITY extends AbsTaskEntity> {
-  //线程Id
-  public int THREAD_ID;
-  //下载文件大小
-  public long FILE_SIZE;
-  //子线程启动下载位置
-  public long START_LOCATION;
-  //子线程结束下载位置
-  public long END_LOCATION;
-  //下载文件或上传的文件路径
-  public File TEMP_FILE;
-  //服务器地址
-  public String URL;
-  public String CONFIG_FILE_PATH;
-  public TASK_ENTITY TASK_ENTITY;
-  public boolean SUPPORT_BP = true;
-}

+ 0 - 152
Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java

@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.os.Handler;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.inf.IEventListener;
-import com.arialyy.aria.core.scheduler.ISchedulers;
-import com.arialyy.aria.util.CommonUtil;
-import java.lang.ref.WeakReference;
-
-/**
- * 下载监听类
- */
-class BaseDListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
-    implements IDownloadListener {
-  private WeakReference<Handler> outHandler;
-  private long mLastLen = 0;   //上一次发送长度
-  private boolean isFirst = true;
-  protected ENTITY mEntity;
-  protected TASK mTask;
-  private boolean isConvertSpeed = false;
-  boolean isWait = false;
-
-  BaseDListener(TASK task, Handler outHandler) {
-    this.outHandler = new WeakReference<>(outHandler);
-    this.mTask = new WeakReference<>(task).get();
-    this.mEntity = this.mTask.getEntity();
-    final AriaManager manager = AriaManager.getInstance(AriaManager.APP);
-    isConvertSpeed = manager.getDownloadConfig().isConvertSpeed();
-    mLastLen = mEntity.getCurrentProgress();
-  }
-
-  @Override public void onPre() {
-    saveData(IEntity.STATE_PRE, -1);
-    sendInState2Target(ISchedulers.PRE);
-  }
-
-  @Override public void onPostPre(long fileSize) {
-    mEntity.setFileSize(fileSize);
-    mEntity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
-    saveData(IEntity.STATE_POST_PRE, -1);
-    sendInState2Target(ISchedulers.POST_PRE);
-  }
-
-  @Override public void supportBreakpoint(boolean support) {
-
-  }
-
-  @Override public void onStart(long startLocation) {
-    saveData(IEntity.STATE_RUNNING, startLocation);
-    sendInState2Target(ISchedulers.START);
-  }
-
-  @Override public void onResume(long resumeLocation) {
-    saveData(IEntity.STATE_RUNNING, resumeLocation);
-    sendInState2Target(ISchedulers.RESUME);
-  }
-
-  @Override public void onProgress(long currentLocation) {
-    mEntity.setCurrentProgress(currentLocation);
-    long speed = currentLocation - mLastLen;
-    if (isFirst) {
-      speed = 0;
-      isFirst = false;
-    }
-    handleSpeed(speed);
-    sendInState2Target(ISchedulers.RUNNING);
-    mLastLen = currentLocation;
-  }
-
-  @Override public void onStop(long stopLocation) {
-    saveData(isWait ? IEntity.STATE_WAIT : IEntity.STATE_STOP, stopLocation);
-    handleSpeed(0);
-    sendInState2Target(ISchedulers.STOP);
-  }
-
-  @Override public void onCancel() {
-    saveData(IEntity.STATE_CANCEL, -1);
-    handleSpeed(0);
-    sendInState2Target(ISchedulers.CANCEL);
-  }
-
-  @Override public void onComplete() {
-    saveData(IEntity.STATE_COMPLETE, mEntity.getFileSize());
-    handleSpeed(0);
-    sendInState2Target(ISchedulers.COMPLETE);
-  }
-
-  @Override public void onFail() {
-    mEntity.setFailNum(mEntity.getFailNum() + 1);
-    saveData(IEntity.STATE_FAIL, mEntity.getCurrentProgress());
-    handleSpeed(0);
-    sendInState2Target(ISchedulers.FAIL);
-  }
-
-  private void handleSpeed(long speed) {
-    if (isConvertSpeed) {
-      mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s");
-    } else {
-      mEntity.setSpeed(speed < 0 ? 0 : speed);
-    }
-  }
-
-  /**
-   * 将任务状态发送给下载器
-   *
-   * @param state {@link ISchedulers#START}
-   */
-  private void sendInState2Target(int state) {
-    if (outHandler.get() != null) {
-      outHandler.get().obtainMessage(state, mTask).sendToTarget();
-    }
-  }
-
-  private void saveData(int state, long location) {
-    mEntity.setComplete(state == IEntity.STATE_COMPLETE);
-    if (state == IEntity.STATE_CANCEL) {
-      mEntity.setState(state);
-      mEntity.deleteData();
-    } else if (state == IEntity.STATE_COMPLETE) {
-      mEntity.setState(state);
-      mEntity.setCompleteTime(System.currentTimeMillis());
-      mEntity.setCurrentProgress(mEntity.getFileSize());
-      mEntity.update();
-    } else {
-      mEntity.setState(state);
-      if (location != -1) {
-        mEntity.setCurrentProgress(location);
-      }
-      mEntity.update();
-    }
-  }
-}

+ 0 - 202
Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java

@@ -1,202 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.text.TextUtils;
-import com.arialyy.aria.core.inf.AbsDownloadTarget;
-import com.arialyy.aria.core.inf.AbsTarget;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by Aria.Lao on 2017/7/26.
- */
-abstract class BaseGroupTarget<TARGET extends AbsTarget, TASK_ENTITY extends AbsTaskEntity>
-    extends AbsDownloadTarget<TARGET, DownloadGroupEntity, TASK_ENTITY> {
-
-  List<String> mUrls = new ArrayList<>();
-  String mGroupName;
-  /**
-   * 子任务文件名
-   */
-  private List<String> mSubTaskFileName = new ArrayList<>();
-  /**
-   * 是否已经设置了文件路径
-   */
-  private boolean isSetDirPathed = false;
-
-  /**
-   * 查询任务组实体,如果数据库不存在该实体,则新创建一个新的任务组实体
-   */
-  DownloadGroupEntity getDownloadGroupEntity() {
-    DownloadGroupEntity entity =
-        DbEntity.findFirst(DownloadGroupEntity.class, "groupName=?", mGroupName);
-    if (entity == null) {
-      entity = new DownloadGroupEntity();
-      entity.setGroupName(mGroupName);
-      entity.setUrls(mUrls);
-      entity.insert();
-    }
-    return entity;
-  }
-
-  /**
-   * 设置任务组别名
-   */
-  public TARGET setGroupAlias(String alias) {
-    if (TextUtils.isEmpty(alias)) return (TARGET) this;
-    mEntity.setAlias(alias);
-    mEntity.update();
-    return (TARGET) this;
-  }
-
-  /**
-   * 设置任务组的文件夹路径,在Aria中,任务组的所有子任务都会下载到以任务组组名的文件夹中。
-   * 如:groupDirPath = "/mnt/sdcard/download/group_test"
-   * <pre>
-   *   {@code
-   *      + mnt
-   *        + sdcard
-   *          + download
-   *            + group_test
-   *              - task1.apk
-   *              - task2.apk
-   *              - task3.apk
-   *              ....
-   *
-   *   }
-   * </pre>
-   *
-   * @param groupDirPath 任务组保存文件夹路径
-   */
-  public TARGET setDownloadDirPath(String groupDirPath) {
-    if (TextUtils.isEmpty(groupDirPath)) {
-      throw new NullPointerException("任务组文件夹保存路径不能为null");
-    }
-
-    isSetDirPathed = true;
-    if (mEntity.getDirPath().equals(groupDirPath)) return (TARGET) this;
-
-    File file = new File(groupDirPath);
-    if (file.exists() && file.isFile()) {
-      throw new IllegalArgumentException("路径不能为文件");
-    }
-    if (!file.exists()) {
-      file.mkdirs();
-    }
-
-    mEntity.setDirPath(groupDirPath);
-    if (!TextUtils.isEmpty(mEntity.getDirPath())) {
-      reChangeDirPath(groupDirPath);
-    } else {
-      mEntity.setSubTasks(createSubTask());
-    }
-    mEntity.update();
-    return (TARGET) this;
-  }
-
-  /**
-   * 改变任务组文件夹路径,修改文件夹路径会将子任务所有路径更换
-   *
-   * @param newDirPath 新的文件夹路径
-   */
-  private void reChangeDirPath(String newDirPath) {
-    List<DownloadEntity> subTask = mEntity.getSubTask();
-    if (subTask != null && !subTask.isEmpty()) {
-      for (DownloadEntity entity : subTask) {
-        String oldPath = entity.getDownloadPath();
-        String newPath = newDirPath + "/" + entity.getFileName();
-        File file = new File(oldPath);
-        file.renameTo(new File(newPath));
-        DbEntity.exeSql("UPDATE DownloadEntity SET downloadPath='"
-            + newPath
-            + "' WHERE downloadPath='"
-            + oldPath
-            + "'");
-        DbEntity.exeSql(
-            "UPDATE DownloadTaskEntity SET key='" + newPath + "' WHERE key='" + oldPath + "'");
-      }
-    } else {
-      mEntity.setSubTasks(createSubTask());
-    }
-  }
-
-  /**
-   * 设置子任务文件名,该方法必须在{@link #setDownloadDirPath(String)}之后调用,否则不生效
-   */
-  public TARGET setSubTaskFileName(List<String> subTaskFileName) {
-    if (subTaskFileName == null || subTaskFileName.isEmpty()) return (TARGET) this;
-    mSubTaskFileName.addAll(subTaskFileName);
-    if (mUrls.size() != subTaskFileName.size()) {
-      throw new IllegalArgumentException("下载链接数必须要和保存路径的数量一致");
-    }
-    if (isSetDirPathed) {
-      List<DownloadEntity> entities = mEntity.getSubTask();
-      int i = 0;
-      for (DownloadEntity entity : entities) {
-        String newName = mSubTaskFileName.get(i);
-        updateSubFileName(entity, newName);
-        i++;
-      }
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 更新子任务文件名
-   */
-  private void updateSubFileName(DownloadEntity entity, String newName) {
-    if (!newName.equals(entity.getFileName())) {
-      String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
-      String newPath = mEntity.getDirPath() + "/" + newName;
-      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);
-      entity.setFileName(newName);
-      entity.update();
-    }
-  }
-
-  /**
-   * 创建子任务
-   */
-  private List<DownloadEntity> createSubTask() {
-    List<DownloadEntity> list = new ArrayList<>();
-    for (int i = 0, len = mUrls.size(); i < len; i++) {
-      DownloadEntity entity = new DownloadEntity();
-      entity.setUrl(mUrls.get(i));
-      String fileName = mSubTaskFileName.isEmpty() ? createFileName(entity.getUrl())
-          : mSubTaskFileName.get(i);
-      entity.setDownloadPath(mEntity.getDirPath() + "/" + fileName);
-      entity.setGroupName(mGroupName);
-      entity.setGroupChild(true);
-      entity.setFileName(fileName);
-      entity.insert();
-      list.add(entity);
-    }
-    return list;
-  }
-
-}

+ 0 - 165
Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java

@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.download;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.text.TextUtils;
-import com.arialyy.aria.core.inf.AbsNormalEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.orm.Primary;
-import com.arialyy.aria.util.CommonUtil;
-
-/**
- * Created by lyy on 2015/12/25.
- * 下载实体
- */
-public class DownloadEntity extends AbsNormalEntity implements Parcelable {
-  @Primary private String downloadPath = ""; //保存路径
-
-  /**
-   * 所属任务组
-   */
-  private String groupName = "";
-
-  /**
-   * 通过{@link AbsTaskEntity#md5Key}从服务器的返回信息中获取的文件md5信息,如果服务器没有返回,则不会设置该信息
-   * 如果你已经设置了该任务的MD5信息,Aria也不会从服务器返回的信息中获取该信息
-   */
-  private String md5Code = "";
-
-  /**
-   * 通过{@link AbsTaskEntity#dispositionKey}从服务器的返回信息中获取的文件描述信息
-   */
-  private String disposition = "";
-
-  /**
-   * 从disposition获取到的文件名,如果可以获取到,则会赋值到这个字段
-   */
-  private String serverFileName = "";
-
-  @Override public String getKey() {
-    return getUrl();
-  }
-
-  public DownloadEntity() {
-  }
-
-  public String getMd5Code() {
-    return md5Code;
-  }
-
-  public void setMd5Code(String md5Code) {
-    this.md5Code = md5Code;
-  }
-
-  public String getDisposition() {
-    return TextUtils.isEmpty(disposition) ? "" : CommonUtil.decryptBASE64(disposition);
-  }
-
-  public void setDisposition(String disposition) {
-    this.disposition = disposition;
-  }
-
-  public String getServerFileName() {
-    return serverFileName;
-  }
-
-  public void setServerFileName(String serverFileName) {
-    this.serverFileName = serverFileName;
-  }
-
-  public String getGroupName() {
-    return groupName;
-  }
-
-  public void setGroupName(String groupName) {
-    this.groupName = groupName;
-  }
-
-  /**
-   * {@link #getUrl()}
-   */
-  @Deprecated public String getDownloadUrl() {
-    return getUrl();
-  }
-
-  public String getDownloadPath() {
-    return downloadPath;
-  }
-
-  public DownloadEntity setDownloadPath(String downloadPath) {
-    this.downloadPath = downloadPath;
-    return this;
-  }
-
-  @Override public DownloadEntity clone() throws CloneNotSupportedException {
-    return (DownloadEntity) super.clone();
-  }
-
-  @Override public int describeContents() {
-    return 0;
-  }
-
-  @Override public void writeToParcel(Parcel dest, int flags) {
-    super.writeToParcel(dest, flags);
-    dest.writeString(this.downloadPath);
-    dest.writeString(this.groupName);
-    dest.writeString(this.md5Code);
-    dest.writeString(this.disposition);
-    dest.writeString(this.serverFileName);
-  }
-
-  @Override public String toString() {
-    return "DownloadEntity{"
-        + "downloadPath='"
-        + downloadPath
-        + '\''
-        + ", groupName='"
-        + groupName
-        + '\''
-        + ", md5Code='"
-        + md5Code
-        + '\''
-        + ", disposition='"
-        + disposition
-        + '\''
-        + ", serverFileName='"
-        + serverFileName
-        + '\''
-        + '}';
-  }
-
-  protected DownloadEntity(Parcel in) {
-    super(in);
-    this.downloadPath = in.readString();
-    this.groupName = in.readString();
-    this.md5Code = in.readString();
-    this.disposition = in.readString();
-    this.serverFileName = in.readString();
-  }
-
-  public static final Creator<DownloadEntity> CREATOR = new Creator<DownloadEntity>() {
-    @Override public DownloadEntity createFromParcel(Parcel source) {
-      return new DownloadEntity(source);
-    }
-
-    @Override public DownloadEntity[] newArray(int size) {
-      return new DownloadEntity[size];
-    }
-  };
-}

+ 0 - 102
Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java

@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.os.Parcel;
-import com.arialyy.aria.core.inf.AbsGroupEntity;
-import com.arialyy.aria.orm.NormalList;
-import com.arialyy.aria.orm.OneToMany;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 下载任务组实体
- */
-public class DownloadGroupEntity extends AbsGroupEntity {
-
-  @OneToMany(table = DownloadEntity.class, key = "groupName") private List<DownloadEntity> subtask =
-      new ArrayList<>();
-
-  /**
-   * 子任务链接组
-   */
-  @NormalList(clazz = String.class) private List<String> urls = new ArrayList<>();
-
-  /**
-   * 任务组下载文件的文件夹地址
-   *
-   * @see DownloadGroupTarget#setDownloadDirPath(String)
-   */
-  private String dirPath = "";
-
-  public List<DownloadEntity> getSubTask() {
-    return subtask;
-  }
-
-  public void setSubTasks(List<DownloadEntity> subTasks) {
-    this.subtask = subTasks;
-  }
-
-  public String getDirPath() {
-    return dirPath;
-  }
-
-  public void setDirPath(String dirPath) {
-    this.dirPath = dirPath;
-  }
-
-  public List<String> getUrls() {
-    return urls;
-  }
-
-  public void setUrls(List<String> urls) {
-    this.urls = urls;
-  }
-
-  void setGroupName(String key) {
-    this.groupName = key;
-  }
-
-  public DownloadGroupEntity() {
-  }
-
-  @Override public int describeContents() {
-    return 0;
-  }
-
-  @Override public void writeToParcel(Parcel dest, int flags) {
-    super.writeToParcel(dest, flags);
-    dest.writeTypedList(this.subtask);
-    dest.writeString(this.dirPath);
-  }
-
-  protected DownloadGroupEntity(Parcel in) {
-    super(in);
-    this.subtask = in.createTypedArrayList(DownloadEntity.CREATOR);
-    this.dirPath = in.readString();
-  }
-
-  public static final Creator<DownloadGroupEntity> CREATOR = new Creator<DownloadGroupEntity>() {
-    @Override public DownloadGroupEntity createFromParcel(Parcel source) {
-      return new DownloadGroupEntity(source);
-    }
-
-    @Override public DownloadGroupEntity[] newArray(int size) {
-      return new DownloadGroupEntity[size];
-    }
-  };
-}

+ 0 - 65
Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java

@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.os.Handler;
-import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
-
-/**
- * Created by Aria.Lao on 2017/7/20.
- * 任务组下载事件
- */
-class DownloadGroupListener extends BaseDListener<DownloadGroupEntity, DownloadGroupTask>
-    implements IDownloadGroupListener {
-  private final String TAG = "DownloadGroupListener";
-
-  DownloadGroupListener(DownloadGroupTask task, Handler outHandler) {
-    super(task, outHandler);
-  }
-
-  @Override public void supportBreakpoint(boolean support, DownloadEntity subEntity) {
-
-  }
-
-  @Override public void onSubStart(DownloadEntity subEntity) {
-
-  }
-
-  @Override public void onSubStop(DownloadEntity subEntity) {
-    saveCurrentLocation();
-  }
-
-  @Override public void onSubComplete(DownloadEntity subEntity) {
-    saveCurrentLocation();
-  }
-
-  @Override public void onSubFail(DownloadEntity subEntity) {
-    saveCurrentLocation();
-  }
-
-  @Override public void onSubCancel(DownloadEntity entity) {
-    saveCurrentLocation();
-  }
-
-  private void saveCurrentLocation() {
-    long location = 0;
-    for (DownloadEntity e : mEntity.getSubTask()) {
-      location += e.getCurrentProgress();
-    }
-    mEntity.setCurrentProgress(location);
-    mEntity.update();
-  }
-}

+ 0 - 71
Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java

@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.CheckUtil;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.List;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 下载任务组
- */
-public class DownloadGroupTarget
-    extends BaseGroupTarget<DownloadGroupTarget, DownloadGroupTaskEntity> {
-  private final String TAG = "DownloadGroupTarget";
-
-  DownloadGroupTarget(DownloadGroupEntity groupEntity, String targetName) {
-    this.mTargetName = targetName;
-    if (groupEntity.getUrls() != null && !groupEntity.getUrls().isEmpty()) {
-      this.mUrls.addAll(groupEntity.getUrls());
-    }
-    init(groupEntity.getGroupName());
-  }
-
-  DownloadGroupTarget(List<String> urls, String targetName) {
-    this.mTargetName = targetName;
-    this.mUrls = urls;
-    init(CommonUtil.getMd5Code(urls));
-  }
-
-  private void init(String key) {
-    mGroupName = key;
-    mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
-    if (mTaskEntity == null) {
-      mTaskEntity = new DownloadGroupTaskEntity();
-      mTaskEntity.key = key;
-      mTaskEntity.entity = getDownloadGroupEntity();
-      mTaskEntity.insert();
-    }
-    if (mTaskEntity.entity == null) {
-      mTaskEntity.entity = getDownloadGroupEntity();
-    }
-    mEntity = mTaskEntity.entity;
-  }
-
-  /**
-   * 如果你是使用{@link DownloadReceiver#load(DownloadGroupEntity)}进行下载操作,那么你需要设置任务组的下载地址
-   */
-  public DownloadGroupTarget setGroupUrl(List<String> urls) {
-    CheckUtil.checkDownloadUrls(urls);
-    mUrls.clear();
-    mUrls.addAll(urls);
-    mEntity.setGroupName(CommonUtil.getMd5Code(urls));
-    mEntity.update();
-    return this;
-  }
-}

+ 0 - 107
Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java

@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.os.Handler;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.downloader.DownloadGroupUtil;
-import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil;
-import com.arialyy.aria.core.common.IUtil;
-import com.arialyy.aria.core.inf.AbsGroupTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.scheduler.ISchedulers;
-import com.arialyy.aria.util.CheckUtil;
-
-/**
- * Created by AriaL on 2017/6/27.
- * 任务组任务
- */
-public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, DownloadGroupEntity> {
-  private final String TAG = "DownloadGroupTask";
-  private DownloadGroupListener mListener;
-  private IUtil mUtil;
-
-  private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) {
-    mTaskEntity = taskEntity;
-    mEntity = taskEntity.getEntity();
-    mOutHandler = outHandler;
-    mContext = AriaManager.APP;
-    mListener = new DownloadGroupListener(this, mOutHandler);
-    switch (taskEntity.requestType) {
-      case AbsTaskEntity.HTTP:
-        mUtil = new DownloadGroupUtil(mListener, mTaskEntity);
-        break;
-      case  AbsTaskEntity.FTP_DIR:
-        mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity);
-        break;
-    }
-  }
-
-  @Override public boolean isRunning() {
-    return mUtil.isRunning();
-  }
-
-  @Override public void start() {
-    mUtil.start();
-  }
-
-  @Override public void stop() {
-    if (!mUtil.isRunning()) {
-      if (mOutHandler != null) {
-        mOutHandler.obtainMessage(ISchedulers.STOP, this).sendToTarget();
-      }
-    }
-    mUtil.stop();
-  }
-
-  @Override public void cancel() {
-    if (!mUtil.isRunning()) {
-      if (mOutHandler != null) {
-        mOutHandler.obtainMessage(ISchedulers.CANCEL, this).sendToTarget();
-      }
-    }
-    mUtil.cancel();
-  }
-
-  public static class Builder {
-    DownloadGroupTaskEntity taskEntity;
-    Handler outHandler;
-    String targetName;
-
-    public Builder(String targetName, DownloadGroupTaskEntity taskEntity) {
-      CheckUtil.checkTaskEntity(taskEntity);
-      this.targetName = targetName;
-      this.taskEntity = taskEntity;
-    }
-
-    /**
-     * 设置自定义Handler处理下载状态时间
-     *
-     * @param schedulers {@link ISchedulers}
-     */
-    public DownloadGroupTask.Builder setOutHandler(ISchedulers schedulers) {
-      this.outHandler = new Handler(schedulers);
-      return this;
-    }
-
-    public DownloadGroupTask build() {
-      DownloadGroupTask task = new DownloadGroupTask(taskEntity, outHandler);
-      task.setTargetName(targetName);
-      taskEntity.save();
-      return task;
-    }
-  }
-}

+ 0 - 31
Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java

@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.orm.OneToOne;
-
-/**
- * Created by AriaL on 2017/7/1.
- */
-public class DownloadGroupTaskEntity extends AbsTaskEntity<DownloadGroupEntity> {
-
-  @OneToOne(table = DownloadGroupEntity.class, key = "groupName") public DownloadGroupEntity entity;
-
-  @Override public DownloadGroupEntity getEntity() {
-    return entity;
-  }
-}

+ 0 - 35
Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java

@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.os.Handler;
-import com.arialyy.aria.core.inf.IDownloadListener;
-
-/**
- * Created by Aria.Lao on 2017/7/20.
- * 普通任务下载的事件监听器
- */
-class DownloadListener extends BaseDListener<DownloadEntity, DownloadTask>
-    implements IDownloadListener {
-  DownloadListener(DownloadTask task, Handler outHandler) {
-    super(task, outHandler);
-  }
-
-  @Override public void supportBreakpoint(boolean support) {
-
-  }
-
-}

+ 0 - 273
Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java

@@ -1,273 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.support.annotation.NonNull;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsReceiver;
-import com.arialyy.aria.core.inf.IReceiver;
-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.common.ProxyHelper;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.CheckUtil;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created by lyy on 2016/12/5.
- * 下载功能接收器
- */
-public class DownloadReceiver extends AbsReceiver {
-  private final String TAG = "DownloadReceiver";
-  public ISchedulerListener<DownloadTask> listener;
-
-  /**
-   * 设置最大下载速度,单位:kb
-   * 该方法为实验性功能,清不要轻易在生产环境中使用。
-   *
-   * @param maxSpeed 为0表示不限速
-   */
-  @Deprecated public void setMaxSpeed(double maxSpeed) {
-    AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMsxSpeed(maxSpeed);
-  }
-
-  /**
-   * 使用下载实体执行下载操作
-   */
-  public DownloadTarget load(DownloadEntity entity) {
-    return new DownloadTarget(entity, targetName);
-  }
-
-  /**
-   * 加载Http、https单任务下载地址
-   */
-  public DownloadTarget load(@NonNull String url) {
-    CheckUtil.checkDownloadUrl(url);
-    return new DownloadTarget(url, targetName);
-  }
-
-  /**
-   * 加载下载地址,如果任务组的中的下载地址改变了,则任务从新的一个任务组
-   */
-  public DownloadGroupTarget load(List<String> urls) {
-    CheckUtil.checkDownloadUrls(urls);
-    return new DownloadGroupTarget(urls, targetName);
-  }
-
-  /**
-   * 加载ftp单任务下载地址
-   */
-  public FtpDownloadTarget loadFtp(@NonNull String url) {
-    CheckUtil.checkDownloadUrl(url);
-    return new FtpDownloadTarget(url, targetName);
-  }
-
-  /**
-   * 使用任务组实体执行任务组的实体执行任务组的下载操作
-   *
-   * @param groupEntity 如果加载的任务实体没有子项的下载地址,
-   * 那么你需要使用{@link DownloadGroupTarget#setGroupUrl(List)}设置子项的下载地址
-   */
-  public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
-    return new DownloadGroupTarget(groupEntity, targetName);
-  }
-
-  /**
-   * 加载ftp文件夹下载地址
-   */
-  public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) {
-    CheckUtil.checkDownloadUrl(dirUrl);
-    return new FtpDirDownloadTarget(dirUrl, targetName);
-  }
-
-  /**
-   * 将当前类注册到Aria
-   */
-  public DownloadReceiver register() {
-    String className = obj.getClass().getName();
-    Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
-    Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
-    if (dCounter != null && dCounter.contains(className)) {
-      DownloadSchedulers.getInstance().register(obj);
-    }
-    if (dgCounter != null && dgCounter.contains(className)) {
-      DownloadGroupSchedulers.getInstance().register(obj);
-    }
-    return this;
-  }
-
-  /**
-   * 取消注册
-   */
-  @Override public void unRegister() {
-    String className = obj.getClass().getName();
-    Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
-    Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
-    if (dCounter != null && dCounter.contains(className)) {
-      DownloadSchedulers.getInstance().unRegister(obj);
-    }
-    if (dgCounter != null && dgCounter.contains(className)) {
-      DownloadGroupSchedulers.getInstance().unRegister(obj);
-    }
-  }
-
-  /**
-   * 添加调度器回调
-   *
-   * @see #register()
-   */
-  @Deprecated public DownloadReceiver addSchedulerListener(
-      ISchedulerListener<DownloadTask> listener) {
-    this.listener = listener;
-    DownloadSchedulers.getInstance().addSchedulerListener(targetName, listener);
-    return this;
-  }
-
-  /**
-   * 移除回调
-   *
-   * @see #unRegister()
-   */
-  @Deprecated @Override public void removeSchedulerListener() {
-    if (listener != null) {
-      DownloadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
-    }
-  }
-
-  @Override public void destroy() {
-    targetName = null;
-    listener = null;
-  }
-
-  /**
-   * 通过下载链接获取下载实体
-   */
-  public DownloadEntity getDownloadEntity(String downloadUrl) {
-    CheckUtil.checkDownloadUrl(downloadUrl);
-    return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'",
-        downloadUrl);
-  }
-
-  /**
-   * 通过下载链接获取保存在数据库的下载任务实体
-   */
-  public DownloadTaskEntity getDownloadTask(String downloadUrl) {
-    CheckUtil.checkDownloadUrl(downloadUrl);
-    return DbEntity.findFirst(DownloadTaskEntity.class, "groupName=? and isGroupTask='false'",
-        downloadUrl);
-  }
-
-  /**
-   * 通过下载链接获取保存在数据库的下载任务组实体
-   */
-  public DownloadGroupTaskEntity getDownloadGroupTask(List<String> urls) {
-    CheckUtil.checkDownloadUrls(urls);
-    String hashCode = CommonUtil.getMd5Code(urls);
-    return DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", hashCode);
-  }
-
-  /**
-   * 通过任务组key,获取任务组实体
-   * 如果是http,key为所有子任务下载地址拼接后取md5
-   * 如果是ftp,key为ftp服务器的文件夹路径
-   */
-  public DownloadGroupTaskEntity getDownloadGroupTask(String key) {
-    return DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
-  }
-
-  /**
-   * 下载任务是否存在
-   */
-  @Override public boolean taskExists(String downloadUrl) {
-    return DownloadEntity.findFirst(DownloadEntity.class, "url=?", downloadUrl) != null;
-  }
-
-  /**
-   * 获取普通下载任务列表
-   */
-  @Override public List<DownloadEntity> getSimpleTaskList() {
-    return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=? and downloadPath!=''",
-        "false");
-  }
-
-  /**
-   * 获取任务组列表
-   */
-  public List<DownloadGroupEntity> getGroupTaskList() {
-    return DownloadEntity.findAllData(DownloadGroupEntity.class);
-  }
-
-  /**
-   * 获取普通任务和任务组的任务列表
-   */
-  public List<AbsEntity> getTotleTaskList() {
-    List<AbsEntity> list = new ArrayList<>();
-    List<DownloadEntity> simpleTask = getSimpleTaskList();
-    List<DownloadGroupEntity> groupTask = getGroupTaskList();
-    if (simpleTask != null && !simpleTask.isEmpty()) {
-      list.addAll(simpleTask);
-    }
-    if (groupTask != null && !groupTask.isEmpty()) {
-      list.addAll(groupTask);
-    }
-    return list;
-  }
-
-  /**
-   * 停止所有正在下载的任务,并清空等待队列。
-   */
-  @Override public void stopAllTask() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(NormalCmdFactory.getInstance()
-            .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL))
-        .exe();
-  }
-
-  /**
-   * 恢复所有正在下载的任务
-   * 1.如果执行队列没有满,则开始下载任务,直到执行队列满
-   * 2.如果队列执行队列已经满了,则将所有任务添加到等待队列中
-   */
-  public void resumeAllTask() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(NormalCmdFactory.getInstance()
-            .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL))
-        .exe();
-  }
-
-  /**
-   * 删除所有任务
-   *
-   * @param removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false}
-   * 如果文件已经下载完成,只删除下载记录
-   */
-  @Override public void removeAllTask(boolean removeFile) {
-    final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
-    ariaManager.setCmd(CommonUtil.createCmd(targetName, new DownloadTaskEntity(),
-        NormalCmdFactory.TASK_CANCEL_ALL)).exe();
-
-    Set<String> keys = ariaManager.getReceiver().keySet();
-    for (String key : keys) {
-      ariaManager.getReceiver().remove(key);
-    }
-  }
-}

+ 0 - 153
Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java

@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.support.annotation.NonNull;
-import android.text.TextUtils;
-import com.arialyy.aria.core.inf.AbsDownloadTarget;
-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;
-
-/**
- * Created by lyy on 2016/12/5.
- * https://github.com/AriaLyy/Aria
- */
-public class DownloadTarget
-    extends AbsDownloadTarget<DownloadTarget, DownloadEntity, DownloadTaskEntity> {
-  protected String url;
-
-  DownloadTarget(DownloadEntity entity, String targetName) {
-    this.url = entity.getUrl();
-    mTargetName = targetName;
-    initTask(entity);
-  }
-
-  DownloadTarget(String url, String targetName) {
-    this.url = url;
-    mTargetName = targetName;
-    DownloadEntity entity = getEntity(url);
-    initTask(entity);
-  }
-
-  private void initTask(DownloadEntity entity) {
-    mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'",
-        entity.getDownloadPath());
-    if (mTaskEntity == null) {
-      mTaskEntity = new DownloadTaskEntity();
-      mTaskEntity.key = entity.getDownloadPath();
-      mTaskEntity.entity = entity;
-      mTaskEntity.save();
-    }
-    if (mTaskEntity.entity == null) {
-      mTaskEntity.entity = entity;
-    }
-    mEntity = mTaskEntity.entity;
-  }
-
-  /**
-   * 如果任务存在,但是下载实体不存在,则通过下载地址获取下载实体
-   *
-   * @param downloadUrl 下载地址
-   */
-  private DownloadEntity getEntity(String downloadUrl) {
-    DownloadEntity entity =
-        DownloadEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'",
-            downloadUrl);
-    if (entity == null) {
-      entity = new DownloadEntity();
-      entity.setUrl(downloadUrl);
-      entity.setGroupChild(false);
-      entity.save();
-    }
-    File file = new File(entity.getDownloadPath());
-    if (!file.exists()) {
-      entity.setState(IEntity.STATE_WAIT);
-    }
-    return entity;
-  }
-
-  /**
-   * 将任务设置为最高优先级任务,最高优先级任务有以下特点:
-   * 1、在下载队列中,有且只有一个最高优先级任务
-   * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
-   * 3、任务调度器不会暂停最高优先级任务
-   * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
-   * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行
-   * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
-   */
-  @Override public void setHighestPriority() {
-    super.setHighestPriority();
-  }
-
-  /**
-   * 下载任务是否存在
-   */
-  @Override public boolean taskExists() {
-    return DownloadTaskQueue.getInstance().getTask(mEntity.getUrl()) != null;
-  }
-
-  /**
-   * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。
-   * 如:原文件路径 /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);
-    if (file.isDirectory()) {
-      throw new IllegalArgumentException("文件不能为文件夹");
-    }
-    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());
-      }
-    }
-    return this;
-  }
-
-  public DownloadEntity getDownloadEntity() {
-    return mEntity;
-  }
-
-  /**
-   * 从header中获取文件描述信息
-   */
-  public String getContentDisposition() {
-    return mEntity.getDisposition();
-  }
-
-  /**
-   * 是否在下载
-   */
-  public boolean isDownloading() {
-    DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity);
-    return task != null && task.isRunning();
-  }
-}

+ 0 - 178
Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java

@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.download;
-
-import android.os.Handler;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.IUtil;
-import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil;
-import com.arialyy.aria.core.inf.AbsNormalTask;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.scheduler.ISchedulers;
-import java.io.File;
-
-/**
- * Created by lyy on 2016/8/11.
- * 下载任务类
- */
-public class DownloadTask extends AbsNormalTask<DownloadEntity> {
-  public static final String TAG = "DownloadTask";
-
-  private DownloadListener mListener;
-  private IUtil mUtil;
-
-  private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) {
-    mEntity = taskEntity.getEntity();
-    mOutHandler = outHandler;
-    mContext = AriaManager.APP;
-    mListener = new DownloadListener(this, mOutHandler);
-    mUtil = new SimpleDownloadUtil(taskEntity, mListener);
-  }
-
-  /**
-   * 获取文件保存路径
-   *
-   * @return 如果路径不存在,返回null
-   */
-  public String getDownloadPath() {
-    File file = new File(mEntity.getDownloadPath());
-    if (!file.exists()) {
-      return null;
-    }
-    return mEntity.getDownloadPath();
-  }
-
-  /**
-   * 获取当前下载任务的下载地址
-   *
-   * @see DownloadTask#getKey()
-   */
-  @Deprecated public String getDownloadUrl() {
-    return mEntity.getUrl();
-  }
-
-  @Override public String getKey() {
-    return mEntity.getUrl();
-  }
-
-  /**
-   * 任务下载状态
-   *
-   * @see DownloadTask#isRunning()
-   */
-  @Deprecated public boolean isDownloading() {
-    return mUtil.isRunning();
-  }
-
-  @Override public boolean isRunning() {
-    return isDownloading();
-  }
-
-  public DownloadEntity getDownloadEntity() {
-    return mEntity;
-  }
-
-  /**
-   * 暂停任务,并让任务处于等待状态
-   */
-  @Override public void stopAndWait() {
-    stop(true);
-  }
-
-  /**
-   * 设置最大下载速度,单位:kb
-   *
-   * @param maxSpeed 为0表示不限速
-   */
-  public void setMaxSpeed(double maxSpeed) {
-    mUtil.setMaxSpeed(maxSpeed);
-  }
-
-  /**
-   * 开始下载
-   */
-  @Override public void start() {
-    mListener.isWait = false;
-    if (mUtil.isRunning()) {
-      Log.d(TAG, "任务正在下载");
-    } else {
-      mUtil.start();
-    }
-  }
-
-  /**
-   * 停止下载
-   */
-  @Override public void stop() {
-    stop(false);
-  }
-
-  private void stop(boolean isWait) {
-    mListener.isWait = isWait;
-    if (mUtil.isRunning()) {
-      mUtil.stop();
-    } else {
-      mEntity.setState(isWait ? IEntity.STATE_WAIT : IEntity.STATE_STOP);
-      mEntity.update();
-      if (mOutHandler != null) {
-        mOutHandler.obtainMessage(ISchedulers.STOP, this).sendToTarget();
-      }
-    }
-  }
-
-  /**
-   * 取消下载
-   */
-  @Override public void cancel() {
-    if (!mUtil.isRunning()) {
-      if (mOutHandler != null) {
-        mOutHandler.obtainMessage(ISchedulers.CANCEL, this).sendToTarget();
-      }
-    }
-    mUtil.cancel();
-  }
-
-  public static class Builder {
-    DownloadTaskEntity taskEntity;
-    Handler outHandler;
-    String targetName;
-
-    public Builder(String targetName, DownloadTaskEntity taskEntity) {
-      this.targetName = targetName;
-      this.taskEntity = taskEntity;
-    }
-
-    /**
-     * 设置自定义Handler处理下载状态时间
-     *
-     * @param schedulers {@link ISchedulers}
-     */
-    public Builder setOutHandler(ISchedulers schedulers) {
-      this.outHandler = new Handler(schedulers);
-      return this;
-    }
-
-    public DownloadTask build() {
-      DownloadTask task = new DownloadTask(taskEntity, outHandler);
-      task.setTargetName(targetName);
-      taskEntity.getEntity().save();
-      taskEntity.save();
-      return task;
-    }
-  }
-}

+ 0 - 46
Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java

@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.orm.Ignore;
-import com.arialyy.aria.orm.OneToOne;
-
-/**
- * Created by lyy on 2017/1/23.
- * 下载任务实体
- */
-public class DownloadTaskEntity extends AbsTaskEntity<DownloadEntity> {
-
-  @OneToOne(table = DownloadEntity.class, key = "downloadPath") public DownloadEntity entity;
-
-  /**
-   * 所属的任务组组名,如果不属于任务组,则为null
-   */
-  public String groupName = "";
-
-  /**
-   * 该任务是否属于任务组
-   */
-  public boolean isGroupTask = false;
-
-  public DownloadTaskEntity() {
-  }
-
-  @Override public DownloadEntity getEntity() {
-    return entity;
-  }
-}

+ 0 - 102
Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java

@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.orm.DbEntity;
-
-/**
- * Created by Aria.Lao on 2017/7/26.
- * ftp文件夹下载
- */
-public class FtpDirDownloadTarget
-    extends BaseGroupTarget<FtpDirDownloadTarget, DownloadGroupTaskEntity> {
-  private final String TAG = "FtpDirDownloadTarget";
-  private String serverIp, remotePath;
-  private int port;
-
-  FtpDirDownloadTarget(String url, String targetName) {
-    init(url);
-    String[] pp = url.split("/")[2].split(":");
-    mTargetName = targetName;
-    serverIp = pp[0];
-    port = Integer.parseInt(pp[1]);
-    mTaskEntity.requestType = AbsTaskEntity.FTP_DIR;
-    mTaskEntity.serverIp = serverIp;
-    mTaskEntity.port = port;
-    remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
-    if (TextUtils.isEmpty(remotePath)) {
-      throw new NullPointerException("ftp服务器地址不能为null");
-    }
-  }
-
-  private void init(String key) {
-    mGroupName = key;
-    mTaskEntity = DbEntity.findFirst(DownloadGroupTaskEntity.class, "key=?", key);
-    if (mTaskEntity == null) {
-      mTaskEntity = new DownloadGroupTaskEntity();
-      mTaskEntity.key = key;
-      mTaskEntity.entity = getDownloadGroupEntity();
-      mTaskEntity.insert();
-    }
-    if (mTaskEntity.entity == null) {
-      mTaskEntity.entity = getDownloadGroupEntity();
-    }
-    mEntity = mTaskEntity.entity;
-  }
-
-  /**
-   * 设置字符编码
-   */
-  public FtpDirDownloadTarget charSet(String charSet) {
-    if (TextUtils.isEmpty(charSet)) return this;
-    mTaskEntity.charSet = charSet;
-    return this;
-  }
-
-  /**
-   * ftp 用户登录信息
-   *
-   * @param userName ftp用户名
-   * @param password ftp用户密码
-   */
-  public FtpDirDownloadTarget login(String userName, String password) {
-    return login(userName, password, null);
-  }
-
-  /**
-   * ftp 用户登录信息
-   *
-   * @param userName ftp用户名
-   * @param password ftp用户密码
-   * @param account ftp账号
-   */
-  public FtpDirDownloadTarget login(String userName, String password, String account) {
-    if (TextUtils.isEmpty(userName)) {
-      Log.e(TAG, "用户名不能为null");
-      return this;
-    } else if (TextUtils.isEmpty(password)) {
-      Log.e(TAG, "密码不能为null");
-      return this;
-    }
-    mTaskEntity.userName = userName;
-    mTaskEntity.userPw = password;
-    mTaskEntity.account = account;
-    return this;
-  }
-}

+ 0 - 120
Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java

@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download;
-
-import android.support.annotation.NonNull;
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-
-/**
- * Created by lyy on 2016/12/5.
- * https://github.com/AriaLyy/Aria
- */
-public class FtpDownloadTarget extends DownloadTarget {
-  private final String TAG = "FtpDownloadTarget";
-  private String serverIp, remotePath;
-  private int port;
-
-  FtpDownloadTarget(String url, String targetName) {
-    super(url, targetName);
-    String[] pp = url.split("/")[2].split(":");
-    this.serverIp = pp[0];
-    this.port = Integer.parseInt(pp[1]);
-    mTaskEntity.requestType = AbsTaskEntity.FTP;
-    remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
-    if (TextUtils.isEmpty(remotePath)) {
-      throw new NullPointerException("ftp服务器地址不能为null");
-    }
-    int lastIndex = url.lastIndexOf("/");
-    mTaskEntity.serverIp = serverIp;
-    mTaskEntity.port = port;
-    mEntity.setFileName(url.substring(lastIndex + 1, url.length()));
-  }
-
-  /**
-   * 设置文件保存文件夹路径
-   * 关于文件名:
-   * 1、如果保存路径是该文件的保存路径,如:/mnt/sdcard/file.zip,则使用路径中的文件名file.zip
-   * 2、如果保存路径是文件夹路径,如:/mnt/sdcard/,则使用FTP服务器该文件的文件名
-   *
-   * @param downloadPath 路径必须为文件路径,不能为文件夹路径
-   */
-  @Override public FtpDownloadTarget setDownloadPath(@NonNull String downloadPath) {
-    if (TextUtils.isEmpty(downloadPath)) {
-      throw new IllegalArgumentException("文件保持路径不能为null");
-    }
-    File file = new File(downloadPath);
-    if (file.isDirectory()) {
-      downloadPath += mEntity.getFileName();
-    }
-    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());
-      }
-    }
-    return this;
-  }
-
-  /**
-   * 设置字符编码
-   */
-  public FtpDownloadTarget charSet(String charSet) {
-    if (TextUtils.isEmpty(charSet)) return this;
-    mTaskEntity.charSet = charSet;
-    return this;
-  }
-
-  /**
-   * ftp 用户登录信息
-   *
-   * @param userName ftp用户名
-   * @param password ftp用户密码
-   */
-  public FtpDownloadTarget login(String userName, String password) {
-    return login(userName, password, null);
-  }
-
-  /**
-   * ftp 用户登录信息
-   *
-   * @param userName ftp用户名
-   * @param password ftp用户密码
-   * @param account ftp账号
-   */
-  public FtpDownloadTarget login(String userName, String password, String account) {
-    if (TextUtils.isEmpty(userName)) {
-      Log.e(TAG, "用户名不能为null");
-      return this;
-    } else if (TextUtils.isEmpty(password)) {
-      Log.e(TAG, "密码不能为null");
-      return this;
-    }
-    mTaskEntity.userName = userName;
-    mTaskEntity.userPw = password;
-    mTaskEntity.account = account;
-    return this;
-  }
-}

+ 0 - 155
Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsFtpInfoThread.java

@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.AbsThreadTask;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.IOException;
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPReply;
-
-/**
- * Created by Aria.Lao on 2017/7/25.
- * 获取ftp文件夹信息
- */
-abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>>
-    implements Runnable {
-
-  private final String TAG = "HttpFileInfoThread";
-  protected ENTITY mEntity;
-  protected TASK_ENTITY mTaskEntity;
-  private int mConnectTimeOut;
-  private OnFileInfoCallback mCallback;
-
-  AbsFtpInfoThread(TASK_ENTITY taskEntity, OnFileInfoCallback callback) {
-    mTaskEntity = taskEntity;
-    mEntity = taskEntity.getEntity();
-    mConnectTimeOut =
-        AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
-    mCallback = callback;
-  }
-
-  @Override public void run() {
-    FTPClient client = null;
-    try {
-      String url = mTaskEntity.getEntity().getKey();
-      String[] pp = url.split("/")[2].split(":");
-      String serverIp = pp[0];
-      int port = Integer.parseInt(pp[1]);
-      String remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
-      client = new FTPClient();
-      client.connect(serverIp, port);
-      if (!TextUtils.isEmpty(mTaskEntity.account)) {
-        client.login(mTaskEntity.userName, mTaskEntity.userPw);
-      } else {
-        client.login(mTaskEntity.userName, mTaskEntity.userPw, mTaskEntity.account);
-      }
-      int reply = client.getReplyCode();
-      if (!FTPReply.isPositiveCompletion(reply)) {
-        client.disconnect();
-        failDownload("无法连接到ftp服务器,错误码为:" + reply);
-        return;
-      }
-      client.setDataTimeout(mConnectTimeOut);
-      String charSet = "UTF-8";
-      // 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码
-      if (!TextUtils.isEmpty(mTaskEntity.charSet) || !FTPReply.isPositiveCompletion(
-          client.sendCommand("OPTS UTF8", "ON"))) {
-        charSet = mTaskEntity.charSet;
-      }
-      client.setControlEncoding(charSet);
-      client.enterLocalPassiveMode();
-      client.setFileType(FTP.BINARY_FILE_TYPE);
-      FTPFile[] files =
-          client.listFiles(new String(remotePath.getBytes(charSet), AbsThreadTask.SERVER_CHARSET));
-      long size = getFileSize(files, client, remotePath);
-      mEntity.setFileSize(size);
-      reply = client.getReplyCode();
-      if (!FTPReply.isPositiveCompletion(reply)) {
-        client.disconnect();
-        failDownload("获取文件信息错误,错误码为:" + reply);
-        return;
-      }
-      mTaskEntity.code = reply;
-      onPreComplete();
-      mEntity.update();
-      mTaskEntity.update();
-      mCallback.onComplete(mEntity.getKey(), reply);
-    } catch (IOException e) {
-      failDownload(e.getMessage());
-    } finally {
-      if (client != null) {
-        try {
-          client.disconnect();
-        } catch (IOException e) {
-          e.printStackTrace();
-        }
-      }
-    }
-  }
-
-  void start() {
-    new Thread(this).start();
-  }
-
-  protected void onPreComplete() {
-
-  }
-
-  /**
-   * 遍历FTP服务器上对应文件或文件夹大小
-   *
-   * @throws IOException
-   */
-  private long getFileSize(FTPFile[] files, FTPClient client, String dirName) throws IOException {
-    long size = 0;
-    String path = dirName + "/";
-    for (FTPFile file : files) {
-      if (file.isFile()) {
-        size += file.getSize();
-        handleFile(path + file.getName(), file);
-      } else {
-        size += getFileSize(client.listFiles(
-            CommonUtil.strCharSetConvert(path + file.getName(), mTaskEntity.charSet)), client,
-            path + file.getName());
-      }
-    }
-    return size;
-  }
-
-  /**
-   * 处理FTP文件信息
-   *
-   * @param remotePath ftp服务器文件夹路径
-   * @param ftpFile ftp服务器上对应的文件
-   */
-  void handleFile(String remotePath, FTPFile ftpFile) {
-  }
-
-  private void failDownload(String errorMsg) {
-    Log.e(TAG, errorMsg);
-    if (mCallback != null) {
-      mCallback.onFail(mEntity.getKey(), errorMsg);
-    }
-  }
-}

+ 0 - 399
Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java

@@ -1,399 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.IUtil;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * Created by AriaL on 2017/6/30.
- * 任务组核心逻辑
- */
-abstract class AbsGroupUtil implements IUtil {
-  private final String TAG = "DownloadGroupUtil";
-  /**
-   * 任务组所有任务总大小
-   */
-  long mTotalSize = 0;
-  protected long mCurrentLocation = 0;
-  private ExecutorService mExePool;
-  protected IDownloadGroupListener mListener;
-  protected DownloadGroupTaskEntity mTaskEntity;
-  private boolean isRunning = true;
-  private Timer mTimer;
-  /**
-   * 初始化完成的任务书数
-   */
-  int mInitNum = 0;
-  /**
-   * 初始化失败的任务数
-   */
-  int mInitFailNum = 0;
-  /**
-   * 保存所有没有下载完成的任务,key为下载地址
-   */
-  Map<String, DownloadTaskEntity> mExeMap = new HashMap<>();
-
-  /**
-   * 下载失败的映射表,key为下载地址
-   */
-  Map<String, DownloadTaskEntity> mFailMap = new HashMap<>();
-
-  /**
-   * 下载器映射表,key为下载地址
-   */
-  private Map<String, Downloader> mDownloaderMap = new HashMap<>();
-
-  /**
-   * 该任务组对应的所有任务
-   */
-  private Map<String, DownloadTaskEntity> mTasksMap = new HashMap<>();
-  //已经完成的任务数
-  private int mCompleteNum = 0;
-  //失败的任务数
-  private int mFailNum = 0;
-  //实际的下载任务数
-  int mActualTaskNum = 0;
-
-  AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
-    mListener = listener;
-    mTaskEntity = taskEntity;
-    mExePool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
-    List<DownloadTaskEntity> tasks =
-        DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", mTaskEntity.key);
-    if (tasks != null && !tasks.isEmpty()) {
-      for (DownloadTaskEntity te : tasks) {
-        mTasksMap.put(te.getEntity().getUrl(), te);
-      }
-    }
-    for (DownloadEntity entity : mTaskEntity.entity.getSubTask()) {
-      File file = new File(entity.getDownloadPath());
-      if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) {
-        mCompleteNum++;
-        mInitNum++;
-        mCurrentLocation += entity.getFileSize();
-      } else {
-        mExeMap.put(entity.getUrl(), createChildDownloadTask(entity));
-        mCurrentLocation += entity.getCurrentProgress();
-        mActualTaskNum++;
-      }
-      mTotalSize += entity.getFileSize();
-    }
-  }
-
-  @Override public long getFileSize() {
-    return mTotalSize;
-  }
-
-  @Override public long getCurrentLocation() {
-    return mCurrentLocation;
-  }
-
-  @Override public boolean isRunning() {
-    return isRunning;
-  }
-
-  @Override public void cancel() {
-    closeTimer(false);
-    mListener.onCancel();
-    onCancel();
-    if (!mExePool.isShutdown()) {
-      mExePool.shutdown();
-    }
-
-    Set<String> keys = mDownloaderMap.keySet();
-    for (String key : keys) {
-      Downloader dt = mDownloaderMap.get(key);
-      if (dt != null) {
-        dt.cancel();
-      }
-    }
-    delDownloadInfo();
-    mTaskEntity.deleteData();
-  }
-
-  public void onCancel() {
-
-  }
-
-  /**
-   * 删除所有子任务的下载信息
-   */
-  private void delDownloadInfo() {
-    List<DownloadTaskEntity> tasks =
-        DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", mTaskEntity.key);
-    if (tasks == null || tasks.isEmpty()) return;
-    for (DownloadTaskEntity taskEntity : tasks) {
-      CommonUtil.delDownloadTaskConfig(taskEntity.removeFile, taskEntity);
-    }
-  }
-
-  @Override public void stop() {
-    closeTimer(false);
-    mListener.onStop(mCurrentLocation);
-    onStop();
-    if (!mExePool.isShutdown()) {
-      mExePool.shutdown();
-    }
-
-    Set<String> keys = mDownloaderMap.keySet();
-    for (String key : keys) {
-      Downloader dt = mDownloaderMap.get(key);
-      if (dt != null) {
-        dt.stop();
-      }
-    }
-  }
-
-  protected void onStop() {
-
-  }
-
-  @Override public void start() {
-    isRunning = true;
-    mFailNum = 0;
-    mListener.onPre();
-    onStart();
-  }
-
-  protected void onStart() {
-
-  }
-
-  @Override public void resume() {
-    start();
-    mListener.onResume(mCurrentLocation);
-  }
-
-  @Override public void setMaxSpeed(double maxSpeed) {
-
-  }
-
-  private void closeTimer(boolean isRunning) {
-    this.isRunning = isRunning;
-    if (mTimer != null) {
-      mTimer.purge();
-      mTimer.cancel();
-    }
-  }
-
-  /**
-   * 开始进度流程
-   */
-  void startRunningFlow() {
-    closeTimer(true);
-    mListener.onPostPre(mTotalSize);
-    mListener.onStart(mCurrentLocation);
-    mTimer = new Timer(true);
-    mTimer.schedule(new TimerTask() {
-      @Override public void run() {
-        if (!isRunning) {
-          closeTimer(false);
-        } else if (mCurrentLocation >= 0) {
-          mListener.onProgress(mCurrentLocation);
-        }
-      }
-    }, 0, 1000);
-  }
-
-  /**
-   * 启动子任务下载器
-   */
-  void startChildDownload(DownloadTaskEntity taskEntity) {
-    ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
-    Downloader dt = new Downloader(listener, taskEntity);
-    mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
-    if (mExePool.isShutdown()) return;
-    mExePool.execute(dt);
-  }
-
-  /**
-   * 创建子任务下载信息
-   */
-  DownloadTaskEntity createChildDownloadTask(DownloadEntity entity) {
-    DownloadTaskEntity taskEntity = mTasksMap.get(entity.getUrl());
-    if (taskEntity != null) {
-      taskEntity.entity = entity;
-      //ftp登录的
-      taskEntity.userName = mTaskEntity.userName;
-      taskEntity.userPw = mTaskEntity.userPw;
-      taskEntity.account = mTaskEntity.account;
-      return taskEntity;
-    }
-    taskEntity = new DownloadTaskEntity();
-    taskEntity.entity = entity;
-    taskEntity.headers = mTaskEntity.headers;
-    taskEntity.requestEnum = mTaskEntity.requestEnum;
-    taskEntity.redirectUrlKey = mTaskEntity.redirectUrlKey;
-    taskEntity.removeFile = mTaskEntity.removeFile;
-    taskEntity.groupName = mTaskEntity.key;
-    taskEntity.isGroupTask = true;
-    taskEntity.requestType = mTaskEntity.requestType;
-    //ftp登录的
-    taskEntity.userName = mTaskEntity.userName;
-    taskEntity.userPw = mTaskEntity.userPw;
-    taskEntity.account = mTaskEntity.account;
-    taskEntity.key = entity.getDownloadPath();
-    taskEntity.save();
-    return taskEntity;
-  }
-
-  /**
-   * 子任务事件监听
-   */
-  private class ChildDownloadListener implements IDownloadListener {
-
-    DownloadTaskEntity taskEntity;
-    DownloadEntity entity;
-
-    long lastLen = 0;
-
-    ChildDownloadListener(DownloadTaskEntity entity) {
-      this.taskEntity = entity;
-      this.entity = taskEntity.getEntity();
-      lastLen = this.entity.getCurrentProgress();
-      this.entity.setFailNum(0);
-    }
-
-    @Override public void onPre() {
-      saveData(IEntity.STATE_PRE, -1);
-    }
-
-    @Override public void onPostPre(long fileSize) {
-      entity.setFileSize(fileSize);
-      entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize));
-      saveData(IEntity.STATE_POST_PRE, -1);
-    }
-
-    @Override public void onResume(long resumeLocation) {
-      saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
-      lastLen = resumeLocation;
-    }
-
-    @Override public void onStart(long startLocation) {
-      saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING);
-      lastLen = startLocation;
-    }
-
-    @Override public void onProgress(long currentLocation) {
-      long speed = currentLocation - lastLen;
-      mCurrentLocation += speed;
-      lastLen = currentLocation;
-      entity.setCurrentProgress(currentLocation);
-      handleSpeed(speed);
-    }
-
-    @Override public void onStop(long stopLocation) {
-      saveData(IEntity.STATE_STOP, stopLocation);
-      handleSpeed(0);
-      mListener.onSubStop(entity);
-    }
-
-    @Override public void onCancel() {
-      saveData(IEntity.STATE_CANCEL, -1);
-      handleSpeed(0);
-      mListener.onSubCancel(entity);
-    }
-
-    @Override public void onComplete() {
-      saveData(IEntity.STATE_COMPLETE, entity.getFileSize());
-      mCompleteNum++;
-      handleSpeed(0);
-      mListener.onSubComplete(entity);
-      //如果子任务完成的数量和总任务数一致,表示任务组任务已经完成
-      if (mCompleteNum >= mTaskEntity.getEntity().getSubTask().size()) {
-        closeTimer(false);
-        mListener.onComplete();
-      } else if (mCompleteNum + mFailNum >= mActualTaskNum) {
-        //如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载
-        closeTimer(false);
-      }
-    }
-
-    @Override public void onFail() {
-      entity.setFailNum(entity.getFailNum() + 1);
-      saveData(IEntity.STATE_FAIL, lastLen);
-      handleSpeed(0);
-      reTry();
-    }
-
-    /**
-     * 失败后重试下载,如果失败次数超过5次,不再重试
-     */
-    private void reTry() {
-      synchronized (AriaManager.LOCK) {
-        if (entity.getFailNum() < 5 && isRunning) {
-          reStartTask();
-        } else {
-          mFailNum++;
-          mListener.onSubFail(entity);
-          //如果失败的任务数大于实际的下载任务数,任务组停止下载
-          if (mFailNum >= mActualTaskNum) {
-            closeTimer(false);
-            mListener.onStop(mCurrentLocation);
-          }
-        }
-      }
-    }
-
-    private void reStartTask() {
-      Timer timer = new Timer();
-      timer.schedule(new TimerTask() {
-        @Override public void run() {
-          Downloader dt = mDownloaderMap.get(entity.getUrl());
-          dt.start();
-        }
-      }, 3000);
-    }
-
-    private void handleSpeed(long speed) {
-      entity.setSpeed(speed);
-      entity.setConvertSpeed(speed <= 0 ? "" : CommonUtil.formatFileSize(speed) + "/s");
-    }
-
-    private void saveData(int state, long location) {
-      entity.setState(state);
-      entity.setComplete(state == IEntity.STATE_COMPLETE);
-      if (entity.isComplete()) {
-        entity.setCompleteTime(System.currentTimeMillis());
-        entity.setCurrentProgress(entity.getFileSize());
-      } else if (location > 0) {
-        entity.setCurrentProgress(location);
-      }
-      entity.update();
-    }
-
-    @Override public void supportBreakpoint(boolean support) {
-
-    }
-  }
-}

+ 0 - 145
Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java

@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.text.TextUtils;
-
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.util.SSLContextUtil;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.ProtocolException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Set;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import org.apache.commons.net.ftp.FTPClient;
-
-/**
- * Created by lyy on 2017/1/18.
- * 链接帮助类
- */
-class ConnectionHelp {
-
-  /**
-   * 处理链接
-   *
-   * @throws IOException
-   */
-  static HttpURLConnection handleConnection(URL url) throws IOException {
-    HttpURLConnection conn;
-    URLConnection urlConn = url.openConnection();
-    if (urlConn instanceof HttpsURLConnection) {
-      conn = (HttpsURLConnection) urlConn;
-      SSLContext sslContext =
-          SSLContextUtil.getSSLContext(SSLContextUtil.CA_ALIAS, SSLContextUtil.CA_PATH);
-      if (sslContext == null) {
-        sslContext = SSLContextUtil.getDefaultSLLContext();
-      }
-      SSLSocketFactory ssf = sslContext.getSocketFactory();
-      ((HttpsURLConnection) conn).setSSLSocketFactory(ssf);
-      ((HttpsURLConnection) conn).setHostnameVerifier(SSLContextUtil.HOSTNAME_VERIFIER);
-    } else {
-      conn = (HttpURLConnection) urlConn;
-    }
-    return conn;
-  }
-
-  /**
-   * 设置头部参数
-   *
-   * @throws ProtocolException
-   */
-  static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn)
-      throws ProtocolException {
-    conn.setRequestMethod(entity.requestEnum.name);
-    Set<String> keys = null;
-    if (entity.headers != null && entity.headers.size() > 0) {
-      keys = entity.headers.keySet();
-      for (String key : keys) {
-        conn.setRequestProperty(key, entity.headers.get(key));
-      }
-    }
-    if (keys == null || !keys.contains("Charset")) {
-      conn.setRequestProperty("Charset", "UTF-8");
-    }
-    if (keys == null || !keys.contains("User-Agent")) {
-      conn.setRequestProperty("User-Agent", getUserAgent());
-    }
-    if (keys == null || !keys.contains("Accept")) {
-      StringBuilder accept = new StringBuilder();
-      accept.append("image/gif, ")
-          .append("image/jpeg, ")
-          .append("image/pjpeg, ")
-          .append("image/webp, ")
-          .append("application/xml, ")
-          .append("application/xaml+xml, ")
-          .append("application/xhtml+xml, ")
-          .append("application/x-shockwave-flash, ")
-          .append("application/x-ms-xbap, ")
-          .append("application/x-ms-application, ")
-          .append("application/msword, ")
-          .append("application/vnd.ms-excel, ")
-          .append("application/vnd.ms-xpsdocument, ")
-          .append("application/vnd.ms-powerpoint, ")
-          .append("text/plain, ")
-          .append("text/html, ")
-          .append("*/*");
-      conn.setRequestProperty("Accept", accept.toString());
-    }
-    if (keys == null || !keys.contains("Accept-Encoding")) {
-      conn.setRequestProperty("Accept-Encoding", "identity");
-    }
-    if (keys == null || !keys.contains("Accept-Charset")) {
-      conn.setRequestProperty("Accept-Charset", "UTF-8");
-    }
-    if (keys == null || !keys.contains("Connection")) {
-      conn.setRequestProperty("Connection", "Keep-Alive");
-    }
-    //302获取重定向地址
-    conn.setInstanceFollowRedirects(false);
-    return conn;
-  }
-
-  /**
-   * 返回正确的UserAgent
-   * @return
-   */
-  public   static String getUserAgent(){
-    StringBuilder sb = null;
-    try {
-      String userAgent;
-      sb = new StringBuilder();
-      userAgent = System.getProperty("http.agent");//Dalvik/2.1.0 (Linux; U; Android 6.0.1; vivo X9L Build/MMB29M)
-
-      for (int i = 0, length = userAgent.length(); i < length; i++) {
-        char c = userAgent.charAt(i);
-        if (c <= '\u001f' || c >= '\u007f') {
-          sb.append(String.format("\\u%04x", (int) c));
-        } else {
-          sb.append(c);
-        }
-      }
-
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-    return TextUtils.isEmpty(sb) ? "Dalvik/2.1.0 (Linux; U; Android 5.1.1; letv x501 Build/LMY48Z)" : sb.toString();
-  }
-
-}

+ 0 - 127
Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java

@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.util.SparseArray;
-import com.arialyy.aria.core.common.IUtil;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.IEntity;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * Created by AriaL on 2017/6/30.
- * 任务组下载工具
- */
-public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
-  private final String TAG = "DownloadGroupUtil";
-  private ExecutorService mInfoPool;
-
-  /**
-   * 文件信息回调组
-   */
-  private SparseArray<OnFileInfoCallback> mFileInfoCallbacks = new SparseArray<>();
-
-  public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
-    super(listener, taskEntity);
-    mInfoPool = Executors.newCachedThreadPool();
-  }
-
-  @Override public void onCancel() {
-    super.onCancel();
-    if (!mInfoPool.isShutdown()) {
-      mInfoPool.shutdown();
-    }
-  }
-
-  @Override protected void onStop() {
-    super.onStop();
-    if (!mInfoPool.isShutdown()) {
-      mInfoPool.shutdown();
-    }
-  }
-
-  @Override protected void onStart() {
-    super.onStart();
-    Set<String> keys = mExeMap.keySet();
-    int i = 0;
-    for (String key : keys) {
-      DownloadTaskEntity taskEntity = mExeMap.get(key);
-      if (taskEntity != null) {
-        if (taskEntity.getState() != IEntity.STATE_FAIL
-            && taskEntity.getState() != IEntity.STATE_WAIT) {
-          startChildDownload(taskEntity);
-          i++;
-        } else {
-          mInfoPool.execute(createFileInfoThread(taskEntity));
-        }
-      }
-    }
-    if (i != 0 && i == mExeMap.size()) startRunningFlow();
-    if (mCurrentLocation == mTotalSize) {
-      mListener.onComplete();
-    }
-  }
-
-  /**
-   * 创建文件信息获取线程
-   */
-  private HttpFileInfoThread createFileInfoThread(DownloadTaskEntity taskEntity) {
-    OnFileInfoCallback callback = mFileInfoCallbacks.get(taskEntity.hashCode());
-
-    if (callback == null) {
-      callback = new OnFileInfoCallback() {
-        int failNum = 0;
-
-        @Override public void onComplete(String url, int code) {
-          DownloadTaskEntity te = mExeMap.get(url);
-          if (te != null) {
-            mTotalSize += te.getEntity().getFileSize();
-            startChildDownload(te);
-          }
-          mInitNum++;
-          if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) {
-            startRunningFlow();
-          }
-        }
-
-        @Override public void onFail(String url, String errorMsg) {
-          DownloadTaskEntity te = mExeMap.get(url);
-          if (te != null) {
-            mFailMap.put(url, te);
-            mFileInfoCallbacks.put(te.hashCode(), this);
-          }
-          //404链接不重试下载
-          if (failNum < 10 && !errorMsg.contains("错误码:404") && !errorMsg.contains(
-              "UnknownHostException")) {
-            mInfoPool.execute(createFileInfoThread(te));
-          } else {
-            mInitFailNum++;
-            mActualTaskNum--;
-            if (mActualTaskNum < 0) mActualTaskNum = 0;
-          }
-          failNum++;
-          if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) {
-            startRunningFlow();
-          }
-        }
-      };
-    }
-    return new HttpFileInfoThread(taskEntity, callback);
-  }
-}

+ 0 - 100
Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java

@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.AbsFileer;
-import com.arialyy.aria.core.common.AbsThreadTask;
-import com.arialyy.aria.core.common.SubThreadConfig;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.util.BufferedRandomAccessFile;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Created by AriaL on 2017/7/1.
- * 文件下载器
- */
-class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
-
-  Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) {
-    super(listener, taskEntity);
-  }
-
-  @Override protected void checkTask() {
-    if (!mTaskEntity.isSupportBP) {
-      isNewTask = true;
-      return;
-    }
-    mConfigFile = new File(mContext.getFilesDir().getPath()
-        + AriaManager.DOWNLOAD_TEMP_DIR
-        + mEntity.getFileName()
-        + ".properties");
-    mTempFile = new File(mEntity.getDownloadPath());
-    if (!mConfigFile.exists()) { //记录文件被删除,则重新下载
-      isNewTask = true;
-      CommonUtil.createFile(mConfigFile.getPath());
-    } else if (!mTempFile.exists()) {
-      isNewTask = true;
-    } else if (DbEntity.findFirst(DownloadEntity.class, "url=?", mEntity.getDownloadUrl())
-        == null) {
-      isNewTask = true;
-    } else {
-      isNewTask = checkConfigFile();
-    }
-  }
-
-  @Override protected void handleNewTask() {
-    CommonUtil.createFile(mTempFile.getPath());
-    BufferedRandomAccessFile file = null;
-    try {
-      file = new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
-      //设置文件长度
-      file.setLength(mEntity.getFileSize());
-    } catch (IOException e) {
-      failDownload("下载失败【downloadUrl:"
-          + mEntity.getUrl()
-          + "】\n【filePath:"
-          + mEntity.getDownloadPath()
-          + "】\n"
-          + CommonUtil.getPrintException(e));
-    } finally {
-      if (file != null) {
-        try {
-          file.close();
-        } catch (IOException e) {
-          e.printStackTrace();
-        }
-      }
-    }
-  }
-
-  @Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DownloadTaskEntity> config) {
-    switch (mTaskEntity.requestType) {
-      case AbsTaskEntity.FTP:
-      case AbsTaskEntity.FTP_DIR:
-        return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config);
-      case AbsTaskEntity.HTTP:
-        return new HttpThreadTask(mConstance, (IDownloadListener) mListener, config);
-    }
-    return null;
-  }
-}

+ 0 - 118
Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpClientHelp.java

@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import java.io.IOException;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPReply;
-
-/**
- * Created by Aria.Lao on 2017/7/26.
- */
-public class FtpClientHelp {
-  private final String TAG = "FtpClientHelp";
-  private static volatile FtpClientHelp INSTANCE = null;
-
-  private FTPClient client;
-  private String serverIp, user, pw, account;
-  private int port;
-
-  private FtpClientHelp() {
-  }
-
-  public static FtpClientHelp getInstnce() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new FtpClientHelp();
-      }
-    }
-    return INSTANCE;
-  }
-
-  public FTPClient getClient() {
-    if (client == null || !client.isConnected()) {
-      createClient();
-    }
-    return client;
-  }
-
-  /**
-   * 登录到FTP服务器,当客户端为null或客户端没有连接到FTP服务器时才会执行登录操作
-   */
-  public FTPClient login(String serverIp, int port, String user, String pw, String account) {
-    this.serverIp = serverIp;
-    this.port = port;
-    this.user = user;
-    this.pw = pw;
-    this.account = account;
-    if (client == null || !client.isConnected()) {
-      createClient();
-    }
-    return client;
-  }
-
-  /**
-   * 登出
-   */
-  public void logout() {
-    try {
-      if (client != null && client.isConnected()) {
-        client.logout();
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-  }
-
-  FTPClient createClient() {
-    new Thread(new Runnable() {
-      @Override public void run() {
-        client = new FTPClient();
-        try {
-          client.connect(serverIp, port);
-          if (!TextUtils.isEmpty(account)) {
-            client.login(user, pw);
-          } else {
-            client.login(user, pw, account);
-          }
-          int reply = client.getReplyCode();
-          if (!FTPReply.isPositiveCompletion(reply)) {
-            client.disconnect();
-            Log.e(TAG, "无法连接到ftp服务器,错误码为:" + reply);
-          }
-        } catch (IOException e) {
-          Log.d(TAG, e.getMessage());
-        } finally {
-          synchronized (FtpClientHelp.this) {
-            FtpClientHelp.this.notify();
-          }
-        }
-      }
-    }).start();
-    synchronized (FtpClientHelp.this) {
-      try {
-        wait();
-      } catch (InterruptedException e) {
-        e.printStackTrace();
-      }
-    }
-
-    return client;
-  }
-}

+ 0 - 68
Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java

@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import java.util.Set;
-
-/**
- * Created by Aria.Lao on 2017/7/27.
- * ftp文件夹下载工具
- */
-public class FtpDirDownloadUtil extends AbsGroupUtil {
-  public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
-    super(listener, taskEntity);
-  }
-
-  @Override protected void onStart() {
-    super.onStart();
-    if (mTaskEntity.getEntity().getFileSize() > 1) {
-      startDownload();
-    } else {
-      new FtpDirInfoThread(mTaskEntity, new OnFileInfoCallback() {
-        @Override public void onComplete(String url, int code) {
-          if (code >= 200 && code < 300) {
-            mTotalSize = mTaskEntity.getEntity().getFileSize();
-            for (DownloadEntity entity : mTaskEntity.entity.getSubTask()) {
-              mExeMap.put(entity.getUrl(), createChildDownloadTask(entity));
-            }
-            mActualTaskNum = mTaskEntity.entity.getSubTask().size();
-            startDownload();
-          }
-        }
-
-        @Override public void onFail(String url, String errorMsg) {
-          mListener.onFail();
-        }
-      }).start();
-    }
-  }
-
-  private void startDownload() {
-    int i = 0;
-    Set<String> keys = mExeMap.keySet();
-    for (String key : keys) {
-      DownloadTaskEntity taskEntity = mExeMap.get(key);
-      if (taskEntity != null) {
-        startChildDownload(taskEntity);
-        i++;
-      }
-    }
-    if (i == mExeMap.size()) startRunningFlow();
-  }
-}

+ 0 - 68
Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java

@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadGroupEntity;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.util.CommonUtil;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import org.apache.commons.net.ftp.FTPFile;
-
-/**
- * Created by Aria.Lao on 2017/7/25.
- * 获取ftp文件夹信息
- */
-class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DownloadGroupTaskEntity> {
-  private long mSize = 0;
-
-  FtpDirInfoThread(DownloadGroupTaskEntity taskEntity, OnFileInfoCallback callback) {
-    super(taskEntity, callback);
-  }
-
-  @Override void handleFile(String remotePath, FTPFile ftpFile) {
-    super.handleFile(remotePath, ftpFile);
-    mSize += ftpFile.getSize();
-    addEntity(remotePath, ftpFile);
-  }
-
-  @Override protected void onPreComplete() {
-    super.onPreComplete();
-    mEntity.setFileSize(mSize);
-  }
-
-  private void addEntity(String remotePath, FTPFile ftpFile) {
-    DownloadEntity entity = new DownloadEntity();
-    entity.setUrl("ftp://" + mTaskEntity.serverIp + ":" + mTaskEntity.port + remotePath);
-    entity.setDownloadPath(mEntity.getDirPath() + "/" + remotePath);
-    int lastIndex = remotePath.lastIndexOf("/");
-    String fileName = lastIndex < 0 ? CommonUtil.keyToHashKey(remotePath)
-        : remotePath.substring(lastIndex + 1, remotePath.length());
-    entity.setFileName(new String(fileName.getBytes(), Charset.forName(mTaskEntity.charSet)));
-    entity.setGroupName(mEntity.getGroupName());
-    entity.setGroupChild(true);
-    entity.setFileSize(ftpFile.getSize());
-    entity.insert();
-    if (mEntity.getUrls() == null) {
-      mEntity.setUrls(new ArrayList<String>());
-    }
-    if (mEntity.getSubTask() == null) {
-      mEntity.setSubTasks(new ArrayList<DownloadEntity>());
-    }
-    mEntity.getSubTask().add(entity);
-  }
-}

+ 0 - 30
Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java

@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-
-/**
- * Created by Aria.Lao on 2017/7/25.
- * 获取ftp文件信息
- */
-class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEntity> {
-
-  FtpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) {
-    super(taskEntity, callback);
-  }
-}

+ 0 - 151
Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java

@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.common.AbsThreadTask;
-import com.arialyy.aria.core.common.StateConstance;
-import com.arialyy.aria.core.common.SubThreadConfig;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.util.BufferedRandomAccessFile;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPReply;
-
-/**
- * Created by Aria.Lao on 2017/7/24.
- * Ftp下载任务
- */
-class FtpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEntity> {
-  private final String TAG = "FtpThreadTask";
-
-  FtpThreadTask(StateConstance constance, IDownloadListener listener,
-      SubThreadConfig<DownloadTaskEntity> downloadInfo) {
-    super(constance, listener, downloadInfo);
-  }
-
-  @Override public void run() {
-    FTPClient client = null;
-    InputStream is = null;
-    BufferedRandomAccessFile file = null;
-    try {
-      Log.d(TAG, "任务【"
-          + mConfig.TEMP_FILE.getName()
-          + "】线程__"
-          + mConfig.THREAD_ID
-          + "__开始下载【开始位置 : "
-          + mConfig.START_LOCATION
-          + ",结束位置:"
-          + mConfig.END_LOCATION
-          + "】");
-      String url = mEntity.getUrl();
-      String[] pp = url.split("/")[2].split(":");
-      String serverIp = pp[0];
-      int port = Integer.parseInt(pp[1]);
-      String remotePath = url.substring(url.indexOf(pp[1]) + pp[1].length(), url.length());
-      client = new FTPClient();
-      client.connect(serverIp, port);
-      if (!TextUtils.isEmpty(mTaskEntity.account)) {
-        client.login(mTaskEntity.userName, mTaskEntity.userPw);
-      } else {
-        client.login(mTaskEntity.userName, mTaskEntity.userPw, mTaskEntity.account);
-      }
-      int reply = client.getReplyCode();
-      if (!FTPReply.isPositiveCompletion(reply)) {
-        client.disconnect();
-        fail(STATE.CURRENT_LOCATION, "无法连接到ftp服务器,错误码为:" + reply, null);
-        return;
-      }
-      String charSet = "UTF-8";
-      // 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码
-      if (!TextUtils.isEmpty(mTaskEntity.charSet) || !FTPReply.isPositiveCompletion(
-          client.sendCommand("OPTS UTF8", "ON"))) {
-        charSet = mTaskEntity.charSet;
-      }
-      client.setControlEncoding(charSet);
-      client.setDataTimeout(STATE.READ_TIME_OUT);
-      client.enterLocalPassiveMode();
-      client.setFileType(FTP.BINARY_FILE_TYPE);
-      client.setRestartOffset(mConfig.START_LOCATION);
-      client.allocate(mBufSize);
-      is = client.retrieveFileStream(
-          new String(remotePath.getBytes(charSet), SERVER_CHARSET));
-      //发送第二次指令时,还需要再做一次判断
-      reply = client.getReplyCode();
-      if (!FTPReply.isPositivePreliminary(reply)) {
-        client.disconnect();
-        fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply, null);
-        return;
-      }
-      file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize);
-      file.seek(mConfig.START_LOCATION);
-      byte[] buffer = new byte[mBufSize];
-      int len;
-      //当前子线程的下载位置
-      mChildCurrentLocation = mConfig.START_LOCATION;
-      while ((len = is.read(buffer)) != -1) {
-        if (STATE.isCancel) break;
-        if (STATE.isStop) break;
-        if (mSleepTime > 0) Thread.sleep(mSleepTime);
-        if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
-          len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
-          file.write(buffer, 0, len);
-          progress(len);
-          break;
-        } else {
-          file.write(buffer, 0, len);
-          progress(len);
-        }
-      }
-      if (STATE.isCancel || STATE.isStop) return;
-      Log.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__下载完毕");
-      writeConfig(true, 1);
-      STATE.COMPLETE_THREAD_NUM++;
-      if (STATE.isComplete()) {
-        File configFile = new File(mConfigFPath);
-        if (configFile.exists()) {
-          configFile.delete();
-        }
-        STATE.isRunning = false;
-        mListener.onComplete();
-      }
-    } catch (IOException e) {
-      fail(mChildCurrentLocation, "下载失败【" + mConfig.URL + "】", e);
-    } catch (Exception e) {
-      fail(mChildCurrentLocation, "获取流失败", e);
-    } finally {
-      try {
-        if (file != null) {
-          file.close();
-        }
-        if (is != null) {
-          is.close();
-        }
-        if (client != null && client.isConnected()) {
-          client.disconnect();
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-}

+ 0 - 170
Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java

@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.download.downloader.ConnectionHelp;
-import com.arialyy.aria.util.CommonUtil;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLDecoder;
-
-/**
- * 下载文件信息获取
- */
-class HttpFileInfoThread implements Runnable {
-  private final String TAG = "HttpFileInfoThread";
-  private DownloadEntity mEntity;
-  private DownloadTaskEntity mTaskEntity;
-  private int mConnectTimeOut;
-  private OnFileInfoCallback onFileInfoListener;
-
-  HttpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) {
-    this.mTaskEntity = taskEntity;
-    mEntity = taskEntity.getEntity();
-    mConnectTimeOut =
-        AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut();
-    onFileInfoListener = callback;
-  }
-
-  @Override public void run() {
-    HttpURLConnection conn = null;
-    try {
-      URL url = new URL(mEntity.getUrl());
-      conn = ConnectionHelp.handleConnection(url);
-      conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
-      conn.setRequestProperty("Range", "bytes=" + 0 + "-");
-      conn.setConnectTimeout(mConnectTimeOut);
-      conn.connect();
-      handleConnect(conn);
-    } catch (IOException e) {
-      failDownload("下载失败【downloadUrl:"
-          + mEntity.getUrl()
-          + "】\n【filePath:"
-          + mEntity.getDownloadPath()
-          + "】\n"
-          + CommonUtil.getPrintException(e));
-    } finally {
-      if (conn != null) {
-        conn.disconnect();
-      }
-    }
-  }
-
-  private void handleConnect(HttpURLConnection conn) throws IOException {
-    long len = conn.getContentLength();
-    if (len < 0) {
-      String temp = conn.getHeaderField(mTaskEntity.contentLength);
-      len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp);
-    }
-    int code = conn.getResponseCode();
-    boolean isComplete = false;
-    if (TextUtils.isEmpty(mEntity.getMd5Code())) {
-      String md5Code = conn.getHeaderField(mTaskEntity.md5Key);
-      mEntity.setMd5Code(md5Code);
-    }
-    String disposition = conn.getHeaderField(mTaskEntity.dispositionKey);
-    //Map<String, List<String>> headers = conn.getHeaderFields();
-    if (!TextUtils.isEmpty(disposition)) {
-      mEntity.setDisposition(CommonUtil.encryptBASE64(disposition));
-      if (disposition.contains(mTaskEntity.dispositionFileKey)) {
-        String[] infos = disposition.split("=");
-        mEntity.setServerFileName(URLDecoder.decode(infos[1], "utf-8"));
-      }
-    }
-
-    mTaskEntity.code = code;
-    if (code == HttpURLConnection.HTTP_PARTIAL) {
-      if (!checkLen(len)) return;
-      mEntity.setFileSize(len);
-      mTaskEntity.isSupportBP = true;
-      isComplete = true;
-    } else if (code == HttpURLConnection.HTTP_OK) {
-      if (!checkLen(len)) return;
-      mEntity.setFileSize(len);
-      mTaskEntity.isSupportBP = false;
-      isComplete = true;
-    } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
-      failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:404");
-    } else if (code == HttpURLConnection.HTTP_MOVED_TEMP
-        || code == HttpURLConnection.HTTP_MOVED_PERM
-        || code == 307
-        || code == HttpURLConnection.HTTP_SEE_OTHER) {
-      mTaskEntity.redirectUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey);
-      mEntity.setRedirect(true);
-      mEntity.setRedirectUrl(mTaskEntity.redirectUrl);
-      handle302Turn(conn);
-    } else {
-      failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:" + code);
-    }
-    if (isComplete) {
-      if (onFileInfoListener != null) {
-        onFileInfoListener.onComplete(mEntity.getUrl(), code);
-      }
-      mEntity.update();
-      mTaskEntity.update();
-    }
-  }
-
-  /**
-   * 处理30x跳转
-   */
-  private void handle302Turn(HttpURLConnection conn) throws IOException {
-    String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey);
-    Log.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】");
-    if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
-      if (onFileInfoListener != null) {
-        onFileInfoListener.onFail(mEntity.getUrl(), "获取重定向链接失败");
-      }
-      return;
-    }
-    String cookies = conn.getHeaderField("Set-Cookie");
-    conn = (HttpURLConnection) new URL(newUrl).openConnection();
-    conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
-    conn.setRequestProperty("Cookie", cookies);
-    conn.setRequestProperty("Range", "bytes=" + 0 + "-");
-    conn.setConnectTimeout(mConnectTimeOut);
-    conn.connect();
-    handleConnect(conn);
-    conn.disconnect();
-  }
-
-  /**
-   * 检查长度是否合法
-   *
-   * @param len 从服务器获取的文件长度
-   * @return true, 合法
-   */
-  private boolean checkLen(long len) {
-    if (len < 0) {
-      failDownload("任务【" + mEntity.getUrl() + "】下载失败,文件长度小于0");
-      return false;
-    }
-    return true;
-  }
-
-  private void failDownload(String errorMsg) {
-    Log.e(TAG, errorMsg);
-    if (onFileInfoListener != null) {
-      onFileInfoListener.onFail(mEntity.getUrl(), errorMsg);
-    }
-  }
-}

+ 0 - 128
Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java

@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import android.util.Log;
-import com.arialyy.aria.core.common.AbsThreadTask;
-import com.arialyy.aria.core.common.StateConstance;
-import com.arialyy.aria.core.common.SubThreadConfig;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.util.BufferedRandomAccessFile;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-/**
- * Created by lyy on 2017/1/18.
- * 下载线程
- */
-final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEntity> {
-  private final String TAG = "HttpThreadTask";
-
-  HttpThreadTask(StateConstance constance, IDownloadListener listener,
-      SubThreadConfig<DownloadTaskEntity> downloadInfo) {
-    super(constance, listener, downloadInfo);
-  }
-
-  @Override public void run() {
-    HttpURLConnection conn = null;
-    InputStream is = null;
-    BufferedRandomAccessFile file = null;
-    try {
-      URL url = new URL(mConfig.URL);
-      conn = ConnectionHelp.handleConnection(url);
-      if (mConfig.SUPPORT_BP) {
-        Log.d(TAG, "任务【"
-            + mConfig.TEMP_FILE.getName()
-            + "】线程__"
-            + mConfig.THREAD_ID
-            + "__开始下载【开始位置 : "
-            + mConfig.START_LOCATION
-            + ",结束位置:"
-            + mConfig.END_LOCATION
-            + "】");
-        //在头里面请求下载开始位置和结束位置
-        conn.setRequestProperty("Range",
-            "bytes=" + mConfig.START_LOCATION + "-" + (mConfig.END_LOCATION - 1));
-      } else {
-        Log.w(TAG, "该下载不支持断点");
-      }
-      conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
-      conn.setConnectTimeout(STATE.CONNECT_TIME_OUT);
-      conn.setReadTimeout(STATE.READ_TIME_OUT);  //设置读取流的等待时间,必须设置该参数
-      is = conn.getInputStream();
-      //创建可设置位置的文件
-      file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize);
-      //设置每条线程写入文件的位置
-      file.seek(mConfig.START_LOCATION);
-      byte[] buffer = new byte[mBufSize];
-      int len;
-      //当前子线程的下载位置
-      mChildCurrentLocation = mConfig.START_LOCATION;
-      while ((len = is.read(buffer)) != -1) {
-        if (STATE.isCancel) break;
-        if (STATE.isStop) break;
-        if (mSleepTime > 0) Thread.sleep(mSleepTime);
-        file.write(buffer, 0, len);
-        progress(len);
-      }
-      if (STATE.isCancel || STATE.isStop) return;
-      //支持断点的处理
-      if (mConfig.SUPPORT_BP) {
-        Log.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__下载完毕");
-        writeConfig(true, 1);
-        STATE.COMPLETE_THREAD_NUM++;
-        if (STATE.isComplete()) {
-          File configFile = new File(mConfigFPath);
-          if (configFile.exists()) {
-            configFile.delete();
-          }
-          STATE.isRunning = false;
-          mListener.onComplete();
-        }
-      } else {
-        Log.i(TAG, "下载任务完成");
-        STATE.isRunning = false;
-        mListener.onComplete();
-      }
-    } catch (MalformedURLException e) {
-      fail(mChildCurrentLocation, "下载链接异常", e);
-    } catch (IOException e) {
-      fail(mChildCurrentLocation, "下载失败【" + mConfig.URL + "】", e);
-    } catch (Exception e) {
-      fail(mChildCurrentLocation, "获取流失败", e);
-    } finally {
-      try {
-        if (file != null) {
-          file.close();
-        }
-        if (is != null) {
-          is.close();
-        }
-        if (conn != null) {
-          conn.disconnect();
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-}

+ 0 - 59
Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java

@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-import com.arialyy.aria.core.inf.IEventListener;
-
-/**
- * Created by Aria.Lao on 2017/7/20.
- * 下载任务组事件
- */
-public interface IDownloadGroupListener extends IDownloadListener {
-
-  /**
-   * 子任务支持断点回调
-   *
-   * @param support true,支持;false 不支持
-   */
-  void supportBreakpoint(boolean support, DownloadEntity subEntity);
-
-  /**
-   * 子任务开始下载\恢复下载
-   */
-  void onSubStart(DownloadEntity subEntity);
-
-  /**
-   * 子任务停止下载
-   */
-  void onSubStop(DownloadEntity subEntity);
-
-  /**
-   * 子任务下载完成
-   */
-  void onSubComplete(DownloadEntity subEntity);
-
-  /**
-   * 子任务下载失败
-   */
-  void onSubFail(DownloadEntity subEntity);
-
-  /**
-   * 子任务取消下载
-   */
-  void onSubCancel(DownloadEntity subEntity);
-}

+ 0 - 17
Aria/src/main/java/com/arialyy/aria/core/download/downloader/OnFileInfoCallback.java

@@ -1,17 +0,0 @@
-package com.arialyy.aria.core.download.downloader;
-
-interface OnFileInfoCallback {
-  /**
-   * 处理完成
-   *
-   * @param code 状态码
-   */
-  void onComplete(String url, int code);
-
-  /**
-   * 请求失败
-   *
-   * @param errorMsg 错误信息
-   */
-  void onFail(String url, String errorMsg);
-}

+ 0 - 125
Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java

@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.download.downloader;
-
-import com.arialyy.aria.core.common.IUtil;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IDownloadListener;
-
-/**
- * Created by lyy on 2015/8/25.
- * HTTP单任务下载工具
- */
-public class SimpleDownloadUtil implements IUtil, Runnable {
-  private static final String TAG = "SimpleDownloadUtil";
-  private IDownloadListener mListener;
-  private Downloader mDownloader;
-  private DownloadTaskEntity mTaskEntity;
-
-  public SimpleDownloadUtil(DownloadTaskEntity entity, IDownloadListener downloadListener) {
-    mTaskEntity = entity;
-    mListener = downloadListener;
-    mDownloader = new Downloader(downloadListener, entity);
-  }
-
-  @Override public long getFileSize() {
-    return mDownloader.getFileSize();
-  }
-
-  /**
-   * 获取当前下载位置
-   */
-  @Override public long getCurrentLocation() {
-    return mDownloader.getCurrentLocation();
-  }
-
-  @Override public boolean isRunning() {
-    return mDownloader.isRunning();
-  }
-
-  /**
-   * 取消下载
-   */
-  @Override public void cancel() {
-    mDownloader.cancel();
-  }
-
-  /**
-   * 停止下载
-   */
-  @Override public void stop() {
-    mDownloader.stop();
-  }
-
-  /**
-   * 多线程断点续传下载文件,开始下载
-   */
-  @Override public void start() {
-    new Thread(this).start();
-  }
-
-  @Override public void resume() {
-    start();
-  }
-
-  public void setMaxSpeed(double maxSpeed) {
-    mDownloader.setMaxSpeed(maxSpeed);
-  }
-
-  private void failDownload(String msg) {
-    mListener.onFail();
-  }
-
-  @Override public void run() {
-    mListener.onPre();
-    if (mTaskEntity.getEntity().getFileSize() <= 1) {
-      new Thread(createInfoThread()).start();
-    } else {
-      mDownloader.start();
-    }
-  }
-
-  /**
-   * 通过链接类型创建不同的获取文件信息的线程
-   */
-  private Runnable createInfoThread() {
-    switch (mTaskEntity.requestType) {
-      case AbsTaskEntity.FTP:
-        return new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
-          @Override public void onComplete(String url, int code) {
-            mDownloader.start();
-          }
-
-          @Override public void onFail(String url, String errorMsg) {
-            failDownload(errorMsg);
-          }
-        });
-      case AbsTaskEntity.HTTP:
-        return new HttpFileInfoThread(mTaskEntity, new OnFileInfoCallback() {
-          @Override public void onComplete(String url, int code) {
-            mDownloader.start();
-          }
-
-          @Override public void onFail(String url, String errorMsg) {
-            failDownload(errorMsg);
-          }
-        });
-    }
-    return null;
-  }
-}

+ 0 - 150
Aria/src/main/java/com/arialyy/aria/core/inf/AbsDownloadTarget.java

@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.command.normal.NormalCmdFactory;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.util.CommonUtil;
-
-/**
- * Created by lyy on 2017/2/28.
- */
-public abstract class AbsDownloadTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
-    extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
-
-  /**
-   * 如果你的下载链接的header中含有md5码信息,那么你可以通过设置key,来获取从header获取该md5码信息。
-   * key默认值为:Content-MD5
-   * 获取md5信息:{@link DownloadEntity#getMd5Code()}
-   */
-  public TARGET setHeaderMd5Key(String md5Key) {
-    if (TextUtils.isEmpty(md5Key)) return (TARGET) this;
-    mTaskEntity.md5Key = md5Key;
-    if (TextUtils.isEmpty(mTaskEntity.md5Key) || !mTaskEntity.md5Key.equals(md5Key)) {
-      mTaskEntity.update();
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 如果你的文件长度是放在header中,那么你需要配置key来让Aria知道正确的文件长度
-   * key默认值为:Content-Length
-   */
-  public TARGET setHeaderContentLengthKey(String contentLength) {
-    if (TextUtils.isEmpty(contentLength)) return (TARGET) this;
-    mTaskEntity.contentLength = contentLength;
-    if (TextUtils.isEmpty(mTaskEntity.contentLength) || !mTaskEntity.contentLength.equals(
-        contentLength)) {
-      mTaskEntity.update();
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 如果你的下载链接的header中含有文件描述信息,那么你可以通过设置key,来获取从header获取该文件描述信息。
-   * key默认值为:Content-Disposition
-   * 获取文件描述信息:{@link DownloadEntity#getDisposition()}
-   */
-  public TARGET setHeaderDispositionKey(String dispositionKey) {
-    if (TextUtils.isEmpty(dispositionKey)) return (TARGET) this;
-    mTaskEntity.dispositionKey = dispositionKey;
-    if (TextUtils.isEmpty(mTaskEntity.dispositionKey) || !mTaskEntity.dispositionKey.equals(
-        dispositionKey)) {
-      mTaskEntity.save();
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 从文件描述信息{@link #setHeaderDispositionKey(String)}中含有文件名信息,你可以通过设置key来获取header中的文件名
-   * key默认值为:attachment;filename
-   * 获取文件名信息:{@link DownloadEntity#getServerFileName()}
-   */
-  public TARGET setHeaderDispositionFileKey(String dispositionFileKey) {
-    if (TextUtils.isEmpty(dispositionFileKey)) return (TARGET) this;
-    mTaskEntity.dispositionFileKey = dispositionFileKey;
-    if (TextUtils.isEmpty(mTaskEntity.dispositionFileKey) || !mTaskEntity.dispositionFileKey.equals(
-        dispositionFileKey)) {
-      mTaskEntity.save();
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 将任务设置为最高优先级任务,最高优先级任务有以下特点:
-   * 1、在下载队列中,有且只有一个最高优先级任务
-   * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
-   * 3、任务调度器不会暂停最高优先级任务
-   * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
-   * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行
-   * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
-   */
-  protected void setHighestPriority() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(
-            CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_HIGHEST_PRIORITY))
-        .exe();
-  }
-
-  /**
-   * 重定向后,新url的key,默认为location
-   */
-  public void setRedirectUrlKey(String redirectUrlKey) {
-    if (TextUtils.isEmpty(redirectUrlKey)) {
-      Log.w("AbsDownloadTarget", "重定向后,新url的key不能为null");
-      return;
-    }
-    mTaskEntity.redirectUrlKey = redirectUrlKey;
-  }
-
-  /**
-   * 获取任务文件大小
-   *
-   * @return 文件大小
-   */
-  public long getFileSize() {
-    return getSize();
-  }
-
-  /**
-   * 获取单位转换后的文件大小
-   *
-   * @return 文件大小{@code xxx mb}
-   */
-  public String getConvertFileSize() {
-    return getConvertSize();
-  }
-
-  /**
-   * 添加任务
-   */
-  public void add() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE))
-        .exe();
-  }
-
-  /**
-   * 重新下载
-   */
-  public void reStart() {
-    cancel();
-    start();
-  }
-}

+ 0 - 182
Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java

@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.orm.Ignore;
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable {
-  /**
-   * 速度
-   */
-  @Ignore private long speed = 0;
-  /**
-   * 单位转换后的速度
-   */
-  @Ignore private String convertSpeed = "";
-  /**
-   * 下载失败计数,每次开始都重置为0
-   */
-  @Ignore private int failNum = 0;
-
-  /**
-   * 扩展字段
-   */
-  private String str = "";
-  /**
-   * 文件大小
-   */
-  private long fileSize = 1;
-  /**
-   * 转换后的文件大小
-   */
-  private String convertFileSize = "";
-
-  private int state = STATE_WAIT;
-  /**
-   * 当前下载进度
-   */
-  private long currentProgress = 0;
-  /**
-   * 完成时间
-   */
-  private long completeTime;
-
-  private boolean isComplete = false;
-
-  public boolean isComplete() {
-    return isComplete;
-  }
-
-  public void setComplete(boolean complete) {
-    isComplete = complete;
-  }
-
-  public String getConvertFileSize() {
-    return convertFileSize;
-  }
-
-  public void setConvertFileSize(String convertFileSize) {
-    this.convertFileSize = convertFileSize;
-  }
-
-  public int getFailNum() {
-    return failNum;
-  }
-
-  public void setFailNum(int failNum) {
-    this.failNum = failNum;
-  }
-
-  public long getSpeed() {
-    return speed;
-  }
-
-  public void setSpeed(long speed) {
-    this.speed = speed;
-  }
-
-  public String getConvertSpeed() {
-    return convertSpeed;
-  }
-
-  public void setConvertSpeed(String convertSpeed) {
-    this.convertSpeed = convertSpeed;
-  }
-
-  public String getStr() {
-    return str;
-  }
-
-  public void setStr(String str) {
-    this.str = str;
-  }
-
-  public long getFileSize() {
-    return fileSize;
-  }
-
-  public void setFileSize(long fileSize) {
-    this.fileSize = fileSize;
-  }
-
-  public int getState() {
-    return state;
-  }
-
-  public void setState(int state) {
-    this.state = state;
-  }
-
-  public long getCurrentProgress() {
-    return currentProgress;
-  }
-
-  public void setCurrentProgress(long currentProgress) {
-    this.currentProgress = currentProgress;
-  }
-
-  public long getCompleteTime() {
-    return completeTime;
-  }
-
-  public void setCompleteTime(long completeTime) {
-    this.completeTime = completeTime;
-  }
-
-  /**
-   * 实体唯一标识符
-   */
-  public abstract String getKey();
-
-  public AbsEntity() {
-  }
-
-  @Override public int describeContents() {
-    return 0;
-  }
-
-  @Override public void writeToParcel(Parcel dest, int flags) {
-    dest.writeLong(this.speed);
-    dest.writeString(this.convertSpeed);
-    dest.writeInt(this.failNum);
-    dest.writeString(this.str);
-    dest.writeLong(this.fileSize);
-    dest.writeString(this.convertFileSize);
-    dest.writeInt(this.state);
-    dest.writeLong(this.currentProgress);
-    dest.writeLong(this.completeTime);
-    dest.writeByte(this.isComplete ? (byte) 1 : (byte) 0);
-  }
-
-  protected AbsEntity(Parcel in) {
-    this.speed = in.readLong();
-    this.convertSpeed = in.readString();
-    this.failNum = in.readInt();
-    this.str = in.readString();
-    this.fileSize = in.readLong();
-    this.convertFileSize = in.readString();
-    this.state = in.readInt();
-    this.currentProgress = in.readLong();
-    this.completeTime = in.readLong();
-    this.isComplete = in.readByte() != 0;
-  }
-}

+ 0 - 70
Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java

@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import com.arialyy.aria.orm.Primary;
-
-/**
- * Created by AriaL on 2017/6/3.
- */
-public abstract class AbsGroupEntity extends AbsEntity implements Parcelable {
-  /**
-   * 组名,组名为任务地址相加的urlMd5
-   */
-  @Primary protected String groupName = "";
-
-  /**
-   * 任务组别名
-   */
-  private String alias = "";
-
-  public String getGroupName() {
-    return groupName;
-  }
-
-  public String getAlias() {
-    return alias;
-  }
-
-  @Override public String getKey() {
-    return groupName;
-  }
-
-  public void setAlias(String alias) {
-    this.alias = alias;
-  }
-
-  public AbsGroupEntity() {
-  }
-
-  @Override public int describeContents() {
-    return 0;
-  }
-
-  @Override public void writeToParcel(Parcel dest, int flags) {
-    super.writeToParcel(dest, flags);
-    dest.writeString(this.groupName);
-    dest.writeString(this.alias);
-  }
-
-  protected AbsGroupEntity(Parcel in) {
-    super(in);
-    this.groupName = in.readString();
-    this.alias = in.readString();
-  }
-}

+ 0 - 31
Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java

@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-public abstract class AbsGroupTask<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsGroupEntity>
-    extends AbsTask<ENTITY> {
-
-  protected TASK_ENTITY mTaskEntity;
-
-
-  @Override public String getKey() {
-    return mEntity.getGroupName();
-  }
-}

+ 0 - 110
Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java

@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.orm.Ignore;
-
-/**
- * Created by AriaL on 2017/6/3.
- */
-public abstract class AbsNormalEntity extends AbsEntity implements Parcelable {
-
-  /**
-   * 服务器地址
-   */
-  private String url = "";
-
-  /**
-   * 文件名
-   */
-  private String fileName = "";
-
-  /**
-   * 是否是任务组里面的下载实体
-   */
-  private boolean isGroupChild = false;
-
-  private boolean isRedirect = false; //是否重定向
-  private String redirectUrl = ""; //重定向链接
-
-  public String getUrl() {
-    return url;
-  }
-
-  public void setUrl(String url) {
-    this.url = url;
-  }
-
-  public boolean isGroupChild() {
-    return isGroupChild;
-  }
-
-  public void setGroupChild(boolean groupChild) {
-    isGroupChild = groupChild;
-  }
-
-  public String getFileName() {
-    return fileName;
-  }
-
-  public void setFileName(String fileName) {
-    this.fileName = fileName;
-  }
-
-  public boolean isRedirect() {
-    return isRedirect;
-  }
-
-  public void setRedirect(boolean redirect) {
-    isRedirect = redirect;
-  }
-
-  public String getRedirectUrl() {
-    return redirectUrl;
-  }
-
-  public void setRedirectUrl(String redirectUrl) {
-    this.redirectUrl = redirectUrl;
-  }
-
-  public AbsNormalEntity() {
-  }
-
-  @Override public int describeContents() {
-    return 0;
-  }
-
-  @Override public void writeToParcel(Parcel dest, int flags) {
-    super.writeToParcel(dest, flags);
-    dest.writeString(this.url);
-    dest.writeString(this.fileName);
-    dest.writeByte(this.isGroupChild ? (byte) 1 : (byte) 0);
-    dest.writeByte(this.isRedirect ? (byte) 1 : (byte) 0);
-    dest.writeString(this.redirectUrl);
-  }
-
-  protected AbsNormalEntity(Parcel in) {
-    super(in);
-    this.url = in.readString();
-    this.fileName = in.readString();
-    this.isGroupChild = in.readByte() != 0;
-    this.isRedirect = in.readByte() != 0;
-    this.redirectUrl = in.readString();
-  }
-}

+ 0 - 44
Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java

@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-/**
- * Created by lyy on 2017/6/3.
- */
-public abstract class AbsNormalTask<ENTITY extends AbsEntity> extends AbsTask<ENTITY> {
-
-  /**
-   * 暂停任务,并让任务处于等待状态
-   */
-  public void stopAndWait() {
-
-  }
-
-  /**
-   * 最高优先级命令,最高优先级命令有以下属性
-   * 1、在下载队列中,有且只有一个最高优先级任务
-   * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
-   * 3、任务调度器不会暂停最高优先级任务
-   * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
-   * 5、如果下载队列中已经满了,则会停止队尾的任务
-   * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
-   */
-  public void setHighestPriority(boolean isHighestPriority) {
-    isHeighestTask = isHighestPriority;
-  }
-
-
-}

+ 0 - 27
Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java

@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.inf;
-
-/**
- * Created by AriaL on 2017/6/27.
- */
-
-public abstract class AbsReceiver<ENTITY extends AbsEntity> implements IReceiver<ENTITY>{
-  public String targetName;
-  public Object obj;
-
-}

+ 0 - 239
Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java

@@ -1,239 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.support.annotation.NonNull;
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.common.RequestEnum;
-import com.arialyy.aria.core.command.normal.NormalCmdFactory;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Created by AriaL on 2017/7/3.
- */
-public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
-    implements ITarget<TARGET> {
-  protected ENTITY mEntity;
-  protected TASK_ENTITY mTaskEntity;
-  protected String mTargetName;
-
-  /**
-   * 删除记录
-   */
-  public void removeRecord() {
-    mEntity.deleteData();
-  }
-
-  /**
-   * 任务是否存在
-   */
-  public boolean taskExists() {
-    return false;
-  }
-
-  /**
-   * 获取任务进度,如果任务存在,则返回当前进度
-   *
-   * @return 该任务进度
-   */
-  public long getCurrentProgress() {
-    return mEntity == null ? -1 : mEntity.getCurrentProgress();
-  }
-
-  /**
-   * 获取任务文件大小
-   *
-   * @return 文件大小
-   */
-  @Override public long getSize() {
-    return mEntity == null ? 0 : mEntity.getFileSize();
-  }
-
-  /**
-   * 获取单位转换后的文件大小
-   *
-   * @return 文件大小{@code xxx mb}
-   */
-  @Override public String getConvertSize() {
-    return mEntity == null ? "0b" : CommonUtil.formatFileSize(mEntity.getFileSize());
-  }
-
-  /**
-   * 设置扩展字段,用来保存你的其它数据,如果你的数据比较多,你可以把你的数据转换为JSON字符串,然后再存到Aria中
-   *
-   * @param str 扩展数据
-   */
-  public TARGET setExtendField(String str) {
-    if (TextUtils.isEmpty(str)) return (TARGET) this;
-    if (TextUtils.isEmpty(mEntity.getStr()) || !mEntity.getStr().equals(str)) {
-      mEntity.setStr(str);
-      mEntity.save();
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 获取存放的扩展字段
-   * 设置扩展字段{@link #setExtendField(String)}
-   */
-  public String getExtendField() {
-    return mEntity.getStr();
-  }
-
-  /**
-   * 获取任务状态
-   *
-   * @return {@link IEntity}
-   */
-  public int getTaskState() {
-    return mEntity.getState();
-  }
-
-  /**
-   * 获取任务进度百分比
-   *
-   * @return 返回任务进度
-   */
-  @Override public int getPercent() {
-    if (mEntity == null) {
-      Log.e("AbsTarget", "下载管理器中没有该任务");
-      return 0;
-    }
-    if (mEntity.getFileSize() != 0) {
-      return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize());
-    }
-    return 0;
-  }
-
-  /**
-   * 给url请求添加头部
-   *
-   * @param key 头部key
-   * @param header 头部value
-   */
-  public TARGET addHeader(@NonNull String key, @NonNull String header) {
-    mTaskEntity.headers.put(key, header);
-    return (TARGET) this;
-  }
-
-  /**
-   * 给url请求添加头部
-   */
-  public TARGET addHeaders(Map<String, String> headers) {
-    if (headers != null && headers.size() > 0) {
-      Set<String> keys = headers.keySet();
-      for (String key : keys) {
-        mTaskEntity.headers.put(key, headers.get(key));
-      }
-    }
-    return (TARGET) this;
-  }
-
-  /**
-   * 设置请求类型
-   *
-   * @param requestEnum {@link RequestEnum}
-   */
-  public TARGET setRequestMode(RequestEnum requestEnum) {
-    mTaskEntity.requestEnum = requestEnum;
-    return (TARGET) this;
-  }
-
-  /**
-   * 开始任务
-   */
-  @Override public void start() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
-        .exe();
-  }
-
-  /**
-   * 停止任务
-   *
-   * @see #stop()
-   */
-  @Deprecated public void pause() {
-    stop();
-  }
-
-  @Override public void stop() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP))
-        .exe();
-  }
-
-  /**
-   * 恢复任务
-   */
-  @Override public void resume() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
-        .exe();
-  }
-
-  /**
-   * 删除任务
-   */
-  @Override public void cancel() {
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL))
-        .exe();
-  }
-
-  /**
-   * 删除任务
-   *
-   * @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件
-   * {@code false}如果任务已经完成,只删除任务数据库记录,
-   */
-  public void cancel(boolean removeFile) {
-    mTaskEntity.removeFile = removeFile;
-    AriaManager.getInstance(AriaManager.APP)
-        .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL))
-        .exe();
-  }
-
-  /**
-   * 创建文件名,如果url链接有后缀名,则使用url中的后缀名
-   *
-   * @return url 的 hashKey
-   */
-  protected String createFileName(String url) {
-    int end = url.indexOf("?");
-    String tempUrl, fileName = "";
-    if (end > 0) {
-      tempUrl = url.substring(0, end);
-      int tempEnd = tempUrl.lastIndexOf("/");
-      if (tempEnd > 0) {
-        fileName = tempUrl.substring(tempEnd + 1, tempUrl.length());
-      }
-    } else {
-      int tempEnd = url.lastIndexOf("/");
-      if (tempEnd > 0) {
-        fileName = url.substring(tempEnd + 1, url.length());
-      }
-    }
-    if (TextUtils.isEmpty(fileName)) {
-      fileName = CommonUtil.keyToHashKey(url);
-    }
-    return fileName;
-  }
-}

+ 0 - 172
Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java

@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.content.Context;
-import android.os.Handler;
-import com.arialyy.aria.util.CommonUtil;
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-public abstract class AbsTask<ENTITY extends AbsEntity> implements ITask<ENTITY> {
-
-  protected ENTITY mEntity;
-  protected Handler mOutHandler;
-
-  /**
-   * 用于生成该任务对象的hash码
-   */
-  private String mTargetName;
-  protected Context mContext;
-
-  protected boolean isHeighestTask = false;
-
-  /**
-   * 任务是否完成
-   *
-   * @return {@code true} 已经完成,{@code false} 未完成
-   */
-  public boolean isComplete() {
-    return mEntity.isComplete();
-  }
-
-  /**
-   * 获取当前下载进度
-   */
-  @Override public long getCurrentProgress() {
-    return mEntity.getCurrentProgress();
-  }
-
-  /**
-   * 获取单位转换后的进度
-   *
-   * @return 如:已经下载3mb的大小,则返回{@code 3mb}
-   */
-  @Override public String getConvertCurrentProgress() {
-    if (mEntity.getCurrentProgress() == 0) {
-      return "0b";
-    }
-    return CommonUtil.formatFileSize(mEntity.getCurrentProgress());
-  }
-
-  /**
-   * 转换单位后的文件长度
-   *
-   * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb
-   */
-  @Override public String getConvertFileSize() {
-    if (mEntity.getFileSize() == 0) {
-      return "0mb";
-    }
-    return CommonUtil.formatFileSize(mEntity.getFileSize());
-  }
-
-  /**
-   * 获取文件大小
-   */
-  @Override public long getFileSize() {
-    return mEntity.getFileSize();
-  }
-
-  /**
-   * 获取百分比进度
-   *
-   * @return 返回百分比进度,如果文件长度为0,返回0
-   */
-  @Override public int getPercent() {
-    if (mEntity.getFileSize() == 0) {
-      return 0;
-    }
-    return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize());
-  }
-
-  /**
-   * 任务当前状态
-   *
-   * @return {@link IEntity}
-   */
-  public int getState() {
-    return mEntity == null ? IEntity.STATE_OTHER : mEntity.getState();
-  }
-
-  /**
-   * 获取保存的扩展字段
-   *
-   * @return 如果实体不存在,则返回null,否则返回扩展字段
-   */
-  @Override public String getExtendField() {
-    return mEntity == null ? null : mEntity.getStr();
-  }
-
-  /**
-   * @return 返回原始byte速度,需要你在配置文件中配置
-   * <pre>
-   *   {@code
-   *    <xml>
-   *      <download>
-   *        ...
-   *        <convertSpeed value="false"/>
-   *      </download>
-   *
-   *      或在代码中设置
-   *      Aria.get(this).getDownloadConfig().setConvertSpeed(false);
-   *    </xml>
-   *   }
-   * </pre>
-   * 才能生效
-   */
-  @Override public long getSpeed() {
-    return mEntity.getSpeed();
-  }
-
-  /**
-   * @return 返回转换单位后的速度,需要你在配置文件中配置,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s
-   * <pre>
-   *   {@code
-   *    <xml>
-   *      <download>
-   *        ...
-   *        <convertSpeed value="true"/>
-   *      </download>
-   *
-   *      或在代码中设置
-   *      Aria.get(this).getDownloadConfig().setConvertSpeed(true);
-   *    </xml>
-   *   }
-   * </pre>
-   * 才能生效
-   */
-  @Override public String getConvertSpeed() {
-    return mEntity.getConvertSpeed();
-  }
-
-  @Override public ENTITY getEntity() {
-    return mEntity;
-  }
-
-  public String getTargetName() {
-    return mTargetName;
-  }
-
-  @Override public void setTargetName(String targetName) {
-    this.mTargetName = targetName;
-  }
-
-  public boolean isHighestPriorityTask() {
-    return isHeighestTask;
-  }
-}

+ 0 - 130
Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java

@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import com.arialyy.aria.core.common.RequestEnum;
-import com.arialyy.aria.orm.DbEntity;
-import com.arialyy.aria.orm.Ignore;
-import com.arialyy.aria.orm.Primary;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by lyy on 2017/2/23.
- */
-public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
-  /**
-   * HTTP下载
-   */
-  public static final int HTTP = 0x11;
-  /**
-   * FTP当文件下载
-   */
-  public static final int FTP = 0x12;
-  /**
-   * FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
-   */
-  public static final int FTP_DIR = 0x13;
-
-  /**
-   * Task实体对应的key
-   */
-  @Primary public String key = "";
-
-  /**
-   * 账号和密码
-   */
-  @Ignore public String userName, userPw, account, serverIp;
-  @Ignore public int port;
-
-  /**
-   * 请求类型
-   * {@link AbsTaskEntity#HTTP}、{@link AbsTaskEntity#FTP}
-   */
-  public int requestType = HTTP;
-
-  /**
-   * http 请求头
-   */
-  public Map<String, String> headers = new HashMap<>();
-
-  /**
-   * 字符编码,默认为"utf-8"
-   */
-  public String charSet = "utf-8";
-
-  /**
-   * 网络请求类型
-   */
-  public RequestEnum requestEnum = RequestEnum.GET;
-
-  /**
-   * 从header中含有的文件md5码信息所需要的key
-   */
-  public String md5Key = "Content-MD5";
-
-  /**
-   * 从header中获取文件描述信息所需要的key
-   */
-  public String dispositionKey = "Content-Disposition";
-
-  /**
-   * 重定向后,从header中获取新url所需要的key
-   */
-  public String redirectUrlKey = "location";
-
-  /**
-   * 从Disposition获取的文件名说需要的key
-   */
-  public String dispositionFileKey = "attachment;filename";
-
-  /**
-   * 从header中含有的文件长度信息所需要的key
-   */
-  public String contentLength = "Content-Length";
-
-  /**
-   * 重定向链接
-   */
-  public String redirectUrl = "";
-
-  /**
-   * {@code true}  删除任务数据库记录,并且删除已经下载完成的文件
-   * {@code false} 如果任务已经完成,只删除任务数据库记录
-   */
-  @Ignore public boolean removeFile = false;
-
-  /**
-   * 是否支持断点, {@code true} 为支持断点
-   */
-  public boolean isSupportBP = true;
-
-  /**
-   * 状态码
-   */
-  public int code;
-
-  public abstract ENTITY getEntity();
-
-  /**
-   * 获取任务下载状态
-   *
-   * @return {@link IEntity}
-   */
-  public int getState() {
-    return getEntity().getState();
-  }
-}

+ 0 - 80
Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java

@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.support.annotation.NonNull;
-import com.arialyy.aria.core.queue.UploadTaskQueue;
-import com.arialyy.aria.core.upload.UploadEntity;
-import com.arialyy.aria.core.upload.UploadTask;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-import com.arialyy.aria.util.CheckUtil;
-import java.util.regex.Pattern;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 任务组超类
- */
-public abstract class AbsUploadTarget<TARGET extends AbsUploadTarget, ENTITY extends UploadEntity, TASK_ENTITY extends UploadTaskEntity>
-    extends AbsTarget<TARGET, ENTITY, TASK_ENTITY> {
-
-  /**
-   * 设置上传路径
-   *
-   * @param uploadUrl 上传路径
-   */
-  public TARGET setUploadUrl(@NonNull String uploadUrl) {
-    CheckUtil.checkDownloadUrl(uploadUrl);
-    if (mEntity.getUrl().equals(uploadUrl)) return (TARGET) this;
-    mEntity.setUrl(uploadUrl);
-    mEntity.update();
-    return (TARGET) this;
-  }
-
-  /**
-   * 从数据中读取上传实体,如果数据库查不到,则新创建一个上传实体
-   *
-   * @param filePath 上传文件的文件路径
-   */
-  protected UploadEntity getUploadEntity(String filePath) {
-    UploadEntity entity = UploadEntity.findFirst(UploadEntity.class, "filePath=?", filePath);
-    if (entity == null) {
-      entity = new UploadEntity();
-      String regex = "[/|\\\\|//]";
-      Pattern p = Pattern.compile(regex);
-      String[] strs = p.split(filePath);
-      String fileName = strs[strs.length - 1];
-      entity.setFileName(fileName);
-      entity.setFilePath(filePath);
-      entity.insert();
-    }
-    return entity;
-  }
-
-  /**
-   * 下载任务是否存在
-   */
-  @Override public boolean taskExists() {
-    return UploadTaskQueue.getInstance().getTask(mEntity.getFilePath()) != null;
-  }
-
-  /**
-   * 是否在下载
-   */
-  public boolean isUploading() {
-    UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity);
-    return task != null && task.isRunning();
-  }
-}

+ 0 - 35
Aria/src/main/java/com/arialyy/aria/core/inf/IDownloadListener.java

@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.inf;
-
-/**
- * 下载监听
- */
-public interface IDownloadListener extends IEventListener {
-
-  /**
-   * 预处理完成,准备下载---开始下载之间
-   */
-  void onPostPre(long fileSize);
-
-  /**
-   * 支持断点回调
-   *
-   * @param support true,支持;false 不支持
-   */
-  void supportBreakpoint(boolean support);
-}

+ 0 - 60
Aria/src/main/java/com/arialyy/aria/core/inf/IEntity.java

@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import com.arialyy.aria.orm.Ignore;
-
-/**
- * Created by lyy on 2017/2/23.
- */
-public interface IEntity {
-  /**
-   * 其它状态
-   */
-  @Ignore int STATE_OTHER = -1;
-  /**
-   * 失败状态
-   */
-  @Ignore int STATE_FAIL = 0;
-  /**
-   * 完成状态
-   */
-  @Ignore int STATE_COMPLETE = 1;
-  /**
-   * 停止状态
-   */
-  @Ignore int STATE_STOP = 2;
-  /**
-   * 等待状态
-   */
-  @Ignore int STATE_WAIT = 3;
-  /**
-   * 下载中
-   */
-  @Ignore int STATE_RUNNING = 4;
-  /**
-   * 预处理
-   */
-  @Ignore int STATE_PRE = 5;
-  /**
-   * 预处理完成
-   */
-  @Ignore int STATE_POST_PRE = 6;
-  /**
-   * 取消下载
-   */
-  @Ignore int STATE_CANCEL = 7;
-}

+ 0 - 63
Aria/src/main/java/com/arialyy/aria/core/inf/IEventListener.java

@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-/**
- * Created by Aria.Lao on 2017/7/18.
- * 基础事件
- */
-public interface IEventListener {
-
-  /**
-   * 预处理,有时有些地址链接比较慢,这时可以先在这个地方出来一些界面上的UI,如按钮的状态
-   */
-  void onPre();
-
-  /**
-   * 开始
-   */
-  void onStart(long startLocation);
-
-  /**
-   * 恢复位置
-   */
-  void onResume(long resumeLocation);
-
-  /**
-   * 下载监听
-   */
-  void onProgress(long currentLocation);
-
-  /**
-   * 停止
-   */
-  void onStop(long stopLocation);
-
-  /**
-   * 下载完成
-   */
-  void onComplete();
-
-  /**
-   * 取消下载
-   */
-  void onCancel();
-
-  /**
-   * 下载失败
-   */
-  void onFail();
-}

+ 0 - 60
Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java

@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import java.util.List;
-
-/**
- * Created by lyy on 2017/2/6.
- */
-public interface IReceiver<ENTITY extends IEntity> {
-  /**
-   * Receiver 销毁
-   */
-  void destroy();
-
-  /**
-   * 移除事件回调
-   */
-  void removeSchedulerListener();
-
-  /**
-   * 移除观察者
-   */
-  void unRegister();
-
-  /**
-   * 停止所有任务
-   */
-  void stopAllTask();
-
-  /**
-   * 删除所有任务
-   */
-  void removeAllTask(boolean removeFile);
-
-  /**
-   * 任务是否存在
-   *
-   * @param key 下载时为下载路径,上传时为文件路径
-   */
-  boolean taskExists(String key);
-
-  /**
-   * 获取任务列表
-   */
-  List<ENTITY> getSimpleTaskList();
-}

+ 0 - 86
Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java

@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import android.support.annotation.NonNull;
-import com.arialyy.aria.core.common.RequestEnum;
-import java.util.Map;
-
-/**
- * Created by AriaL on 2017/6/29.
- */
-public interface ITarget<TARGET extends ITarget> {
-  /**
-   * 任务文件大小
-   */
-  long getSize();
-
-  /**
-   * 转换后的大小
-   */
-  String getConvertSize();
-
-  /**
-   * 获取任务进度百分比
-   */
-  int getPercent();
-
-  /**
-   * 获取任务进度,如果任务存在,则返回当前进度
-   */
-  long getCurrentProgress();
-
-  /**
-   * 给url请求添加头部
-   *
-   * @param key 头部key
-   * @param header 头部value
-   */
-  TARGET addHeader(@NonNull String key, @NonNull String header) ;
-
-  /**
-   * 给url请求添加头部
-   */
-  TARGET addHeaders(Map<String, String> headers);
-
-  /**
-   * 设置请求类型
-   *
-   * @param requestEnum {@link RequestEnum}
-   */
-  TARGET setRequestMode(RequestEnum requestEnum);
-
-  /**
-   * 开始下载
-   */
-  void start();
-
-  /**
-   * 停止下载
-   */
-  void stop();
-
-  /**
-   * 恢复下载
-   */
-  void resume();
-
-  /**
-   * 取消下载
-   */
-  void cancel();
-
-}

+ 0 - 95
Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java

@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-/**
- * Created by lyy on 2017/2/13.
- */
-public interface ITask<ENTITY extends AbsEntity> {
-
-  /**
-   * 获取下载状态
-   */
-  int getState();
-
-  /**
-   * 获取扩展字段
-   */
-  String getExtendField();
-
-  /**
-   * 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径
-   */
-  String getKey();
-
-  /**
-   * 任务是否正在执行
-   *
-   * @return true,正在执行;
-   */
-  boolean isRunning();
-
-  /**
-   * 获取信息实体
-   */
-  ENTITY getEntity();
-
-  void start();
-
-  void stop();
-
-  void cancel();
-
-  /**
-   * 原始byte速度
-   */
-  long getSpeed();
-
-  /**
-   * 转换单位后的速度
-   */
-  String getConvertSpeed();
-
-  /**
-   * 获取百分比进度
-   */
-  int getPercent();
-
-  /**
-   * 原始文件byte长度
-   */
-  long getFileSize();
-
-  /**
-   * 转换单位后的文件长度
-   */
-  String getConvertFileSize();
-
-  /**
-   * 获取当前进度
-   */
-  long getCurrentProgress();
-
-  /**
-   * 获取单位转换后的进度
-   *
-   * @return 返回 3mb
-   */
-  String getConvertCurrentProgress();
-
-  void setTargetName(String targetName);
-
-}

+ 0 - 26
Aria/src/main/java/com/arialyy/aria/core/inf/IUploadListener.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.inf;
-
-import com.arialyy.aria.core.inf.IEventListener;
-
-/**
- * Created by lyy on 2017/2/9.
- * 上传监听
- */
-public interface IUploadListener extends IEventListener {
-
-}

+ 0 - 211
Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java

@@ -1,211 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.queue.pool.BaseCachePool;
-import com.arialyy.aria.core.queue.pool.BaseExecutePool;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * Created by lyy on 2017/2/23.
- * 任务队列
- */
-abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity>
-    implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> {
-  private final String TAG = "AbsTaskQueue";
-  BaseCachePool<TASK> mCachePool;
-  BaseExecutePool<TASK> mExecutePool;
-
-  AbsTaskQueue() {
-    mCachePool = setCachePool();
-    mExecutePool = setExecutePool();
-  }
-
-  abstract BaseCachePool<TASK> setCachePool();
-
-  abstract BaseExecutePool<TASK> setExecutePool();
-
-  @Override public boolean taskIsRunning(String key) {
-    return mExecutePool.getTask(key) != null;
-  }
-
-  @Override public void removeAllTask() {
-    for (String key : mExecutePool.getAllTask().keySet()) {
-      TASK task = mExecutePool.getAllTask().get(key);
-      if (task != null) task.cancel();
-    }
-    for (String key : mCachePool.getAllTask().keySet()) {
-      mCachePool.removeTask(key);
-    }
-  }
-
-  /**
-   * 停止所有任务
-   */
-  @Override public void stopAllTask() {
-    for (String key : mExecutePool.getAllTask().keySet()) {
-      TASK task = mExecutePool.getAllTask().get(key);
-      if (task != null && task.isRunning()) task.stop();
-    }
-    for (String key : mCachePool.getAllTask().keySet()) {
-      mCachePool.removeTask(key);
-    }
-  }
-
-  @Override public int getMaxTaskNum() {
-    return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
-  }
-
-  /**
-   * 获取实体的索引
-   */
-  public abstract String getKey(ENTITY entity);
-
-  /**
-   * 获取配置文件配置的最大可执行任务数
-   */
-  public abstract int getConfigMaxNum();
-
-  /**
-   * 获取任务执行池
-   */
-  public BaseExecutePool getExecutePool() {
-    return mExecutePool;
-  }
-
-  /**
-   * 获取缓存池
-   */
-  public BaseCachePool getCachePool() {
-    return mCachePool;
-  }
-
-  /**
-   * 获取缓存任务数
-   *
-   * @return 获取缓存的任务数
-   */
-  @Override public int getCurrentCachePoolNum() {
-    return mCachePool.size();
-  }
-
-  /**
-   * 获取执行池中的任务数量
-   *
-   * @return 当前正在执行的任务数
-   */
-  @Override public int getCurrentExePoolNum() {
-    return mExecutePool.size();
-  }
-
-  @Override public void setMaxTaskNum(int downloadNum) {
-    int oldMaxSize = getConfigMaxNum();
-    int diff = downloadNum - oldMaxSize;
-    if (oldMaxSize == downloadNum) {
-      Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
-      return;
-    }
-    //设置的任务数小于配置任务数
-    if (diff <= -1 && mExecutePool.size() >= oldMaxSize) {
-      for (int i = 0, len = Math.abs(diff); i < len; i++) {
-        TASK eTask = mExecutePool.pollTask();
-        if (eTask != null) {
-          stopTask(eTask);
-        }
-      }
-    }
-    mExecutePool.setMaxNum(downloadNum);
-    if (diff >= 1) {
-      for (int i = 0; i < diff; i++) {
-        TASK nextTask = getNextTask();
-        if (nextTask != null && nextTask.getState() == IEntity.STATE_WAIT) {
-          startTask(nextTask);
-        }
-      }
-    }
-  }
-
-  @Override public TASK getTask(String url) {
-    TASK task = mExecutePool.getTask(url);
-    if (task == null) {
-      task = mCachePool.getTask(url);
-    }
-    return task;
-  }
-
-  @Override public void startTask(TASK task) {
-    if (mExecutePool.putTask(task)) {
-      mCachePool.removeTask(task);
-      task.getEntity().setFailNum(0);
-      task.start();
-    }
-  }
-
-  @Override public void stopTask(TASK task) {
-    if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
-    if (mExecutePool.removeTask(task)) {
-      task.stop();
-    } else {
-      task.stop();
-      Log.w(TAG, "删除任务失败,【执行队列中没有该任务】");
-    }
-  }
-
-  @Override public void removeTask(ENTITY entity) {
-    TASK task = mExecutePool.getTask(getKey(entity));
-    if (task != null) {
-      Log.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
-    }
-    task = mCachePool.getTask(getKey(entity));
-    if (task != null) {
-      Log.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
-    }
-  }
-
-  @Override public void reTryStart(TASK task) {
-    if (task == null) {
-      Log.w(TAG, "重试下载失败,task 为null");
-      return;
-    }
-    if (!task.isRunning()) {
-      task.start();
-    } else {
-      Log.w(TAG, "任务没有完全停止,重试下载失败");
-    }
-  }
-
-  @Override public TASK getTask(ENTITY entity) {
-    return getTask(getKey(entity));
-  }
-
-  @Override public void removeTask(TASK task) {
-    task.cancel();
-  }
-
-  @Override public TASK getNextTask() {
-    return mCachePool.pollTask();
-  }
-}

+ 0 - 80
Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java

@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadGroupEntity;
-import com.arialyy.aria.core.download.DownloadGroupTask;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.queue.pool.BaseCachePool;
-import com.arialyy.aria.core.queue.pool.BaseExecutePool;
-import com.arialyy.aria.core.queue.pool.DownloadSharePool;
-import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 任务组下载队列
- */
-public class DownloadGroupTaskQueue
-    extends AbsTaskQueue<DownloadGroupTask, DownloadGroupTaskEntity, DownloadGroupEntity> {
-  private static volatile DownloadGroupTaskQueue INSTANCE = null;
-
-  private final String TAG = "DownloadGroupTaskQueue";
-
-  public static DownloadGroupTaskQueue getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new DownloadGroupTaskQueue();
-      }
-    }
-    return INSTANCE;
-  }
-
-  private DownloadGroupTaskQueue() {
-  }
-
-  @Override BaseCachePool<DownloadGroupTask> setCachePool() {
-    return DownloadSharePool.getInstance().cachePool;
-  }
-
-  @Override BaseExecutePool<DownloadGroupTask> setExecutePool() {
-    return DownloadSharePool.getInstance().executePool;
-  }
-
-  @Override public DownloadGroupTask createTask(String targetName, DownloadGroupTaskEntity entity) {
-    DownloadGroupTask task = null;
-    if (!TextUtils.isEmpty(targetName)) {
-      task = (DownloadGroupTask) TaskFactory.getInstance()
-          .createTask(targetName, entity, DownloadGroupSchedulers.getInstance());
-      entity.key = entity.getEntity().getGroupName();
-      mCachePool.putTask(task);
-    } else {
-      Log.e(TAG, "target name 为 null!!");
-    }
-    return task;
-  }
-
-  @Override public String getKey(DownloadGroupEntity entity) {
-    return entity.getGroupName();
-  }
-
-  @Override public int getConfigMaxNum() {
-    return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
-  }
-}

+ 0 - 143
Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java

@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.queue.pool.BaseCachePool;
-import com.arialyy.aria.core.queue.pool.BaseExecutePool;
-import com.arialyy.aria.core.queue.pool.DownloadSharePool;
-import com.arialyy.aria.core.scheduler.DownloadSchedulers;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Created by lyy on 2016/8/17.
- * 下载任务队列
- */
-public class DownloadTaskQueue
-    extends AbsTaskQueue<DownloadTask, DownloadTaskEntity, DownloadEntity> {
-  private static final String TAG = "DownloadTaskQueue";
-  private static volatile DownloadTaskQueue INSTANCE = null;
-
-  public static DownloadTaskQueue getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new DownloadTaskQueue();
-      }
-    }
-    return INSTANCE;
-  }
-
-  private DownloadTaskQueue() {
-  }
-
-  @Override BaseCachePool<DownloadTask> setCachePool() {
-    return DownloadSharePool.getInstance().cachePool;
-  }
-
-  @Override BaseExecutePool<DownloadTask> setExecutePool() {
-    return DownloadSharePool.getInstance().executePool;
-  }
-
-  @Override public String getKey(DownloadEntity entity) {
-    return entity.getUrl();
-  }
-
-  @Override public int getConfigMaxNum() {
-    return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
-  }
-
-  /**
-   * 设置任务为最高优先级任务
-   */
-  public void setTaskHighestPriority(DownloadTask task) {
-    task.setHighestPriority(true);
-    Map<String, DownloadTask> exeTasks = mExecutePool.getAllTask();
-    if (exeTasks != null && !exeTasks.isEmpty()) {
-      Set<String> keys = exeTasks.keySet();
-      for (String key : keys) {
-        DownloadTask temp = exeTasks.get(key);
-        if (temp != null && temp.isRunning() && temp.isHighestPriorityTask() && !temp.getKey()
-            .equals(task.getKey())) {
-          Log.e(TAG, "设置最高优先级任务失败,失败原因【任务中已经有最高优先级任务,请等待上一个最高优先级任务完成,或手动暂停该任务】");
-          task.setHighestPriority(false);
-          return;
-        }
-      }
-    }
-    int maxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
-    int currentSize = mExecutePool.size();
-    if (currentSize == 0 || currentSize < maxSize) {
-      startTask(task);
-    } else {
-      Set<DownloadTask> tempTasks = new LinkedHashSet<>();
-      for (int i = 0; i < maxSize; i++) {
-        DownloadTask oldTsk = mExecutePool.pollTask();
-        if (oldTsk != null && oldTsk.isRunning()) {
-          if (i == maxSize - 1) {
-            oldTsk.stopAndWait();
-            mCachePool.putTaskToFirst(oldTsk);
-            break;
-          }
-          tempTasks.add(oldTsk);
-        }
-      }
-      startTask(task);
-
-      for (DownloadTask temp : tempTasks) {
-        mExecutePool.putTask(temp);
-      }
-    }
-  }
-
-  /**
-   * 最大下载速度
-   */
-  public void setMaxSpeed(double maxSpeed) {
-    Map<String, DownloadTask> tasks = mExecutePool.getAllTask();
-    Set<String> keys = tasks.keySet();
-    for (String key : keys) {
-      DownloadTask task = tasks.get(key);
-      task.setMaxSpeed(maxSpeed);
-    }
-  }
-
-  @Override public DownloadTask createTask(String target, DownloadTaskEntity entity) {
-    DownloadTask task = null;
-    if (!TextUtils.isEmpty(target)) {
-      task = (DownloadTask) TaskFactory.getInstance()
-          .createTask(target, entity, DownloadSchedulers.getInstance());
-      entity.key = entity.getEntity().getDownloadPath();
-      mCachePool.putTask(task);
-    } else {
-      Log.e(TAG, "target name 为 null!!");
-    }
-
-    return task;
-  }
-
-  @Override public void stopTask(DownloadTask task) {
-    task.setHighestPriority(false);
-    super.stopTask(task);
-  }
-}

+ 0 - 143
Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java

@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import com.arialyy.aria.core.download.DownloadEntity;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsNormalTask;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.IEntity;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.upload.UploadEntity;
-import com.arialyy.aria.core.upload.UploadTask;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-
-/**
- * Created by lyy on 2016/8/16.
- * 任务功能接口
- */
-public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity> {
-
-  /**
-   * 通过key判断任务是否正在执行
-   *
-   * @param key 下载链接,或上传文件的路径
-   * @return {@code true} 任务正在运行
-   */
-  boolean taskIsRunning(String key);
-
-  /**
-   * 停止所有任务
-   */
-  void stopAllTask();
-
-  /**
-   * 删除所有任务
-   */
-  void removeAllTask();
-
-  /**
-   * 开始任务
-   *
-   * @param task {@link DownloadTask}、{@link UploadTask}
-   */
-  void startTask(TASK task);
-
-  /**
-   * 停止任务
-   *
-   * @param task {@link DownloadTask}、{@link UploadTask}
-   */
-  void stopTask(TASK task);
-
-  /**
-   * 通过任务任务实体删除任务
-   *
-   * @param task {@link DownloadTask}、{@link UploadTask}
-   */
-  void removeTask(TASK task);
-
-  /**
-   * 通过工作实体删除任务
-   *
-   * @param entity 工作实体{@link DownloadEntity}、{@link UploadEntity}
-   */
-  void removeTask(ENTITY entity);
-
-  /**
-   * 重试下载
-   *
-   * @param task {@link DownloadTask}、{@link UploadTask}
-   */
-  void reTryStart(TASK task);
-
-  /**
-   * 获取当前执行池中的任务数量
-   */
-  int getCurrentExePoolNum();
-
-  /**
-   * 获取当前任务缓存池中的任务数量
-   */
-  int getCurrentCachePoolNum();
-
-  /**
-   * 设置执行池可执行的最大任务数
-   *
-   * @param newMaxNum 最大任务数
-   */
-  void setMaxTaskNum(int newMaxNum);
-
-  /**
-   * 获取执行池可执行的最大任务数
-   */
-  int getMaxTaskNum();
-
-  /**
-   * 创建一个新的任务,创建时只是将新任务存储到缓存池
-   *
-   * @param entity 任务实体{@link DownloadTaskEntity}、{@link UploadTaskEntity}
-   * @param targetName 生成该任务的对象
-   * @return {@link DownloadTask}、{@link UploadTask}
-   */
-  TASK createTask(String targetName, TASK_ENTITY entity);
-
-  /**
-   * 通过工作实体缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
-   *
-   * @param entity 工作实体{@link DownloadEntity}、{@link UploadEntity}
-   * @return {@link DownloadTask}、{@link UploadTask}
-   */
-  TASK getTask(ENTITY entity);
-
-  /**
-   * 通过工作实体缓存池或任务池搜索下载任务,如果缓存池或任务池都没有任务,则创建新任务
-   *
-   * @param url 链接地址,如果是下载,则为下载链接,如果是上传,为文件保存路径
-   * @return {@link DownloadTask}、{@link UploadTask}
-   */
-  TASK getTask(String url);
-
-  /**
-   * 获取缓存池的下一个任务
-   *
-   * @return 下载任务 or null
-   */
-  TASK getNextTask();
-}

+ 0 - 119
Aria/src/main/java/com/arialyy/aria/core/queue/QueueControl.java

@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.queue;
-
-import android.os.Handler;
-import android.os.Message;
-import android.util.SparseArray;
-import com.arialyy.aria.core.inf.AbsEntity;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-
-/**
- * Created by Aria.Lao on 2017/8/3.
- * 队列控制器,用于处理各种命令
- */
-public class QueueControl implements Handler.Callback {
-  /**
-   * 获取任务命令
-   */
-  public static final int CMD_GET_TASK = 0xa1;
-  /**
-   * 创建任务命令
-   */
-  public static final int CMD_CREATE_TASK = 0xa2;
-  /**
-   * 启动任务命令
-   */
-  public static final int CMD_START_TASK = 0xa3;
-  /**
-   * 停止任务命令
-   */
-  public static final int CMD_STOP_TASK = 0xa4;
-  /**
-   * 删除任务命令
-   */
-  public static final int CMD_CANCEL_TASK = 0xa5;
-  /**
-   * 停止所有任务命令
-   */
-  public static final int CMD_STOP_ALL_TASK = 0xa6;
-  /**
-   * 删除所有任务命令
-   */
-  public static final int CMD_CANCEL_ALL_TASK = 0xa7;
-
-  /**
-   * 队列类型为单文件下载队列
-   */
-  public static final int TYPE_SIMPLE_DOWNLOAD_QUEUE = 0xc1;
-  /**
-   * 队列类型为任务组下载队列
-   */
-  public static final int TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE = 0xc2;
-  /**
-   * 队列类型为单文件上传队列
-   */
-  public static final int TYPE_SIMPLE_UPLOAD_QUEUE = 0xc3;
-
-  private Handler outHandler;
-  private AbsTaskQueue queue;
-
-  public QueueControl(Handler.Callback callback, int type) {
-    outHandler = new Handler(callback);
-    switch (type) {
-      case TYPE_SIMPLE_DOWNLOAD_QUEUE:
-        queue = DownloadTaskQueue.getInstance();
-        break;
-      case TYPE_SIMPLE_DOWNLOAD_GROUP_QUEUE:
-        queue = DownloadGroupTaskQueue.getInstance();
-        break;
-      case TYPE_SIMPLE_UPLOAD_QUEUE:
-        queue = UploadTaskQueue.getInstance();
-        break;
-    }
-  }
-
-  @Override public boolean handleMessage(Message msg) {
-    switch (msg.what) {
-      case CMD_GET_TASK:
-        outHandler.obtainMessage(CMD_GET_TASK, queue.getTask((AbsEntity) msg.obj)).sendToTarget();
-        break;
-      case CMD_CREATE_TASK:
-        SparseArray params = (SparseArray) msg.obj;
-        outHandler.obtainMessage(CMD_CREATE_TASK,
-            queue.createTask(String.valueOf(params.get(1)), (AbsTaskEntity) params.get(2)))
-            .sendToTarget();
-        break;
-      case CMD_START_TASK:
-        queue.startTask((AbsTask) msg.obj);
-        break;
-      case CMD_STOP_TASK:
-        queue.stopTask((AbsTask) msg.obj);
-        break;
-      case CMD_CANCEL_TASK:
-        queue.removeTask((AbsTask) msg.obj);
-        break;
-      case CMD_STOP_ALL_TASK:
-        queue.stopAllTask();
-        break;
-      case CMD_CANCEL_ALL_TASK:
-        queue.removeAllTask();
-        break;
-    }
-    return true;
-  }
-}

+ 0 - 111
Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java

@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.download.DownloadGroupTask;
-import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
-import com.arialyy.aria.core.download.DownloadTask;
-import com.arialyy.aria.core.download.DownloadTaskEntity;
-import com.arialyy.aria.core.inf.ITask;
-import com.arialyy.aria.core.inf.AbsTaskEntity;
-import com.arialyy.aria.core.scheduler.DownloadSchedulers;
-import com.arialyy.aria.core.scheduler.ISchedulers;
-import com.arialyy.aria.core.scheduler.UploadSchedulers;
-import com.arialyy.aria.core.upload.UploadTask;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-
-/**
- * Created by lyy on 2016/8/18.
- * 任务工厂
- */
-class TaskFactory {
-
-  private static volatile TaskFactory INSTANCE = null;
-
-  private TaskFactory() {
-
-  }
-
-  public static TaskFactory getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new TaskFactory();
-      }
-    }
-    return INSTANCE;
-  }
-
-  /**
-   * 创建任务
-   *
-   * @param entity 下载实体
-   * @param schedulers 对应的任务调度器
-   * @param <TASK_ENTITY> {@link DownloadTaskEntity}、{@link UploadTaskEntity}、{@link
-   * DownloadGroupTaskEntity}
-   * @param <SCHEDULER> {@link DownloadSchedulers}、{@link UploadSchedulers}
-   * @return {@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask}
-   */
-  <TASK_ENTITY extends AbsTaskEntity, SCHEDULER extends ISchedulers> ITask createTask(
-      String targetName, TASK_ENTITY entity, SCHEDULER schedulers) {
-    if (entity instanceof DownloadTaskEntity) {
-      return createDownloadTask(targetName, (DownloadTaskEntity) entity, schedulers);
-    } else if (entity instanceof UploadTaskEntity) {
-      return createUploadTask(targetName, (UploadTaskEntity) entity, schedulers);
-    } else if (entity instanceof DownloadGroupTaskEntity) {
-      return createDownloadGroupTask(targetName, (DownloadGroupTaskEntity) entity, schedulers);
-    }
-    return null;
-  }
-
-  /**
-   * 创建下载任务主任务
-   *
-   * @param entity 下载任务实体{@link DownloadGroupTask}
-   * @param schedulers {@link ISchedulers}
-   */
-  private DownloadGroupTask createDownloadGroupTask(String targetName,
-      DownloadGroupTaskEntity entity, ISchedulers schedulers) {
-    DownloadGroupTask.Builder builder = new DownloadGroupTask.Builder(targetName, entity);
-    builder.setOutHandler(schedulers);
-    return builder.build();
-  }
-
-  /**
-   * @param entity 上传任务实体{@link UploadTaskEntity}
-   * @param schedulers {@link ISchedulers}
-   */
-  private UploadTask createUploadTask(String targetName, UploadTaskEntity entity,
-      ISchedulers schedulers) {
-    UploadTask.Builder builder = new UploadTask.Builder();
-    builder.setTargetName(targetName);
-    builder.setUploadTaskEntity(entity);
-    builder.setOutHandler(schedulers);
-    return builder.build();
-  }
-
-  /**
-   * @param entity 下载任务实体{@link DownloadTaskEntity}
-   * @param schedulers {@link ISchedulers}
-   */
-  private DownloadTask createDownloadTask(String targetName, DownloadTaskEntity entity,
-      ISchedulers schedulers) {
-    DownloadTask.Builder builder = new DownloadTask.Builder(targetName, entity);
-    builder.setOutHandler(schedulers);
-    return builder.build();
-  }
-}

+ 0 - 78
Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java

@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.queue.pool.BaseCachePool;
-import com.arialyy.aria.core.queue.pool.BaseExecutePool;
-import com.arialyy.aria.core.queue.pool.UploadSharePool;
-import com.arialyy.aria.core.scheduler.UploadSchedulers;
-import com.arialyy.aria.core.upload.UploadEntity;
-import com.arialyy.aria.core.upload.UploadTask;
-import com.arialyy.aria.core.upload.UploadTaskEntity;
-
-/**
- * Created by lyy on 2017/2/27.
- * 上传任务队列
- */
-public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity, UploadEntity> {
-  private static final String TAG = "UploadTaskQueue";
-  private static volatile UploadTaskQueue INSTANCE = null;
-
-  public static UploadTaskQueue getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new UploadTaskQueue();
-      }
-    }
-    return INSTANCE;
-  }
-
-  private UploadTaskQueue() {
-  }
-
-  @Override BaseCachePool<UploadTask> setCachePool() {
-    return UploadSharePool.getInstance().cachePool;
-  }
-
-  @Override BaseExecutePool<UploadTask> setExecutePool() {
-    return UploadSharePool.getInstance().executePool;
-  }
-
-  @Override public String getKey(UploadEntity entity) {
-    return entity.getFilePath();
-  }
-
-  @Override public int getConfigMaxNum() {
-    return AriaManager.getInstance(AriaManager.APP).getUploadConfig().oldMaxTaskNum;
-  }
-
-  @Override public UploadTask createTask(String targetName, UploadTaskEntity entity) {
-    UploadTask task = null;
-    if (!TextUtils.isEmpty(targetName)) {
-      task = (UploadTask) TaskFactory.getInstance()
-          .createTask(targetName, entity, UploadSchedulers.getInstance());
-      entity.key = entity.getEntity().getFilePath();
-      mCachePool.putTask(task);
-    } else {
-      Log.e(TAG, "target name 为 null是!!");
-    }
-    return task;
-  }
-}

+ 0 - 154
Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java

@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue.pool;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.ITask;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by lyy on 2016/8/14.
- * 任务缓存池,所有下载任务最先缓存在这个池中
- */
-public class BaseCachePool<TASK extends AbsTask> implements IPool<TASK> {
-  private static final String TAG = "BaseCachePool";
-  private static final int MAX_NUM = Integer.MAX_VALUE;  //最大下载任务数
-  private static final long TIME_OUT = 1000;
-  private Map<String, TASK> mCacheMap;
-  private LinkedBlockingQueue<TASK> mCacheQueue;
-
-  BaseCachePool() {
-    mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
-    mCacheMap = new ConcurrentHashMap<>();
-  }
-
-  /**
-   * 获取被缓存的任务
-   */
-  public Map<String, TASK> getAllTask() {
-    return mCacheMap;
-  }
-
-  /**
-   * 将任务放在队首
-   */
-  public boolean putTaskToFirst(TASK task) {
-    if (mCacheQueue.isEmpty()) {
-      return putTask(task);
-    } else {
-      Set<TASK> temps = new LinkedHashSet<>();
-      temps.add(task);
-      for (int i = 0, len = size(); i < len; i++) {
-        TASK temp = pollTask();
-        temps.add(temp);
-      }
-      for (TASK t : temps) {
-        putTask(t);
-      }
-      return true;
-    }
-  }
-
-  @Override public boolean putTask(TASK task) {
-    synchronized (AriaManager.LOCK) {
-      if (task == null) {
-        Log.e(TAG, "下载任务不能为空!!");
-        return false;
-      }
-      String url = task.getKey();
-      if (mCacheQueue.contains(task)) {
-        Log.w(TAG, "队列中已经包含了该任务,任务下载链接【" + url + "】");
-        return false;
-      } else {
-        boolean s = mCacheQueue.offer(task);
-        Log.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
-        if (s) {
-          mCacheMap.put(CommonUtil.keyToHashKey(url), task);
-        }
-        return s;
-      }
-    }
-  }
-
-  @Override public TASK pollTask() {
-    synchronized (AriaManager.LOCK) {
-      try {
-        TASK task;
-        task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
-        if (task != null) {
-          String url = task.getKey();
-          mCacheMap.remove(CommonUtil.keyToHashKey(url));
-        }
-        return task;
-      } catch (InterruptedException e) {
-        e.printStackTrace();
-      }
-    }
-    return null;
-  }
-
-  @Override public TASK getTask(String downloadUrl) {
-    synchronized (AriaManager.LOCK) {
-      if (TextUtils.isEmpty(downloadUrl)) {
-        Log.e(TAG, "请传入有效的下载链接");
-        return null;
-      }
-      String key = CommonUtil.keyToHashKey(downloadUrl);
-      return mCacheMap.get(key);
-    }
-  }
-
-  @Override public boolean removeTask(TASK task) {
-    synchronized (AriaManager.LOCK) {
-      if (task == null) {
-        Log.e(TAG, "任务不能为空");
-        return false;
-      } else {
-        String key = CommonUtil.keyToHashKey(task.getKey());
-        mCacheMap.remove(key);
-        return mCacheQueue.remove(task);
-      }
-    }
-  }
-
-  @Override public boolean removeTask(String downloadUrl) {
-    synchronized (AriaManager.LOCK) {
-      if (TextUtils.isEmpty(downloadUrl)) {
-        Log.e(TAG, "请传入有效的下载链接");
-        return false;
-      }
-      String key = CommonUtil.keyToHashKey(downloadUrl);
-      TASK task = mCacheMap.get(key);
-      mCacheMap.remove(key);
-      return mCacheQueue.remove(task);
-    }
-  }
-
-  @Override public int size() {
-    return mCacheQueue.size();
-  }
-}

+ 0 - 196
Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java

@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(DownloadUtil)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue.pool;
-
-import android.text.TextUtils;
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.core.inf.ITask;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by lyy on 2016/8/15.
- * 任务执行池,所有当前下载任务都该任务池中,默认下载大小为2
- */
-public class BaseExecutePool<TASK extends AbsTask> implements IPool<TASK> {
-  private final String TAG = "BaseExecutePool";
-  final long TIME_OUT = 1000;
-  ArrayBlockingQueue<TASK> mExecuteQueue;
-  Map<String, TASK> mExecuteMap;
-  int mSize;
-
-  BaseExecutePool() {
-    mSize = getMaxSize();
-    mExecuteQueue = new ArrayBlockingQueue<>(mSize);
-    mExecuteMap = new ConcurrentHashMap<>();
-  }
-
-  /**
-   * 获取最大任务数配置
-   *
-   * @return {@link AriaManager#getDownloadConfig()} {@link AriaManager#getUploadConfig()},如果不设置,默认返回2
-   */
-  protected int getMaxSize() {
-    return 2;
-  }
-
-  /**
-   * 获取所有正在执行的任务
-   */
-  public Map<String, TASK> getAllTask() {
-    return mExecuteMap;
-  }
-
-  @Override public boolean putTask(TASK task) {
-    synchronized (AriaManager.LOCK) {
-      if (task == null) {
-        Log.e(TAG, "任务不能为空!!");
-        return false;
-      }
-      String url = task.getKey();
-      if (mExecuteQueue.contains(task)) {
-        Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】");
-        return false;
-      } else {
-        if (mExecuteQueue.size() >= mSize) {
-          if (pollFirstTask()) {
-            return putNewTask(task);
-          }
-        } else {
-          return putNewTask(task);
-        }
-      }
-    }
-    return false;
-  }
-
-  /**
-   * 设置执行队列最大任务数
-   *
-   * @param maxNum 下载数
-   */
-  public void setMaxNum(int maxNum) {
-    try {
-      ArrayBlockingQueue<TASK> temp = new ArrayBlockingQueue<>(maxNum);
-      TASK task;
-      while ((task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS)) != null) {
-        temp.offer(task);
-      }
-      mExecuteQueue = temp;
-      mSize = maxNum;
-    } catch (InterruptedException e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
-   * 添加新任务
-   *
-   * @param newTask 新任务
-   */
-  boolean putNewTask(TASK newTask) {
-    String url = newTask.getKey();
-    boolean s = mExecuteQueue.offer(newTask);
-    Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
-    if (s) {
-      mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask);
-    }
-    return s;
-  }
-
-  /**
-   * 队列满时,将移除下载队列中的第一个任务
-   */
-  boolean pollFirstTask() {
-    try {
-      TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
-      if (oldTask == null) {
-        Log.e(TAG, "移除任务失败");
-        return false;
-      }
-      oldTask.stop();
-      String key = CommonUtil.keyToHashKey(oldTask.getKey());
-      mExecuteMap.remove(key);
-    } catch (InterruptedException e) {
-      e.printStackTrace();
-      return false;
-    }
-    return true;
-  }
-
-  @Override public TASK pollTask() {
-    synchronized (AriaManager.LOCK) {
-      try {
-        TASK task;
-        task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
-        if (task != null) {
-          String url = task.getKey();
-          mExecuteMap.remove(CommonUtil.keyToHashKey(url));
-        }
-        return task;
-      } catch (InterruptedException e) {
-        e.printStackTrace();
-      }
-      return null;
-    }
-  }
-
-  @Override public TASK getTask(String downloadUrl) {
-    synchronized (AriaManager.LOCK) {
-      if (TextUtils.isEmpty(downloadUrl)) {
-        Log.e(TAG, "请传入有效的任务key");
-        return null;
-      }
-      String key = CommonUtil.keyToHashKey(downloadUrl);
-      return mExecuteMap.get(key);
-    }
-  }
-
-  @Override public boolean removeTask(TASK task) {
-    synchronized (AriaManager.LOCK) {
-      if (task == null) {
-        Log.e(TAG, "任务不能为空");
-        return false;
-      } else {
-        return removeTask(task.getKey());
-      }
-    }
-  }
-
-  @Override public boolean removeTask(String key) {
-    synchronized (AriaManager.LOCK) {
-      if (TextUtils.isEmpty(key)) {
-        Log.e(TAG, "请传入有效的任务key");
-        return false;
-      }
-      String convertKey = CommonUtil.keyToHashKey(key);
-      TASK task = mExecuteMap.get(convertKey);
-      mExecuteMap.remove(convertKey);
-      return mExecuteQueue.remove(task);
-    }
-  }
-
-  @Override public int size() {
-    return mExecuteQueue.size();
-  }
-}

+ 0 - 83
Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java

@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.queue.pool;
-
-import android.util.Log;
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsTask;
-import com.arialyy.aria.util.CommonUtil;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by AriaL on 2017/6/29.
- * 单个下载任务的执行池
- */
-class DownloadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
-  private final String TAG = "DownloadExecutePool";
-
-  @Override protected int getMaxSize() {
-    return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
-  }
-
-  @Override public boolean putTask(TASK task) {
-    synchronized (AriaManager.LOCK) {
-      if (task == null) {
-        Log.e(TAG, "任务不能为空!!");
-        return false;
-      }
-      String url = task.getKey();
-      if (mExecuteQueue.contains(task)) {
-        if (!task.isRunning()) return true;
-        Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】");
-        return false;
-      } else {
-        if (mExecuteQueue.size() >= mSize) {
-          Set<String> keys = mExecuteMap.keySet();
-          for (String key : keys) {
-            if (mExecuteMap.get(key).isHighestPriorityTask()) return false;
-          }
-          if (pollFirstTask()) {
-            return putNewTask(task);
-          }
-        } else {
-          return putNewTask(task);
-        }
-      }
-    }
-    return false;
-  }
-
-  @Override boolean pollFirstTask() {
-    try {
-      TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
-      if (oldTask == null) {
-        Log.e(TAG, "移除任务失败");
-        return false;
-      }
-      if (oldTask.isHighestPriorityTask()) {
-        return false;
-      }
-      oldTask.stop();
-      String key = CommonUtil.keyToHashKey(oldTask.getKey());
-      mExecuteMap.remove(key);
-    } catch (InterruptedException e) {
-      e.printStackTrace();
-      return false;
-    }
-    return true;
-  }
-}

+ 0 - 43
Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadSharePool.java

@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.queue.pool;
-
-import com.arialyy.aria.core.AriaManager;
-
-/**
- * Created by Aria.Lao on 2017/7/17.
- * 下载任务池,该池子为简单任务和任务组共用
- */
-public class DownloadSharePool {
-  private static volatile DownloadSharePool INSTANCE;
-
-  public DownloadExecutePool executePool;
-  public BaseCachePool cachePool;
-
-  private DownloadSharePool() {
-    executePool = new DownloadExecutePool<>();
-    cachePool = new BaseCachePool<>();
-  }
-
-  public static DownloadSharePool getInstance() {
-    if (INSTANCE == null) {
-      synchronized (AriaManager.LOCK) {
-        INSTANCE = new DownloadSharePool();
-      }
-    }
-    return INSTANCE;
-  }
-}

+ 0 - 68
Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java

@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.arialyy.aria.core.queue.pool;
-
-import com.arialyy.aria.core.inf.AbsTask;
-
-/**
- * Created by lyy on 2016/8/14.
- * 任务池
- */
-interface IPool<T extends AbsTask> {
-  /**
-   * 将下载任务添加到任务池中
-   */
-  boolean putTask(T task);
-
-  /**
-   * 按照队列原则取出下载任务
-   *
-   * @return 返回null或者下载任务
-   */
-  T pollTask();
-
-  /**
-   * 通过下载链接获取下载任务,当任务不为空时,队列将删除该下载任务
-   *
-   * @param downloadUrl 下载链接
-   * @return 返回null或者下载任务
-   */
-  T getTask(String downloadUrl);
-
-  /**
-   * 删除任务池中的下载任务
-   *
-   * @param task 下载任务
-   * @return true:移除成功
-   */
-  boolean removeTask(T task);
-
-  /**
-   * 通过key除下载任务
-   *
-   * @param key 下载链接
-   * @return true:移除成功
-   */
-  boolean removeTask(String key);
-
-  /**
-   * 池子大小
-   *
-   * @return 返回缓存池或者执行池大小
-   */
-  int size();
-}

+ 0 - 28
Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java

@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.arialyy.aria.core.queue.pool;
-
-import com.arialyy.aria.core.AriaManager;
-import com.arialyy.aria.core.inf.AbsTask;
-
-/**
- * Created by Aria.Lao on 2017/7/17.
- */
-public class UploadExecutePool<TASK extends AbsTask> extends BaseExecutePool<TASK> {
-  @Override protected int getMaxSize() {
-    return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
-  }
-}

+ 0 - 0
Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadSharePool.java


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff