refactor(download): 重构下载模块代码格式和逻辑实现
- 格式化 ChildHandleDialog 类代码缩进和空行 - 优化 ChildHandleDialog 中的 onClick 方法使用 if-else 替代 switch - 格式化 M3U8LiveDLoadActivity 类代码缩进和空行 - 优化 M3U8LiveDLoadActivity 中的菜单点击事件处理逻辑 - 格式化 M3U8VodDLoadActivity 类代码缩进和空行 - 添加必要的 import 语句和空行分隔 - 统一代码风格和提高可读性
This commit is contained in:
@@ -1,57 +1,76 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.lyy.frame"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
dataBinding true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
dataBinding {
|
||||
enabled = true
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
testImplementation 'junit:junit:4.12'
|
||||
api "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}"
|
||||
api 'com.google.code.gson:gson:2.8.2'
|
||||
api 'io.reactivex:rxandroid:1.2.0'
|
||||
api 'io.reactivex:rxjava:1.1.5'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0'
|
||||
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
api 'androidx.lifecycle:lifecycle-runtime:2.0.0'
|
||||
api 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0'
|
||||
api "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}"
|
||||
api 'com.google.code.gson:gson:2.8.2'
|
||||
api 'io.reactivex:rxandroid:1.2.0'
|
||||
api 'io.reactivex:rxjava:1.1.5'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0'
|
||||
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
|
||||
api 'androidx.lifecycle:lifecycle-runtime:2.0.0'
|
||||
api 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0'
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +1,51 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.arialyy.aria"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
}
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testImplementation 'junit:junit:4.12'
|
||||
// implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}"
|
||||
api project(path: ':AriaAnnotations')
|
||||
api project(path: ':PublicComponent')
|
||||
api project(path: ':HttpComponent')
|
||||
api project(path: ':AriaAnnotations')
|
||||
api project(path: ':PublicComponent')
|
||||
api project(path: ':HttpComponent')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'core'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'core'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,19 +1,19 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'annotations'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'annotations'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,22 +1,22 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.google.auto:auto-common:0.10'
|
||||
implementation 'com.google.auto.service:auto-service:1.0-rc6'
|
||||
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'
|
||||
implementation 'com.squareup:javapoet:1.9.0'
|
||||
implementation project(':AriaAnnotations')
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.google.auto:auto-common:0.10'
|
||||
implementation 'com.google.auto.service:auto-service:1.0-rc6'
|
||||
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'
|
||||
implementation 'com.squareup:javapoet:1.9.0'
|
||||
implementation project(':AriaAnnotations')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'compiler'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'compiler'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,42 +1,50 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.example.ariaftpcomponent"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation project(path: ':PublicComponent')
|
||||
implementation project(path: ':PublicComponent')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'ftp'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'ftp'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,41 +1,50 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.arialyy.aria.http"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation project(path: ':PublicComponent')
|
||||
implementation project(path: ':PublicComponent')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'http'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'http'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,2 +1 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.arialyy.aria.http" />
|
||||
<manifest package="com.arialyy.aria.http" />
|
||||
|
||||
@@ -1,43 +1,52 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.arialyy.aria.m3u8"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation project(path: ':HttpComponent')
|
||||
implementation project(path: ':PublicComponent')
|
||||
implementation project(path: ':HttpComponent')
|
||||
implementation project(path: ':PublicComponent')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'm3u8'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'm3u8'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,2 +1 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.arialyy.aria.m3u8" />
|
||||
<manifest package="com.arialyy.aria.m3u8" />
|
||||
|
||||
@@ -1,42 +1,50 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.arialyy.aria.publiccomponent"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'public'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'public'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,44 +1,53 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
namespace "com.arialyy.aria.sftp"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode rootProject.ext.versionCode
|
||||
versionName rootProject.ext.versionName
|
||||
|
||||
buildTypes {
|
||||
debug{
|
||||
debuggable true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
debuggable true
|
||||
}
|
||||
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
api "com.jcraft:jsch:0.1.55"
|
||||
api "com.jcraft:jzlib:1.1.3"
|
||||
implementation project(path: ':PublicComponent')
|
||||
api "com.jcraft:jsch:0.1.55"
|
||||
api "com.jcraft:jzlib:1.1.3"
|
||||
implementation project(path: ':PublicComponent')
|
||||
}
|
||||
|
||||
//apply from: 'bintray-release.gradle'
|
||||
ext{
|
||||
PUBLISH_ARTIFACT_ID = 'sftp'
|
||||
ext {
|
||||
PUBLISH_ARTIFACT_ID = 'sftp'
|
||||
}
|
||||
apply from: '../gradle/mavenCentral-release.gradle'
|
||||
@@ -1,2 +1 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.arialyy.aria.sftp" />
|
||||
<manifest package="com.arialyy.aria.sftp" />
|
||||
|
||||
@@ -5,13 +5,17 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "com.arialyy.simple"
|
||||
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.arialyy.simple"
|
||||
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
multiDexEnabled true
|
||||
@@ -20,6 +24,25 @@ android {
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
dataBinding true
|
||||
buildConfig true
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile file("lyy.keystore")
|
||||
@@ -35,6 +58,7 @@ android {
|
||||
debuggable true
|
||||
minifyEnabled false //混淆
|
||||
}
|
||||
|
||||
release {
|
||||
zipAlignEnabled true
|
||||
minifyEnabled true
|
||||
@@ -43,18 +67,11 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
dataBinding {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||
merge 'META-INF/services/com.arialyy.aria.core.inf.IUtil'
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -65,16 +82,18 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
|
||||
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
|
||||
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}"
|
||||
api 'com.github.PhilJay:MPAndroidChart:v3.0.3'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
implementation 'com.pddstudio:highlightjs-android:1.5.0'
|
||||
implementation 'org.greenrobot:eventbus:3.1.1'
|
||||
implementation project(':AppFrame')
|
||||
|
||||
implementation project(':AppFrame')
|
||||
// aria
|
||||
kapt project(':AriaCompiler')
|
||||
implementation project(':Aria')
|
||||
|
||||
@@ -1,72 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:sharedUserId="com.arialyy"
|
||||
package="com.arialyy.simple">
|
||||
package="com.arialyy.simple"
|
||||
android:sharedUserId="com.arialyy">
|
||||
|
||||
<application
|
||||
android:name="com.arialyy.simple.base.BaseApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<!--android:name=".test.TestFTPDirActivity"-->
|
||||
<!--android:name=".test.TestFTPActivity"-->
|
||||
<!--android:name=".download.group.DownloadGroupActivity"-->
|
||||
<!--android:name=".MainActivity"-->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<activity android:name=".core.download.fragment.MultiFragmentActivity"/>
|
||||
<activity android:name=".core.upload.SFtpUploadActivity" />
|
||||
<activity android:name=".core.download.SFtpDownloadActivity" />
|
||||
<activity android:name=".core.download.DownloadActivity" />
|
||||
<activity android:name=".core.download.SingleTaskActivity" />
|
||||
<activity android:name=".core.download.mutil.MultiTaskListActivity" />
|
||||
<activity android:name=".core.download.fragment.FragmentActivity" />
|
||||
<activity android:name=".core.download.mutil.MultiDownloadActivity" />
|
||||
<activity android:name=".core.download.HighestPriorityActivity" />
|
||||
<activity android:name=".core.download.group.DownloadGroupActivity" />
|
||||
<activity android:name=".core.download.FtpDownloadActivity" />
|
||||
<activity android:name=".core.download.group.FTPDirDownloadActivity" />
|
||||
<activity android:name=".core.upload.HttpUploadActivity" />
|
||||
<activity android:name=".core.upload.FtpUploadActivity" />
|
||||
<activity android:name=".core.download.KotlinDownloadActivity" />
|
||||
<activity android:name=".core.download.ComponentActivity" />
|
||||
<activity
|
||||
android:name=".core.FullScreenCodeActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/FullScreen"
|
||||
android:windowSoftInputMode="stateHidden|adjustResize" />
|
||||
<activity android:name=".core.download.m3u8.M3U8VodDLoadActivity" />
|
||||
<activity android:name=".core.download.m3u8.M3U8LiveDLoadActivity" />
|
||||
<application
|
||||
android:name="com.arialyy.simple.base.BaseApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<!--android:name=".test.TestFTPDirActivity"-->
|
||||
<!--android:name=".test.TestFTPActivity"-->
|
||||
<!--android:name=".download.group.DownloadGroupActivity"-->
|
||||
<!--android:name=".MainActivity"-->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/aria_fileprovider_paths" />
|
||||
</provider>
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".core.download.service.DownloadService" />
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<activity android:name=".core.download.fragment.MultiFragmentActivity" />
|
||||
<activity android:name=".core.upload.SFtpUploadActivity" />
|
||||
<activity android:name=".core.download.SFtpDownloadActivity" />
|
||||
<activity android:name=".core.download.DownloadActivity" />
|
||||
<activity android:name=".core.download.SingleTaskActivity" />
|
||||
<activity android:name=".core.download.mutil.MultiTaskListActivity" />
|
||||
<activity android:name=".core.download.fragment.FragmentActivity" />
|
||||
<activity android:name=".core.download.mutil.MultiDownloadActivity" />
|
||||
<activity android:name=".core.download.HighestPriorityActivity" />
|
||||
<activity android:name=".core.download.group.DownloadGroupActivity" />
|
||||
<activity android:name=".core.download.FtpDownloadActivity" />
|
||||
<activity android:name=".core.download.group.FTPDirDownloadActivity" />
|
||||
<activity android:name=".core.upload.HttpUploadActivity" />
|
||||
<activity android:name=".core.upload.FtpUploadActivity" />
|
||||
<activity android:name=".core.download.KotlinDownloadActivity" />
|
||||
<activity android:name=".core.download.ComponentActivity" />
|
||||
<activity
|
||||
android:name=".core.FullScreenCodeActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@style/FullScreen"
|
||||
android:windowSoftInputMode="stateHidden|adjustResize" />
|
||||
<activity android:name=".core.download.m3u8.M3U8VodDLoadActivity" />
|
||||
<activity android:name=".core.download.m3u8.M3U8LiveDLoadActivity" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/aria_fileprovider_paths" />
|
||||
</provider>
|
||||
|
||||
<service
|
||||
android:name=".core.download.service.DownloadService"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -3,69 +3,69 @@ package com.arialyy.simple;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityDbTestBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DbTestActivity extends BaseActivity<ActivityDbTestBinding> {
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_db_test;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.insert:
|
||||
insertManyRecord(10000);
|
||||
break;
|
||||
case R.id.search:
|
||||
break;
|
||||
case R.id.search_all:
|
||||
searchAll();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void searchAll() {
|
||||
long startT = System.currentTimeMillis();
|
||||
//List<DTaskWrapper> data = DownloadEntity.findRelationData(DownloadEntity.class);
|
||||
|
||||
long endT = System.currentTimeMillis();
|
||||
Log.d(TAG, "search_time=" + (endT - startT));
|
||||
}
|
||||
|
||||
private void insertManyRecord(int len) {
|
||||
long startT = System.currentTimeMillis();
|
||||
List<DbEntity> datas = new ArrayList<>();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String key = UUID.randomUUID().toString();
|
||||
String url = "https://blog.csdn.net/carefree31441/article/details/3998553";
|
||||
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setUrl(url);
|
||||
entity.setFileName("ssssssssssssssssss");
|
||||
entity.setFilePath(key);
|
||||
|
||||
DTaskWrapper dte = new DTaskWrapper(entity);
|
||||
|
||||
datas.add(entity);
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_db_test;
|
||||
}
|
||||
|
||||
//AbsEntity.insertManyData(DownloadEntity.class, datas);
|
||||
AbsEntity.saveAll(datas);
|
||||
long endT = System.currentTimeMillis();
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
|
||||
Log.d(TAG, "insert_time=" + (endT - startT));
|
||||
}
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.insert) {
|
||||
insertManyRecord(10000);
|
||||
} else if (id == R.id.search) {
|
||||
|
||||
} else if (id == R.id.search_all) {
|
||||
searchAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void searchAll() {
|
||||
long startT = System.currentTimeMillis();
|
||||
//List<DTaskWrapper> data = DownloadEntity.findRelationData(DownloadEntity.class);
|
||||
|
||||
long endT = System.currentTimeMillis();
|
||||
Log.d(TAG, "search_time=" + (endT - startT));
|
||||
}
|
||||
|
||||
private void insertManyRecord(int len) {
|
||||
long startT = System.currentTimeMillis();
|
||||
List<DbEntity> datas = new ArrayList<>();
|
||||
for (int i = 0; i < len; i++) {
|
||||
String key = UUID.randomUUID().toString();
|
||||
String url = "https://blog.csdn.net/carefree31441/article/details/3998553";
|
||||
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setUrl(url);
|
||||
entity.setFileName("ssssssssssssssssss");
|
||||
entity.setFilePath(key);
|
||||
|
||||
DTaskWrapper dte = new DTaskWrapper(entity);
|
||||
|
||||
datas.add(entity);
|
||||
}
|
||||
|
||||
//AbsEntity.insertManyData(DownloadEntity.class, datas);
|
||||
AbsEntity.saveAll(datas);
|
||||
long endT = System.currentTimeMillis();
|
||||
|
||||
Log.d(TAG, "insert_time=" + (endT - startT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.os.Environment;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -34,95 +35,98 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
* Created by AriaL on 2017/1/2.
|
||||
*/
|
||||
public class DownloadDialog extends AbsDialog implements View.OnClickListener {
|
||||
private HorizontalProgressBarWithNumber mPb;
|
||||
private Button mStart;
|
||||
private Button mCancel;
|
||||
private TextView mSize;
|
||||
private TextView mSpeed;
|
||||
private long mTaskId = -1;
|
||||
private HorizontalProgressBarWithNumber mPb;
|
||||
private Button mStart;
|
||||
private Button mCancel;
|
||||
private TextView mSize;
|
||||
private TextView mSpeed;
|
||||
private long mTaskId = -1;
|
||||
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://sdkdown.muzhiwan.com/openfile/2019/07/12/com.nswj.acing.mzw_5d283abee9a3c.apk";
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://sdkdown.muzhiwan.com/openfile/2019/07/12/com.nswj.acing.mzw_5d283abee9a3c.apk";
|
||||
|
||||
public DownloadDialog(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.dialog_download;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Aria.download(this).register();
|
||||
mPb = findViewById(R.id.progressBar);
|
||||
mStart = findViewById(R.id.start);
|
||||
mCancel = findViewById(R.id.cancel);
|
||||
mSize = findViewById(R.id.size);
|
||||
mSpeed = findViewById(R.id.speed);
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
int state = entity.getState();
|
||||
mTaskId = entity.getId();
|
||||
public DownloadDialog(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
mStart.setOnClickListener(this);
|
||||
mCancel.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
if (mTaskId == -1) {
|
||||
mTaskId = Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/女神危机.apk")
|
||||
.create();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
break;
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.dialog_download;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Aria.download(this).register();
|
||||
mPb = findViewById(R.id.progressBar);
|
||||
mStart = findViewById(R.id.start);
|
||||
mCancel = findViewById(R.id.cancel);
|
||||
mSize = findViewById(R.id.size);
|
||||
mSpeed = findViewById(R.id.speed);
|
||||
DownloadEntity entity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
int state = entity.getState();
|
||||
mTaskId = entity.getId();
|
||||
}
|
||||
if (Aria.download(this).load(mTaskId).isRunning()) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
mStart.setText(getContext().getString(R.string.resume));
|
||||
} else {
|
||||
Aria.download(this).load(mTaskId).resume();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
mStart.setOnClickListener(this);
|
||||
mCancel.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {
|
||||
if (mTaskId == -1) {
|
||||
mTaskId = Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/女神危机.apk")
|
||||
.create();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
return;
|
||||
}
|
||||
if (Aria.download(this).load(mTaskId).isRunning()) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
mStart.setText(getContext().getString(R.string.resume));
|
||||
} else {
|
||||
Aria.download(this).load(mTaskId).resume();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
}
|
||||
} else if (id == R.id.cancel) {
|
||||
Aria.download(this).load(mTaskId).cancel();
|
||||
mTaskId = -1;
|
||||
mStart.setText(getContext().getString(R.string.start));
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(mTaskId).cancel();
|
||||
mTaskId = -1;
|
||||
mStart.setText(getContext().getString(R.string.start));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
}
|
||||
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
@Download.onTaskPre
|
||||
public void onTaskPre(DownloadTask task) {
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object obj) {
|
||||
@Download.onTaskStop
|
||||
public void onTaskStop(DownloadTask task) {
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
}
|
||||
@Download.onTaskCancel
|
||||
public void onTaskCancel(DownloadTask task) {
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dataCallback(int result, Object obj) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -19,110 +20,119 @@ import com.arialyy.simple.util.AppUtil;
|
||||
/**
|
||||
* Created by lyy on 2017/8/8.
|
||||
*/
|
||||
@SuppressLint("ValidFragment") public class DownloadDialogFragment
|
||||
extends BaseDialog<DialogFragmentDownloadBinding> implements View.OnClickListener {
|
||||
@SuppressLint("ValidFragment")
|
||||
public class DownloadDialogFragment
|
||||
extends BaseDialog<DialogFragmentDownloadBinding> implements View.OnClickListener {
|
||||
|
||||
private DownloadEntity mEntity;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://res3.d.cn/android/new/game/2/78702/fzjh_1499390260312.apk?f=web_1";
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://res3.d.cn/android/new/game/2/78702/fzjh_1499390260312.apk?f=web_1";
|
||||
|
||||
protected DownloadDialogFragment(Object obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
if (mEntity != null) {
|
||||
if (mEntity.getState() == IEntity.STATE_RUNNING) {
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
} else {
|
||||
getBinding().setStateStr(getString(R.string.resume));
|
||||
}
|
||||
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(mEntity.getFileSize()));
|
||||
getBinding().setProgress((int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));
|
||||
protected DownloadDialogFragment(Object obj) {
|
||||
super(obj);
|
||||
}
|
||||
mRootView.findViewById(R.id.start).setOnClickListener(this);
|
||||
mRootView.findViewById(R.id.cancel).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.dialog_fragment_download;
|
||||
}
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
if (mEntity != null) {
|
||||
if (mEntity.getState() == IEntity.STATE_RUNNING) {
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
} else {
|
||||
getBinding().setStateStr(getString(R.string.resume));
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
@Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskStart(DOWNLOAD_URL) void taskStart(DownloadTask task) {
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning(DOWNLOAD_URL) protected void running(DownloadTask task) {
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
getBinding().setProgress(0);
|
||||
} else {
|
||||
getBinding().setProgress(task.getPercent());
|
||||
}
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskResume(DOWNLOAD_URL) void taskResume(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskStop(DOWNLOAD_URL) void taskStop(DownloadTask task) {
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
@Download.onTaskCancel(DOWNLOAD_URL) void taskCancel(DownloadTask task) {
|
||||
getBinding().setProgress(0);
|
||||
Toast.makeText(getContext(), "取消下载", Toast.LENGTH_SHORT).show();
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
@Download.onTaskFail(DOWNLOAD_URL) void taskFail(DownloadTask task) {
|
||||
Toast.makeText(getContext(), "下载失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Download.onTaskComplete(DOWNLOAD_URL) void taskComplete(DownloadTask task) {
|
||||
getBinding().setProgress(100);
|
||||
Toast.makeText(getContext(), "下载完成", Toast.LENGTH_SHORT).show();
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
if (!AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.create();
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
break;
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(mEntity.getFileSize()));
|
||||
getBinding().setProgress((int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()));
|
||||
}
|
||||
if (Aria.download(this).load(mEntity.getId()).isRunning()) {
|
||||
Aria.download(this).load(mEntity.getId()).stop();
|
||||
getBinding().setStateStr(getString(R.string.resume));
|
||||
mRootView.findViewById(R.id.start).setOnClickListener(this);
|
||||
mRootView.findViewById(R.id.cancel).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.dialog_fragment_download;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
@Download.onPre(DOWNLOAD_URL)
|
||||
protected void onPre(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskStart(DOWNLOAD_URL)
|
||||
void taskStart(DownloadTask task) {
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning(DOWNLOAD_URL)
|
||||
protected void running(DownloadTask task) {
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
getBinding().setProgress(0);
|
||||
} else {
|
||||
Aria.download(this).load(mEntity.getId()).resume();
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
getBinding().setProgress(task.getPercent());
|
||||
}
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskResume(DOWNLOAD_URL)
|
||||
void taskResume(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskStop(DOWNLOAD_URL)
|
||||
void taskStop(DownloadTask task) {
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
@Download.onTaskCancel(DOWNLOAD_URL)
|
||||
void taskCancel(DownloadTask task) {
|
||||
getBinding().setProgress(0);
|
||||
Toast.makeText(getContext(), "取消下载", Toast.LENGTH_SHORT).show();
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
@Download.onTaskFail(DOWNLOAD_URL)
|
||||
void taskFail(DownloadTask task) {
|
||||
Toast.makeText(getContext(), "下载失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Download.onTaskComplete(DOWNLOAD_URL)
|
||||
void taskComplete(DownloadTask task) {
|
||||
getBinding().setProgress(100);
|
||||
Toast.makeText(getContext(), "下载完成", Toast.LENGTH_SHORT).show();
|
||||
getBinding().setSpeed("");
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {
|
||||
if (!AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.create();
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
return;
|
||||
}
|
||||
if (Aria.download(this).load(mEntity.getId()).isRunning()) {
|
||||
Aria.download(this).load(mEntity.getId()).stop();
|
||||
getBinding().setStateStr(getString(R.string.resume));
|
||||
} else {
|
||||
Aria.download(this).load(mEntity.getId()).resume();
|
||||
getBinding().setStateStr(getString(R.string.stop));
|
||||
}
|
||||
} else if (id == R.id.cancel) {
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).cancel();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.cancel:
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).cancel();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.Environment;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -84,32 +85,28 @@ public class DownloadPopupWindow extends AbsPopupWindow implements View.OnClickL
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
if (mTaskId != -1) {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.create();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
break;
|
||||
}
|
||||
if (Aria.download(this).load(mTaskId).isRunning()) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
mStart.setText(getContext().getString(R.string.resume));
|
||||
} else {
|
||||
Aria.download(this).load(mTaskId).resume();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.cancel:
|
||||
|
||||
Aria.download(this).load(mTaskId).cancel();
|
||||
mStart.setText(getContext().getResources().getString(R.string.start));
|
||||
mTaskId = -1;
|
||||
break;
|
||||
}
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {
|
||||
if (mTaskId != -1) {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.create();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
return;
|
||||
}
|
||||
if (Aria.download(this).load(mTaskId).isRunning()) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
mStart.setText(getContext().getString(R.string.resume));
|
||||
} else {
|
||||
Aria.download(this).load(mTaskId).resume();
|
||||
mStart.setText(getContext().getString(R.string.stop));
|
||||
}
|
||||
} else if (id == R.id.cancel) {
|
||||
Aria.download(this).load(mTaskId).cancel();
|
||||
mStart.setText(getContext().getResources().getString(R.string.start));
|
||||
mTaskId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object obj) {
|
||||
|
||||
@@ -21,8 +21,10 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
@@ -36,6 +38,7 @@ import com.arialyy.simple.core.download.mutil.DownloadAdapter;
|
||||
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
|
||||
import com.arialyy.simple.util.AppUtil;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -46,204 +49,212 @@ import java.util.Set;
|
||||
* 最高优先级任务Demo
|
||||
*/
|
||||
public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorityBinding> {
|
||||
private HorizontalProgressBarWithNumber mPb;
|
||||
private Button mStart;
|
||||
private Button mStop;
|
||||
private Button mCancel;
|
||||
private TextView mSize;
|
||||
private TextView mSpeed;
|
||||
private RecyclerView mList;
|
||||
private DownloadEntity mEntity;
|
||||
private HorizontalProgressBarWithNumber mPb;
|
||||
private Button mStart;
|
||||
private Button mStop;
|
||||
private Button mCancel;
|
||||
private TextView mSize;
|
||||
private TextView mSpeed;
|
||||
private RecyclerView mList;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
private String mTaskName = "光明大陆";
|
||||
private static final String DOWNLOAD_URL =
|
||||
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
|
||||
private DownloadAdapter mAdapter;
|
||||
private List<AbsEntity> mData = new ArrayList<>();
|
||||
private Set<String> mRecord = new HashSet<>();
|
||||
private String mTaskName = "光明大陆";
|
||||
private static final String DOWNLOAD_URL =
|
||||
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
|
||||
private DownloadAdapter mAdapter;
|
||||
private List<AbsEntity> mData = new ArrayList<>();
|
||||
private Set<String> mRecord = new HashSet<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_highest_priority;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mPb = findViewById(R.id.progressBar);
|
||||
mStart = findViewById(R.id.start);
|
||||
mStop = findViewById(R.id.stop);
|
||||
mCancel = findViewById(R.id.cancel);
|
||||
mSize = findViewById(R.id.size);
|
||||
mSpeed = findViewById(R.id.speed);
|
||||
mList = findViewById(R.id.list);
|
||||
|
||||
setTitle("最高优先级任务");
|
||||
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
|
||||
initWidget();
|
||||
Aria.download(this).register();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress(mEntity.getPercent());
|
||||
if (mEntity.getState() == IEntity.STATE_STOP) {
|
||||
mStart.setText("恢复");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||
setBtState(true);
|
||||
} else if (mEntity.getState() == IEntity.STATE_RUNNING) {
|
||||
setBtState(false);
|
||||
}
|
||||
mSize.setText(mEntity.getConvertFileSize());
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_highest_priority;
|
||||
}
|
||||
|
||||
List<DownloadEntity> temp = Aria.download(this).getTaskList();
|
||||
if (temp != null && !temp.isEmpty()) {
|
||||
for (DownloadEntity entity : temp) {
|
||||
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
|
||||
mData.add(entity);
|
||||
mRecord.add(entity.getUrl());
|
||||
}
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mPb = findViewById(R.id.progressBar);
|
||||
mStart = findViewById(R.id.start);
|
||||
mStop = findViewById(R.id.stop);
|
||||
mCancel = findViewById(R.id.cancel);
|
||||
mSize = findViewById(R.id.size);
|
||||
mSpeed = findViewById(R.id.speed);
|
||||
mList = findViewById(R.id.list);
|
||||
|
||||
setTitle("最高优先级任务");
|
||||
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
|
||||
initWidget();
|
||||
Aria.download(this).register();
|
||||
}
|
||||
mAdapter = new DownloadAdapter(this, mData);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
private void initWidget() {
|
||||
mEntity = Aria.download(this).getFirstDownloadEntity(DOWNLOAD_URL);
|
||||
|
||||
@Override public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.add_task:
|
||||
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
|
||||
for (DownloadEntity entity : temp) {
|
||||
String url = entity.getUrl();
|
||||
if (mRecord.contains(url)) {
|
||||
continue;
|
||||
}
|
||||
mAdapter.addDownloadEntity(entity);
|
||||
mRecord.add(url);
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress(mEntity.getPercent());
|
||||
if (mEntity.getState() == IEntity.STATE_STOP) {
|
||||
mStart.setText("恢复");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||
setBtState(true);
|
||||
} else if (mEntity.getState() == IEntity.STATE_RUNNING) {
|
||||
setBtState(false);
|
||||
}
|
||||
mSize.setText(mEntity.getConvertFileSize());
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
case R.id.help:
|
||||
String title = "最高优先级任务介绍";
|
||||
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
|
||||
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
|
||||
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
|
||||
+ " 3、任务调度器不会暂停最高优先级任务\n"
|
||||
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
|
||||
+ " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n"
|
||||
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
|
||||
showMsgDialog(title, msg);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
} else {
|
||||
Aria.download(this).load(mEntity.getId()).resume();
|
||||
}
|
||||
List<DownloadEntity> temp = Aria.download(this).getTaskList();
|
||||
if (temp != null && !temp.isEmpty()) {
|
||||
for (DownloadEntity entity : temp) {
|
||||
if (entity.getUrl().equals(DOWNLOAD_URL)) continue;
|
||||
mData.add(entity);
|
||||
mRecord.add(entity.getUrl());
|
||||
}
|
||||
}
|
||||
((TextView) view).setText(getString(R.string.stop));
|
||||
break;
|
||||
case R.id.stop:
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).stop();
|
||||
mAdapter = new DownloadAdapter(this, mData);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.add_task) {
|
||||
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
|
||||
for (DownloadEntity entity : temp) {
|
||||
String url = entity.getUrl();
|
||||
if (mRecord.contains(url)) {
|
||||
continue;
|
||||
}
|
||||
mAdapter.addDownloadEntity(entity);
|
||||
mRecord.add(url);
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
} else if (itemId == R.id.help) {
|
||||
String title = "最高优先级任务介绍";
|
||||
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
|
||||
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
|
||||
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
|
||||
+ " 3、任务调度器不会暂停最高优先级任务\n"
|
||||
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
|
||||
+ " 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行\n"
|
||||
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
|
||||
showMsgDialog(title, msg);
|
||||
}
|
||||
((TextView) view).setText(getString(R.string.resume));
|
||||
break;
|
||||
case R.id.cancel:
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
} else {
|
||||
Aria.download(this).load(mEntity.getId()).resume();
|
||||
}
|
||||
}
|
||||
((TextView) view).setText(getString(R.string.stop));
|
||||
} else if (id == R.id.stop) {
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).stop();
|
||||
}
|
||||
((TextView) view).setText(getString(R.string.resume));
|
||||
} else if (id == R.id.cancel) {
|
||||
if (AppUtil.chekEntityValid(mEntity)) {
|
||||
Aria.download(this).load(mEntity.getId()).cancel();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置start 和 stop 按钮状态
|
||||
*/
|
||||
private void setBtState(boolean state) {
|
||||
mStart.setEnabled(state);
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
|
||||
@Download.onPre public void onPre(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mSize.setText(task.getConvertFileSize());
|
||||
/**
|
||||
* 设置start 和 stop 按钮状态
|
||||
*/
|
||||
private void setBtState(boolean state) {
|
||||
mStart.setEnabled(state);
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
@Download.onPre
|
||||
public void onPre(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskResume public void onTaskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
@Download.onTaskPre
|
||||
public void onTaskPre(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mSize.setText(task.getConvertFileSize());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("恢复");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||
@Download.onTaskStart
|
||||
public void onTaskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("开始");
|
||||
mPb.setProgress(0);
|
||||
@Download.onTaskResume
|
||||
public void onTaskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(false);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
} else {
|
||||
L.d(TAG, "download fail【" + task.getKey() + "】");
|
||||
@Download.onTaskStop
|
||||
public void onTaskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("恢复");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("重新开始");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
|
||||
mPb.setProgress(100);
|
||||
@Download.onTaskCancel
|
||||
public void onTaskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("开始");
|
||||
mPb.setProgress(0);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
@Download.onTaskFail
|
||||
public void onTaskFail(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
} else {
|
||||
L.d(TAG, "download fail【" + task.getKey() + "】");
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
public void onTaskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
setBtState(true);
|
||||
mStart.setText("重新开始");
|
||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
|
||||
mPb.setProgress(100);
|
||||
}
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,293 +26,293 @@ import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.HttpOption;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTaskListener;
|
||||
import com.arialyy.aria.core.download.target.HttpNormalTarget;
|
||||
import com.arialyy.aria.core.listener.ISchedulers;
|
||||
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
|
||||
import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.FileUtil;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||
import com.arialyy.simple.widget.ProgressLayout;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private HttpDownloadModule mModule;
|
||||
private long mTaskId = -1;
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private HttpDownloadModule mModule;
|
||||
private long mTaskId = -1;
|
||||
|
||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ISchedulers.ARIA_TASK_INFO_ACTION)) {
|
||||
ALog.d(TAG, "state = " + intent.getIntExtra(ISchedulers.TASK_STATE, -1));
|
||||
ALog.d(TAG, "type = " + intent.getIntExtra(ISchedulers.TASK_TYPE, -1));
|
||||
ALog.d(TAG, "speed = " + intent.getLongExtra(ISchedulers.TASK_SPEED, -1));
|
||||
ALog.d(TAG, "percent = " + intent.getIntExtra(ISchedulers.TASK_PERCENT, -1));
|
||||
ALog.d(TAG, "entity = " + intent.getParcelableExtra(ISchedulers.TASK_ENTITY).toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//registerReceiver(receiver, new IntentFilter(ISchedulers.ARIA_TASK_INFO_ACTION));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//unregisterReceiver(receiver);
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle("单任务下载");
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(HttpDownloadModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
|
||||
@Override public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ISchedulers.ARIA_TASK_INFO_ACTION)) {
|
||||
ALog.d(TAG, "state = " + intent.getIntExtra(ISchedulers.TASK_STATE, -1));
|
||||
ALog.d(TAG, "type = " + intent.getIntExtra(ISchedulers.TASK_TYPE, -1));
|
||||
ALog.d(TAG, "speed = " + intent.getLongExtra(ISchedulers.TASK_SPEED, -1));
|
||||
ALog.d(TAG, "percent = " + intent.getIntExtra(ISchedulers.TASK_PERCENT, -1));
|
||||
ALog.d(TAG, "entity = " + intent.getParcelableExtra(ISchedulers.TASK_ENTITY).toString());
|
||||
}
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
};
|
||||
|
||||
@Override public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this)
|
||||
.load(mTaskId)
|
||||
.stop();
|
||||
}
|
||||
|
||||
@Override public void resume(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId)
|
||||
//.updateUrl(mUrl)
|
||||
.resume();
|
||||
}
|
||||
|
||||
@Override public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(false);
|
||||
// //1. 删除本地文件目录
|
||||
// File localDirFile = new File(mFilePath);
|
||||
// if (localDirFile.exists()) {
|
||||
// FileUtil.deleteDir(localDirFile.getParentFile());
|
||||
// }
|
||||
//
|
||||
// //2. 删除记录
|
||||
// HttpNormalTarget target = Aria.download(SingleTaskActivity.this).load(mTaskId);
|
||||
// if (target != null) {
|
||||
// // target.cancel();
|
||||
// target.removeRecord();
|
||||
// }
|
||||
//
|
||||
// List<DownloadEntity> notCompleteTask = Aria.download(SingleTaskActivity.this).getAllNotCompleteTask();
|
||||
// if (notCompleteTask == null){
|
||||
// Log.d(TAG, "未完成的任务数:0");
|
||||
// return;
|
||||
// }
|
||||
// Log.d(TAG, "未完成的任务数:" + notCompleteTask.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
switch (item.getItemId()) {
|
||||
case R.id.help:
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
break;
|
||||
case R.id.speed_0:
|
||||
speed = 0;
|
||||
break;
|
||||
case R.id.speed_128:
|
||||
speed = 128;
|
||||
break;
|
||||
case R.id.speed_256:
|
||||
speed = 256;
|
||||
break;
|
||||
case R.id.speed_512:
|
||||
speed = 512;
|
||||
break;
|
||||
case R.id.speed_1m:
|
||||
speed = 1024;
|
||||
break;
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//registerReceiver(receiver, new IntentFilter(ISchedulers.ARIA_TASK_INFO_ACTION));
|
||||
}
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
T.showShort(this, msg);
|
||||
Aria.get(this).getDownloadConfig().setMaxSpeed(speed);
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//unregisterReceiver(receiver);
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Download.onWait
|
||||
public void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle("单任务下载");
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(HttpDownloadModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override
|
||||
public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this)
|
||||
.load(mTaskId)
|
||||
.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId)
|
||||
//.updateUrl(mUrl)
|
||||
.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(false);
|
||||
// //1. 删除本地文件目录
|
||||
// File localDirFile = new File(mFilePath);
|
||||
// if (localDirFile.exists()) {
|
||||
// FileUtil.deleteDir(localDirFile.getParentFile());
|
||||
// }
|
||||
//
|
||||
// //2. 删除记录
|
||||
// HttpNormalTarget target = Aria.download(SingleTaskActivity.this).load(mTaskId);
|
||||
// if (target != null) {
|
||||
// // target.cancel();
|
||||
// target.removeRecord();
|
||||
// }
|
||||
//
|
||||
// List<DownloadEntity> notCompleteTask = Aria.download(SingleTaskActivity.this).getAllNotCompleteTask();
|
||||
// if (notCompleteTask == null){
|
||||
// Log.d(TAG, "未完成的任务数:0");
|
||||
// return;
|
||||
// }
|
||||
// Log.d(TAG, "未完成的任务数:" + notCompleteTask.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onPre
|
||||
public void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
}
|
||||
|
||||
//@Override public void onTaskPre(DownloadTask task) {
|
||||
//
|
||||
//}
|
||||
|
||||
@Download.onTaskStart
|
||||
public void onTaskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.help) {
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
} else if (itemId == R.id.speed_0) {
|
||||
speed = 0;
|
||||
} else if (itemId == R.id.speed_128) {
|
||||
speed = 128;
|
||||
} else if (itemId == R.id.speed_256) {
|
||||
speed = 256;
|
||||
} else if (itemId == R.id.speed_512) {
|
||||
speed = 512;
|
||||
} else if (itemId == R.id.speed_1m) {
|
||||
speed = 1024;
|
||||
}
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
T.showShort(this, msg);
|
||||
Aria.get(this).getDownloadConfig().setMaxSpeed(speed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
//ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onWait
|
||||
public void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
//
|
||||
//}
|
||||
|
||||
@Download.onTaskResume
|
||||
public void onTaskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onPre
|
||||
public void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
public void onTaskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
//@Override public void onTaskPre(DownloadTask task) {
|
||||
//
|
||||
//}
|
||||
|
||||
@Download.onTaskStart
|
||||
public void onTaskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
public void onTaskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
mTaskId = -1;
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskRunning
|
||||
public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
//ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
public void onTaskFail(DownloadTask task, Exception e) {
|
||||
ALog.d(TAG, "下载失败");
|
||||
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
if (task != null && task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
//@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
//
|
||||
//}
|
||||
|
||||
@Download.onTaskResume
|
||||
public void onTaskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
public void onTaskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "文件md5: e088677570afe2e9f847cc8159b932dd");
|
||||
ALog.d(TAG, "下载完成的文件md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
getBinding().pl.setProgress(100);
|
||||
@Download.onTaskStop
|
||||
public void onTaskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_single;
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
HttpOption option = new HttpOption();
|
||||
option.useServerFileName(true);
|
||||
option.addHeader("1", "@")
|
||||
.useServerFileName(true)
|
||||
.setFileLenAdapter(new FileLenAdapter());
|
||||
//option.setRequestType(RequestEnum.POST);
|
||||
mTaskId = Aria.download(SingleTaskActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath, true)
|
||||
.option(option)
|
||||
.ignoreCheckPermissions()
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
//Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
@Override public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
static class FileLenAdapter implements IHttpFileLenAdapter {
|
||||
@Override public long handleFileLen(Map<String, List<String>> headers) {
|
||||
|
||||
List<String> sLength = headers.get("Content-Length");
|
||||
if (sLength == null || sLength.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
String temp = sLength.get(0);
|
||||
|
||||
return Long.parseLong(temp);
|
||||
@Download.onTaskCancel
|
||||
public void onTaskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
mTaskId = -1;
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
public void onTaskFail(DownloadTask task, Exception e) {
|
||||
ALog.d(TAG, "下载失败");
|
||||
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
if (task != null && task.getKey().equals(mUrl)) {
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
public void onTaskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "文件md5: e088677570afe2e9f847cc8159b932dd");
|
||||
ALog.d(TAG, "下载完成的文件md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
getBinding().pl.setProgress(100);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_single;
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
HttpOption option = new HttpOption();
|
||||
option.useServerFileName(true);
|
||||
option.addHeader("1", "@")
|
||||
.useServerFileName(true)
|
||||
.setFileLenAdapter(new FileLenAdapter());
|
||||
//option.setRequestType(RequestEnum.POST);
|
||||
mTaskId = Aria.download(SingleTaskActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath, true)
|
||||
.option(option)
|
||||
.ignoreCheckPermissions()
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
//Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
static class FileLenAdapter implements IHttpFileLenAdapter {
|
||||
@Override
|
||||
public long handleFileLen(Map<String, List<String>> headers) {
|
||||
|
||||
List<String> sLength = headers.get("Content-Length");
|
||||
if (sLength == null || sLength.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
String temp = sLength.get(0);
|
||||
|
||||
return Long.parseLong(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@@ -33,130 +34,140 @@ import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseDialog;
|
||||
import com.arialyy.simple.databinding.DialogSubTaskHandlerBinding;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/9/5.
|
||||
*/
|
||||
@SuppressLint("ValidFragment") public class ChildHandleDialog
|
||||
extends BaseDialog<DialogSubTaskHandlerBinding> implements View.OnClickListener {
|
||||
TextView mSub;
|
||||
TextView mGroup;
|
||||
HorizontalProgressBarWithNumber mPb;
|
||||
private String mGroupHash;
|
||||
private String mChildName;
|
||||
private List<String> mUrls;
|
||||
private DownloadEntity mChildEntity;
|
||||
@SuppressLint("ValidFragment")
|
||||
public class ChildHandleDialog
|
||||
extends BaseDialog<DialogSubTaskHandlerBinding> implements View.OnClickListener {
|
||||
TextView mSub;
|
||||
TextView mGroup;
|
||||
HorizontalProgressBarWithNumber mPb;
|
||||
private String mGroupHash;
|
||||
private String mChildName;
|
||||
private List<String> mUrls;
|
||||
private DownloadEntity mChildEntity;
|
||||
|
||||
public ChildHandleDialog(Context context, List<String> urls, DownloadEntity childEntity) {
|
||||
super(context);
|
||||
setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog);
|
||||
mChildEntity = childEntity;
|
||||
mGroupHash = "任务组测试";
|
||||
mUrls = urls;
|
||||
mChildName = childEntity.getFileName();
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(getContext()).register();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
mSub = findViewById(R.id.sub_task);
|
||||
mGroup = findViewById(R.id.task_group);
|
||||
mPb = findViewById(R.id.pb);
|
||||
|
||||
findViewById(R.id.stop).setOnClickListener(this);
|
||||
findViewById(R.id.start).setOnClickListener(this);
|
||||
//findViewById(R.id.cancel).setOnClickListener(this);
|
||||
mGroup.setText("任务组:" + mGroupHash);
|
||||
mSub.setText("子任务:" + mChildName);
|
||||
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize()));
|
||||
|
||||
Window window = getDialog().getWindow();
|
||||
window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
|
||||
WindowManager.LayoutParams p = window.getAttributes();
|
||||
p.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(p);
|
||||
window.setWindowAnimations(R.style.dialogStyle);
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mPb.setProgress(subEntity.getPercent());
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
L.d(TAG, subEntity.getPercent() + "");
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskStop void onSubTaskStop(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务停止");
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskStart void onSubTaskStart(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:下载中");
|
||||
}
|
||||
|
||||
//@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
|
||||
// DownloadEntity subEntity) {
|
||||
// Log.d(TAG, "new Size: " + groupTask.getConvertFileSize());
|
||||
// mSub.setText("子任务:" + mChildName + ",状态:取消下载");
|
||||
//}
|
||||
|
||||
@DownloadGroup.onSubTaskComplete void onSubTaskComplete(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务完成");
|
||||
mPb.setProgress(100);
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
L.d(TAG, subEntity.getPercent() + "");
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.dialog_sub_task_handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(getContext())
|
||||
.loadGroup(mUrls)
|
||||
.getSubTaskManager()
|
||||
.startSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(getContext())
|
||||
.loadGroup(mUrls)
|
||||
.getSubTaskManager()
|
||||
.stopSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
//case R.id.cancel:
|
||||
// Aria.download(this).load(mUrls).getSubTaskManager().cancelSubTask(mChildEntity.getUrl());
|
||||
// break;
|
||||
public ChildHandleDialog(Context context, List<String> urls, DownloadEntity childEntity) {
|
||||
super(context);
|
||||
setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog);
|
||||
mChildEntity = childEntity;
|
||||
mGroupHash = "任务组测试";
|
||||
mUrls = urls;
|
||||
mChildName = childEntity.getFileName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object obj) {
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(getContext()).register();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
mSub = findViewById(R.id.sub_task);
|
||||
mGroup = findViewById(R.id.task_group);
|
||||
mPb = findViewById(R.id.pb);
|
||||
|
||||
findViewById(R.id.stop).setOnClickListener(this);
|
||||
findViewById(R.id.start).setOnClickListener(this);
|
||||
//findViewById(R.id.cancel).setOnClickListener(this);
|
||||
mGroup.setText("任务组:" + mGroupHash);
|
||||
mSub.setText("子任务:" + mChildName);
|
||||
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize()));
|
||||
|
||||
Window window = getDialog().getWindow();
|
||||
window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
|
||||
WindowManager.LayoutParams p = window.getAttributes();
|
||||
p.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(p);
|
||||
window.setWindowAnimations(R.style.dialogStyle);
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskRunning
|
||||
void onSubTaskRunning(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mPb.setProgress(subEntity.getPercent());
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskPre
|
||||
void onSubTaskPre(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
L.d(TAG, subEntity.getPercent() + "");
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskStop
|
||||
void onSubTaskStop(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务停止");
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskStart
|
||||
void onSubTaskStart(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:下载中");
|
||||
}
|
||||
|
||||
//@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
|
||||
// DownloadEntity subEntity) {
|
||||
// Log.d(TAG, "new Size: " + groupTask.getConvertFileSize());
|
||||
// mSub.setText("子任务:" + mChildName + ",状态:取消下载");
|
||||
//}
|
||||
|
||||
@DownloadGroup.onSubTaskComplete
|
||||
void onSubTaskComplete(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务完成");
|
||||
mPb.setProgress(100);
|
||||
}
|
||||
|
||||
@DownloadGroup.onSubTaskFail
|
||||
void onSubTaskFail(DownloadGroupTask groupTask,
|
||||
DownloadEntity subEntity) {
|
||||
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
|
||||
L.d(TAG, subEntity.getPercent() + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.dialog_sub_task_handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {
|
||||
Aria.download(getContext())
|
||||
.loadGroup(mUrls)
|
||||
.getSubTaskManager()
|
||||
.startSubTask(mChildEntity.getUrl());
|
||||
} else if (id == R.id.stop) {
|
||||
Aria.download(getContext())
|
||||
.loadGroup(mUrls)
|
||||
.getSubTaskManager()
|
||||
.stopSubTask(mChildEntity.getUrl());
|
||||
//case R.id.cancel:
|
||||
// Aria.download(this).load(mUrls).getSubTaskManager().cancelSubTask(mChildEntity.getUrl());
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dataCallback(int result, Object obj) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
@@ -43,233 +45,236 @@ import com.arialyy.simple.common.ModifyPathDialog;
|
||||
import com.arialyy.simple.common.ModifyUrlDialog;
|
||||
import com.arialyy.simple.databinding.ActivityM3u8LiveBinding;
|
||||
import com.arialyy.simple.widget.ProgressLayout;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding> {
|
||||
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private M3U8LiveModule mModule;
|
||||
private long mTaskId;
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private M3U8LiveModule mModule;
|
||||
private long mTaskId;
|
||||
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle(getString(R.string.m3u8_live));
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(M3U8LiveModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle(getString(R.string.m3u8_live));
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(M3U8LiveModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
|
||||
@Override public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
@Override
|
||||
public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override
|
||||
public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(View v, AbsEntity entity) {
|
||||
ALog.d(TAG, "m3u8 live 不支持恢复");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(true);
|
||||
mTaskId = -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.help) {
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
} else if (itemId == R.id.speed_0) {
|
||||
speed = 0;
|
||||
} else if (itemId == R.id.speed_128) {
|
||||
speed = 128;
|
||||
} else if (itemId == R.id.speed_256) {
|
||||
speed = 256;
|
||||
} else if (itemId == R.id.speed_512) {
|
||||
speed = 512;
|
||||
} else if (itemId == R.id.speed_1m) {
|
||||
speed = 1024;
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
|
||||
@Override public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
}
|
||||
|
||||
@Override public void resume(View v, AbsEntity entity) {
|
||||
ALog.d(TAG, "m3u8 live 不支持恢复");
|
||||
}
|
||||
|
||||
@Override public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(true);
|
||||
mTaskId = -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
switch (item.getItemId()) {
|
||||
case R.id.help:
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
break;
|
||||
case R.id.speed_0:
|
||||
speed = 0;
|
||||
break;
|
||||
case R.id.speed_128:
|
||||
speed = 128;
|
||||
break;
|
||||
case R.id.speed_256:
|
||||
speed = 256;
|
||||
break;
|
||||
case R.id.speed_512:
|
||||
speed = 512;
|
||||
break;
|
||||
case R.id.speed_1m:
|
||||
speed = 1024;
|
||||
break;
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
Aria.download(this).setMaxSpeed(speed);
|
||||
T.showShort(this, msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
Aria.download(this).setMaxSpeed(speed);
|
||||
T.showShort(this, msg);
|
||||
|
||||
@M3U8.onPeerStart
|
||||
void onPeerStart(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer create, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@M3U8.onPeerStart
|
||||
void onPeerStart(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer create, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
|
||||
@M3U8.onPeerComplete
|
||||
void onPeerComplete(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer complete, path: " + peerPath + ", index: " + peerIndex);
|
||||
//mVideoFragment.addPlayer(peerIndex, peerPath);
|
||||
}
|
||||
|
||||
@M3U8.onPeerFail
|
||||
void onPeerFail(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer fail, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
@M3U8.onPeerComplete
|
||||
void onPeerComplete(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer complete, path: " + peerPath + ", index: " + peerIndex);
|
||||
//mVideoFragment.addPlayer(peerIndex, peerPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onPre
|
||||
protected void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "pre");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@M3U8.onPeerFail
|
||||
void onPeerFail(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer fail, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStart
|
||||
void taskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG,
|
||||
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onPre
|
||||
protected void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "pre");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskResume
|
||||
void taskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "m3u8 vod resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskStart
|
||||
void taskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void taskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG,
|
||||
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void taskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskResume
|
||||
void taskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "m3u8 vod resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(this, getString(R.string.download_fail),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
Log.d(TAG, "fail");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskStop
|
||||
void taskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskCancel
|
||||
void taskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_m3u8_live;
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
mTaskId = Aria.download(M3U8LiveDLoadActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath)
|
||||
.ignoreFilePathOccupy()
|
||||
.m3u8LiveOption(getLiveoption())
|
||||
.create();
|
||||
}
|
||||
|
||||
private M3U8LiveOption getLiveoption() {
|
||||
M3U8LiveOption option = new M3U8LiveOption();
|
||||
option
|
||||
//.generateIndexFile()
|
||||
.setLiveTsUrlConvert(new LiveTsUrlConverter());
|
||||
//.setBandWidthUrlConverter(new BandWidthUrlConverter(mUrl));
|
||||
return option;
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
|
||||
mModule.uploadUrl(this, String.valueOf(data));
|
||||
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
|
||||
mModule.updateFilePath(this, String.valueOf(data));
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(this, getString(R.string.download_fail),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
Log.d(TAG, "fail");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class LiveTsUrlConverter implements ILiveTsUrlConverter {
|
||||
@Override public String convert(String m3u8Url, String tsUrl) {
|
||||
int index = m3u8Url.lastIndexOf("/");
|
||||
String parentUrl = m3u8Url.substring(0, index + 1);
|
||||
return parentUrl + tsUrl;
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
|
||||
|
||||
@Override public String convert(String m3u8Url, String bandWidthUrl) {
|
||||
int peerIndex = m3u8Url.lastIndexOf("/");
|
||||
return m3u8Url.substring(0, peerIndex + 1) + bandWidthUrl;
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_m3u8_live;
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
mTaskId = Aria.download(M3U8LiveDLoadActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath)
|
||||
.ignoreFilePathOccupy()
|
||||
.m3u8LiveOption(getLiveoption())
|
||||
.create();
|
||||
}
|
||||
|
||||
private M3U8LiveOption getLiveoption() {
|
||||
M3U8LiveOption option = new M3U8LiveOption();
|
||||
option
|
||||
//.generateIndexFile()
|
||||
.setLiveTsUrlConvert(new LiveTsUrlConverter());
|
||||
//.setBandWidthUrlConverter(new BandWidthUrlConverter(mUrl));
|
||||
return option;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
|
||||
mModule.uploadUrl(this, String.valueOf(data));
|
||||
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
|
||||
mModule.updateFilePath(this, String.valueOf(data));
|
||||
}
|
||||
}
|
||||
|
||||
static class LiveTsUrlConverter implements ILiveTsUrlConverter {
|
||||
@Override
|
||||
public String convert(String m3u8Url, String tsUrl) {
|
||||
int index = m3u8Url.lastIndexOf("/");
|
||||
String parentUrl = m3u8Url.substring(0, index + 1);
|
||||
return parentUrl + tsUrl;
|
||||
}
|
||||
}
|
||||
|
||||
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
|
||||
|
||||
@Override
|
||||
public String convert(String m3u8Url, String bandWidthUrl) {
|
||||
int peerIndex = m3u8Url.lastIndexOf("/");
|
||||
return m3u8Url.substring(0, peerIndex + 1) + bandWidthUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,15 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.M3U8;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.HttpOption;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.M3U8Entity;
|
||||
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
|
||||
@@ -50,325 +51,334 @@ import com.arialyy.simple.common.ModifyUrlDialog;
|
||||
import com.arialyy.simple.databinding.ActivityM3u8VodBinding;
|
||||
import com.arialyy.simple.to.PeerIndex;
|
||||
import com.arialyy.simple.widget.ProgressLayout;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
|
||||
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private M3U8VodModule mModule;
|
||||
private VideoPlayerFragment mVideoFragment;
|
||||
private long mTaskId;
|
||||
private String mUrl;
|
||||
private String mFilePath;
|
||||
private M3U8VodModule mModule;
|
||||
private VideoPlayerFragment mVideoFragment;
|
||||
private long mTaskId;
|
||||
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle(getString(R.string.m3u8_file));
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(M3U8VodModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setTitle(getString(R.string.m3u8_file));
|
||||
Aria.download(this).register();
|
||||
mModule = ViewModelProviders.of(this).get(M3U8VodModule.class);
|
||||
mModule.getHttpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
|
||||
|
||||
@Override public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
@Override
|
||||
public void onChanged(@Nullable DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
if (entity.getM3U8Entity() != null) {
|
||||
getBinding().seekBar.setMax(entity.getM3U8Entity().getPeerNum());
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
//mVideoFragment = new VideoPlayerFragment(0, entity);
|
||||
//FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
//ft.add(R.id.video_content, mVideoFragment);
|
||||
//ft.commit();
|
||||
}
|
||||
});
|
||||
getBinding().seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
Aria.download(this).load(mTaskId).m3u8VodOption().jumPeerIndex(seekBar.getProgress());
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override
|
||||
public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(View v, AbsEntity entity) {
|
||||
Aria.download(this)
|
||||
.load(mTaskId)
|
||||
.m3u8VodOption(getM3U8Option())
|
||||
.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(true);
|
||||
mTaskId = -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void chooseUrl() {
|
||||
ModifyUrlDialog dialog =
|
||||
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);
|
||||
dialog.show(getSupportFragmentManager(), "ModifyUrlDialog");
|
||||
}
|
||||
|
||||
public void chooseFilePath() {
|
||||
ModifyPathDialog dialog =
|
||||
new ModifyPathDialog(this, getString(R.string.modify_file_path), mFilePath);
|
||||
dialog.show(getSupportFragmentManager(), "ModifyPathDialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void jumpIndex(PeerIndex index) {
|
||||
Aria.download(this).load(mTaskId).m3u8VodOption().jumPeerIndex(index.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.help) {
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
} else if (itemId == R.id.speed_0) {
|
||||
speed = 0;
|
||||
} else if (itemId == R.id.speed_128) {
|
||||
speed = 128;
|
||||
} else if (itemId == R.id.speed_256) {
|
||||
speed = 256;
|
||||
} else if (itemId == R.id.speed_512) {
|
||||
speed = 512;
|
||||
} else if (itemId == R.id.speed_1m) {
|
||||
speed = 1024;
|
||||
}
|
||||
if (entity.getM3U8Entity() != null) {
|
||||
getBinding().seekBar.setMax(entity.getM3U8Entity().getPeerNum());
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
Aria.download(this).setMaxSpeed(speed);
|
||||
T.showShort(this, msg);
|
||||
}
|
||||
mTaskId = entity.getId();
|
||||
mUrl = entity.getUrl();
|
||||
mFilePath = entity.getFilePath();
|
||||
getBinding().pl.setInfo(entity);
|
||||
//mVideoFragment = new VideoPlayerFragment(0, entity);
|
||||
//FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
//ft.add(R.id.video_content, mVideoFragment);
|
||||
//ft.commit();
|
||||
}
|
||||
});
|
||||
getBinding().seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
Aria.download(this).load(mTaskId).m3u8VodOption().jumPeerIndex(seekBar.getProgress());
|
||||
}
|
||||
});
|
||||
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
|
||||
@Override public void create(View v, AbsEntity entity) {
|
||||
startD();
|
||||
}
|
||||
|
||||
@Override public void stop(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).stop();
|
||||
}
|
||||
|
||||
@Override public void resume(View v, AbsEntity entity) {
|
||||
Aria.download(this)
|
||||
.load(mTaskId)
|
||||
.m3u8VodOption(getM3U8Option())
|
||||
.resume();
|
||||
}
|
||||
|
||||
@Override public void cancel(View v, AbsEntity entity) {
|
||||
Aria.download(this).load(mTaskId).cancel(true);
|
||||
mTaskId = -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void chooseUrl() {
|
||||
ModifyUrlDialog dialog =
|
||||
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);
|
||||
dialog.show(getSupportFragmentManager(), "ModifyUrlDialog");
|
||||
}
|
||||
|
||||
public void chooseFilePath() {
|
||||
ModifyPathDialog dialog =
|
||||
new ModifyPathDialog(this, getString(R.string.modify_file_path), mFilePath);
|
||||
dialog.show(getSupportFragmentManager(), "ModifyPathDialog");
|
||||
}
|
||||
|
||||
@Override protected void onStart() {
|
||||
super.onStart();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override protected void onStop() {
|
||||
super.onStop();
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void jumpIndex(PeerIndex index) {
|
||||
Aria.download(this).load(mTaskId).m3u8VodOption().jumPeerIndex(index.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int speed = -1;
|
||||
String msg = "";
|
||||
switch (item.getItemId()) {
|
||||
case R.id.help:
|
||||
msg = "一些小知识点:\n"
|
||||
+ "1、你可以在注解中增加链接,用于指定被注解的方法只能被特定的下载任务回调,以防止progress乱跳\n"
|
||||
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
|
||||
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据";
|
||||
showMsgDialog("tip", msg);
|
||||
break;
|
||||
case R.id.speed_0:
|
||||
speed = 0;
|
||||
break;
|
||||
case R.id.speed_128:
|
||||
speed = 128;
|
||||
break;
|
||||
case R.id.speed_256:
|
||||
speed = 256;
|
||||
break;
|
||||
case R.id.speed_512:
|
||||
speed = 512;
|
||||
break;
|
||||
case R.id.speed_1m:
|
||||
speed = 1024;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
Aria.download(this).setMaxSpeed(speed);
|
||||
T.showShort(this, msg);
|
||||
|
||||
@M3U8.onPeerStart
|
||||
void onPeerStart(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer create, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@M3U8.onPeerStart
|
||||
void onPeerStart(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer create, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
|
||||
@M3U8.onPeerComplete
|
||||
void onPeerComplete(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer complete, path: " + peerPath + ", index: " + peerIndex);
|
||||
//mVideoFragment.addPlayer(peerIndex, peerPath);
|
||||
}
|
||||
|
||||
@M3U8.onPeerFail
|
||||
void onPeerFail(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer fail, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
@M3U8.onPeerComplete
|
||||
void onPeerComplete(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer complete, path: " + peerPath + ", index: " + peerIndex);
|
||||
//mVideoFragment.addPlayer(peerIndex, peerPath);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onPre
|
||||
protected void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "pre");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@M3U8.onPeerFail
|
||||
void onPeerFail(String m3u8Url, String peerPath, int peerIndex) {
|
||||
//ALog.d(TAG, "peer fail, path: " + peerPath + ", index: " + peerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStart
|
||||
void taskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
getBinding().seekBar.setMax(task.getEntity().getM3U8Entity().getPeerNum());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onWait
|
||||
void onWait(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG,
|
||||
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onPre
|
||||
protected void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "pre");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskResume
|
||||
void taskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "m3u8 vod resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskStart
|
||||
void taskStart(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
|
||||
getBinding().seekBar.setMax(task.getEntity().getM3U8Entity().getPeerNum());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void taskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG,
|
||||
"m3u8 void running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void taskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskResume
|
||||
void taskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "m3u8 vod resume");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
if (task != null && task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_fail),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
Log.d(TAG, "fail");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskStop
|
||||
void taskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
ALog.d(TAG, "stop");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
@Download.onTaskCancel
|
||||
void taskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Log.d(TAG, "cancel");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_m3u8_vod;
|
||||
}
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
if (task != null && task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_fail),
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
Log.d(TAG, "fail");
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
mTaskId = Aria.download(M3U8VodDLoadActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath)
|
||||
.ignoreFilePathOccupy()
|
||||
.m3u8VodOption(getM3U8Option())
|
||||
.create();
|
||||
}
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(mUrl)) {
|
||||
Toast.makeText(M3U8VodDLoadActivity.this, getString(R.string.download_success),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
ALog.d(TAG, "md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
|
||||
getBinding().pl.setInfo(task.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
private M3U8VodOption getM3U8Option() {
|
||||
M3U8VodOption option = new M3U8VodOption();
|
||||
//option.setBandWidth(200000);
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_m3u8_vod;
|
||||
}
|
||||
|
||||
private void startD() {
|
||||
mTaskId = Aria.download(M3U8VodDLoadActivity.this)
|
||||
.load(mUrl)
|
||||
.setFilePath(mFilePath)
|
||||
.ignoreFilePathOccupy()
|
||||
.m3u8VodOption(getM3U8Option())
|
||||
.create();
|
||||
}
|
||||
|
||||
private M3U8VodOption getM3U8Option() {
|
||||
M3U8VodOption option = new M3U8VodOption();
|
||||
//option.setBandWidth(200000);
|
||||
//.generateIndexFile()
|
||||
//.merge(true)
|
||||
//.setVodTsUrlConvert(new VodTsUrlConverter());
|
||||
//.setMergeHandler(new TsMergeHandler());
|
||||
option.setUseDefConvert(true);
|
||||
option.generateIndexFile();
|
||||
//option.setKeyUrlConverter(new KeyUrlConverter());
|
||||
//option.setVodTsUrlConvert(new VodTsUrlConverter());
|
||||
option.setBandWidthUrlConverter(new BandWidthUrlConverter());
|
||||
//option.setUseDefConvert(true);
|
||||
return option;
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
|
||||
mModule.uploadUrl(this, String.valueOf(data));
|
||||
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
|
||||
mModule.updateFilePath(this, String.valueOf(data));
|
||||
//.setMergeHandler(new TsMergeHandler());
|
||||
option.setUseDefConvert(true);
|
||||
option.generateIndexFile();
|
||||
//option.setKeyUrlConverter(new KeyUrlConverter());
|
||||
//option.setVodTsUrlConvert(new VodTsUrlConverter());
|
||||
option.setBandWidthUrlConverter(new BandWidthUrlConverter());
|
||||
//option.setUseDefConvert(true);
|
||||
return option;
|
||||
}
|
||||
}
|
||||
|
||||
static class VodTsUrlConverter implements IVodTsUrlConverter {
|
||||
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
|
||||
Uri uri = Uri.parse(m3u8Url);
|
||||
//String parentUrl = "http://devimages.apple.com/iphone/samples/bipbop/gear1/";
|
||||
//String parentUrl = "http://youku.cdn7-okzy.com/20200123/16815_fbe419ed/1000k/hls/";
|
||||
//String parentUrl = "http://" + uri.getHost() + "/gear1/";
|
||||
//int index = m3u8Url.lastIndexOf("/");
|
||||
//String parentUrl = m3u8Url.substring(0, index + 1);
|
||||
//String parentUrl = "https://v1.szjal.cn/20190819/Ql6UD1od/";
|
||||
//String parentUrl = "http://" + uri.getHost() + "/";
|
||||
//List<String> newUrls = new ArrayList<>();
|
||||
//for (String url : tsUrls) {
|
||||
// newUrls.add(parentUrl + url);
|
||||
//}
|
||||
|
||||
//return newUrls;
|
||||
return tsUrls;
|
||||
@Override
|
||||
protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
|
||||
mModule.uploadUrl(this, String.valueOf(data));
|
||||
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
|
||||
mModule.updateFilePath(this, String.valueOf(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class TsMergeHandler implements ITsMergeHandler {
|
||||
public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) {
|
||||
ALog.d("TsMergeHandler", "合并TS....");
|
||||
return false;
|
||||
static class VodTsUrlConverter implements IVodTsUrlConverter {
|
||||
@Override
|
||||
public List<String> convert(String m3u8Url, List<String> tsUrls) {
|
||||
Uri uri = Uri.parse(m3u8Url);
|
||||
//String parentUrl = "http://devimages.apple.com/iphone/samples/bipbop/gear1/";
|
||||
//String parentUrl = "http://youku.cdn7-okzy.com/20200123/16815_fbe419ed/1000k/hls/";
|
||||
//String parentUrl = "http://" + uri.getHost() + "/gear1/";
|
||||
//int index = m3u8Url.lastIndexOf("/");
|
||||
//String parentUrl = m3u8Url.substring(0, index + 1);
|
||||
//String parentUrl = "https://v1.szjal.cn/20190819/Ql6UD1od/";
|
||||
//String parentUrl = "http://" + uri.getHost() + "/";
|
||||
//List<String> newUrls = new ArrayList<>();
|
||||
//for (String url : tsUrls) {
|
||||
// newUrls.add(parentUrl + url);
|
||||
//}
|
||||
|
||||
//return newUrls;
|
||||
return tsUrls;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
|
||||
|
||||
|
||||
@Override public String convert(String m3u8Url, String bandWidthUrl) {
|
||||
int index = m3u8Url.lastIndexOf("/");
|
||||
return m3u8Url.substring(0, index + 1) + bandWidthUrl;
|
||||
static class TsMergeHandler implements ITsMergeHandler {
|
||||
public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) {
|
||||
ALog.d("TsMergeHandler", "合并TS....");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class KeyUrlConverter implements IKeyUrlConverter {
|
||||
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
|
||||
|
||||
@Override public String convert(String m3u8Url, String tsListUrl, String keyUrl) {
|
||||
ALog.d("TAG", "convertUrl....");
|
||||
return null;
|
||||
|
||||
@Override
|
||||
public String convert(String m3u8Url, String bandWidthUrl) {
|
||||
int index = m3u8Url.lastIndexOf("/");
|
||||
return m3u8Url.substring(0, index + 1) + bandWidthUrl;
|
||||
}
|
||||
}
|
||||
|
||||
static class KeyUrlConverter implements IKeyUrlConverter {
|
||||
|
||||
@Override
|
||||
public String convert(String m3u8Url, String tsListUrl, String keyUrl) {
|
||||
ALog.d("TAG", "convertUrl....");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,11 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
@@ -35,6 +37,7 @@ import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.core.download.DownloadModule;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,123 +46,137 @@ import java.util.List;
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class MultiTaskListActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
RecyclerView mList;
|
||||
Toolbar mBar;
|
||||
private FileListAdapter mAdapter;
|
||||
List<FileListEntity> mData = new ArrayList<>();
|
||||
RecyclerView mList;
|
||||
Toolbar mBar;
|
||||
private FileListAdapter mAdapter;
|
||||
List<FileListEntity> mData = new ArrayList<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_multi;
|
||||
}
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_multi;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
setTitle("多任务下载");
|
||||
mData.addAll(getModule(DownloadModule.class).createGroupTestList());
|
||||
mData.addAll(getModule(DownloadModule.class).createMultiTestList());
|
||||
mData.addAll(getModule(DownloadModule.class).createM3u8TestList());
|
||||
mAdapter = new FileListAdapter(this, mData);
|
||||
mList = getBinding().list;
|
||||
mBar = findViewById(R.id.toolbar);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
setTitle("多任务下载");
|
||||
mData.addAll(getModule(DownloadModule.class).createGroupTestList());
|
||||
mData.addAll(getModule(DownloadModule.class).createMultiTestList());
|
||||
mData.addAll(getModule(DownloadModule.class).createM3u8TestList());
|
||||
mAdapter = new FileListAdapter(this, mData);
|
||||
mList = getBinding().list;
|
||||
mBar = findViewById(R.id.toolbar);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.num:
|
||||
DownloadNumDialog dialog = new DownloadNumDialog(this);
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
break;
|
||||
case R.id.stop_all:
|
||||
//Aria.download(this).stopAllTask();
|
||||
List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
||||
for (AbsEntity entity : list){
|
||||
Aria.download(this).load(entity.getId()).cancel(true);
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.num) {
|
||||
DownloadNumDialog dialog = new DownloadNumDialog(this);
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
} else if (id == R.id.stop_all) {//Aria.download(this).stopAllTask();
|
||||
List<AbsEntity> list = Aria.download(this).getTotalTaskList();
|
||||
for (AbsEntity entity : list) {
|
||||
Aria.download(this).load(entity.getId()).cancel(true);
|
||||
}
|
||||
//Aria.download(this).removeAllTask(false);
|
||||
} else if (id == R.id.turn) {
|
||||
startActivity(new Intent(this, MultiDownloadActivity.class));
|
||||
}
|
||||
//Aria.download(this).removeAllTask(false);
|
||||
break;
|
||||
case R.id.turn:
|
||||
startActivity(new Intent(this, MultiDownloadActivity.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onWait void taskWait(DownloadTask task) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
if (task == null || task.getEntity() == null){
|
||||
return;
|
||||
@Download.onWait
|
||||
void taskWait(DownloadTask task) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
Log.d(TAG, FileUtil.getFileMD5(new File(task.getFilePath())));
|
||||
}
|
||||
|
||||
//############################### 任务组 ##############################
|
||||
@DownloadGroup.onTaskComplete void groupTaskComplete(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStart void groupTaskStart(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskResume void groupTaskResume(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@DownloadGroup.onWait void groupTaskWait(DownloadGroupTask task) {
|
||||
ALog.d(TAG, String.format("group【%s】wait---", task.getTaskName()));
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStop void groupTaskStop(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
Log.d(TAG, String.format("group【%s】stop", task.getTaskName()));
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskCancel void groupTaskCancel(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskFail void groupTaskFail(DownloadGroupTask task) {
|
||||
if (task == null) {
|
||||
return;
|
||||
@Download.onTaskStart
|
||||
void taskStart(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
Log.d(TAG, String.format("group【%s】fail", task.getTaskName()));
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskComplete void taskComplete(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == DownloadNumDialog.RESULT_CODE) {
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + ""));
|
||||
@Download.onTaskResume
|
||||
void taskResume(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@Download.onTaskStop
|
||||
void taskStop(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel
|
||||
void taskCancel(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task) {
|
||||
if (task == null || task.getEntity() == null) {
|
||||
return;
|
||||
}
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
Log.d(TAG, FileUtil.getFileMD5(new File(task.getFilePath())));
|
||||
}
|
||||
|
||||
//############################### 任务组 ##############################
|
||||
@DownloadGroup.onTaskComplete
|
||||
void groupTaskComplete(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStart
|
||||
void groupTaskStart(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskResume
|
||||
void groupTaskResume(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@DownloadGroup.onWait
|
||||
void groupTaskWait(DownloadGroupTask task) {
|
||||
ALog.d(TAG, String.format("group【%s】wait---", task.getTaskName()));
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStop
|
||||
void groupTaskStop(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
Log.d(TAG, String.format("group【%s】stop", task.getTaskName()));
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskCancel
|
||||
void groupTaskCancel(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskFail
|
||||
void groupTaskFail(DownloadGroupTask task) {
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
Log.d(TAG, String.format("group【%s】fail", task.getTaskName()));
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskComplete
|
||||
void taskComplete(DownloadGroupTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == DownloadNumDialog.RESULT_CODE) {
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package com.arialyy.simple.core.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityTestBinding;
|
||||
@@ -14,60 +14,59 @@ import com.arialyy.simple.modlue.AnyRunnModule;
|
||||
*/
|
||||
|
||||
public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||
AnyRunnModule module;
|
||||
String[] urls;
|
||||
int index = 0;
|
||||
//String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
//String URL = "http://58.213.157.242:8081/sims_file/rest/v1/file/mshd_touchscreen_ms/guideFile/41c33556-dc4a-4d78-bb76-b9f627f94448.mp4/%E5%85%AB%E5%8D%A6%E6%B4%B2%E5%8D%97%E4%BA%AC%E5%86%9C%E4%B8%9A%E5%98%89%E5%B9%B4%E5%8D%8E0511.mp4";
|
||||
//String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk";
|
||||
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar";
|
||||
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
||||
//String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk";
|
||||
//String URL = "ftps://192.168.29.140:990/download/SDK_Demo-release.apk";
|
||||
//String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176";
|
||||
//String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
|
||||
//String URL = "https://app-dl.byfen.com//app//201810//ef0400d637e768e9c630b4d38633ee06.zip";
|
||||
String URL = "ftps://9.9.9.59:990/download/SDK_Demo-release.apk";
|
||||
//private String URL = "https://www.bilibili.com/bangumi/play/ep77693";
|
||||
//private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1";
|
||||
AnyRunnModule module;
|
||||
String[] urls;
|
||||
int index = 0;
|
||||
//String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
//String URL = "http://58.213.157.242:8081/sims_file/rest/v1/file/mshd_touchscreen_ms/guideFile/41c33556-dc4a-4d78-bb76-b9f627f94448.mp4/%E5%85%AB%E5%8D%A6%E6%B4%B2%E5%8D%97%E4%BA%AC%E5%86%9C%E4%B8%9A%E5%98%89%E5%B9%B4%E5%8D%8E0511.mp4";
|
||||
//String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk";
|
||||
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar";
|
||||
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
||||
//String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk";
|
||||
//String URL = "ftps://192.168.29.140:990/download/SDK_Demo-release.apk";
|
||||
//String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176";
|
||||
//String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
|
||||
//String URL = "https://app-dl.byfen.com//app//201810//ef0400d637e768e9c630b4d38633ee06.zip";
|
||||
String URL = "ftps://9.9.9.59:990/download/SDK_Demo-release.apk";
|
||||
//private String URL = "https://www.bilibili.com/bangumi/play/ep77693";
|
||||
//private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1";
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_test;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.init(this);
|
||||
mBar.setVisibility(View.GONE);
|
||||
module = new AnyRunnModule(this);
|
||||
urls = getResources().getStringArray(R.array.group_urls);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
//module.create(URL);
|
||||
module.startFtp(URL);
|
||||
break;
|
||||
case R.id.stop:
|
||||
module.stop(URL);
|
||||
break;
|
||||
case R.id.cancel:
|
||||
module.cancel(URL);
|
||||
//String newUrl = "ftp://192.168.29.140:21/download/11SDK_Demo-release.apk";
|
||||
//Aria.download(this)
|
||||
// .loadFtp(URL)
|
||||
// .updateUrl(newUrl)
|
||||
// .login("lao", "123456")
|
||||
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/")
|
||||
// .create();
|
||||
break;
|
||||
@Override
|
||||
protected int setLayoutId() {
|
||||
return R.layout.activity_test;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
module.unRegister();
|
||||
}
|
||||
@Override
|
||||
protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.init(this);
|
||||
mBar.setVisibility(View.GONE);
|
||||
module = new AnyRunnModule(this);
|
||||
urls = getResources().getStringArray(R.array.group_urls);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.start) {//module.create(URL);
|
||||
module.startFtp(URL);
|
||||
} else if (id == R.id.stop) {
|
||||
module.stop(URL);
|
||||
} else if (id == R.id.cancel) {
|
||||
module.cancel(URL);
|
||||
//String newUrl = "ftp://192.168.29.140:21/download/11SDK_Demo-release.apk";
|
||||
//Aria.download(this)
|
||||
// .loadFtp(URL)
|
||||
// .updateUrl(newUrl)
|
||||
// .login("lao", "123456")
|
||||
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/")
|
||||
// .create();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
module.unRegister();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.AbsGroupEntity;
|
||||
import com.arialyy.aria.core.common.AbsNormalEntity;
|
||||
@@ -30,238 +32,238 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 统一的进度布局
|
||||
*/
|
||||
public class ProgressLayout extends RelativeLayout implements View.OnClickListener {
|
||||
private final String TAG = "ProgressLayout";
|
||||
private TextView speedOrState, fileName, leftTime, fileSize;
|
||||
private HorizontalProgressBarWithNumber pb;
|
||||
private AppCompatImageButton delBt;
|
||||
private Button handleBt;
|
||||
private OnProgressLayoutBtListener listener;
|
||||
private AbsEntity entity;
|
||||
private int currentState;
|
||||
private final String TAG = "ProgressLayout";
|
||||
private TextView speedOrState, fileName, leftTime, fileSize;
|
||||
private HorizontalProgressBarWithNumber pb;
|
||||
private AppCompatImageButton delBt;
|
||||
private Button handleBt;
|
||||
private OnProgressLayoutBtListener listener;
|
||||
private AbsEntity entity;
|
||||
private int currentState;
|
||||
|
||||
public interface OnProgressLayoutBtListener {
|
||||
/**
|
||||
* 处理创建操作
|
||||
*/
|
||||
void create(View v, AbsEntity entity);
|
||||
public interface OnProgressLayoutBtListener {
|
||||
/**
|
||||
* 处理创建操作
|
||||
*/
|
||||
void create(View v, AbsEntity entity);
|
||||
|
||||
/**
|
||||
* 处理任务暂停的操作
|
||||
*/
|
||||
void stop(View v, AbsEntity entity);
|
||||
/**
|
||||
* 处理任务暂停的操作
|
||||
*/
|
||||
void stop(View v, AbsEntity entity);
|
||||
|
||||
/**
|
||||
* 处理恢复任务的操作
|
||||
*/
|
||||
void resume(View v, AbsEntity entity);
|
||||
/**
|
||||
* 处理恢复任务的操作
|
||||
*/
|
||||
void resume(View v, AbsEntity entity);
|
||||
|
||||
/**
|
||||
* 处理任务删除的操作
|
||||
*/
|
||||
void cancel(View v, AbsEntity entity);
|
||||
}
|
||||
|
||||
public ProgressLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ProgressLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, -1);
|
||||
}
|
||||
|
||||
public ProgressLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
LayoutInflater.from(context).inflate(R.layout.layout_progress_content, this, true);
|
||||
speedOrState = findViewById(R.id.speed_or_state);
|
||||
fileName = findViewById(R.id.file_name);
|
||||
leftTime = findViewById(R.id.left_time);
|
||||
fileSize = findViewById(R.id.file_size);
|
||||
pb = findViewById(R.id.pb);
|
||||
delBt = findViewById(R.id.del_bt);
|
||||
handleBt = findViewById(R.id.handle_bt);
|
||||
delBt.setOnClickListener(this);
|
||||
handleBt.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setBtListener(OnProgressLayoutBtListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
if (listener == null) {
|
||||
ALog.e(TAG, "没有设置OnProgressLayoutBtListener");
|
||||
return;
|
||||
}
|
||||
if (entity == null) {
|
||||
ALog.d(TAG, "entity 为空,请设置信息");
|
||||
return;
|
||||
/**
|
||||
* 处理任务删除的操作
|
||||
*/
|
||||
void cancel(View v, AbsEntity entity);
|
||||
}
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.del_bt:
|
||||
listener.cancel(v, entity);
|
||||
initState();
|
||||
break;
|
||||
case R.id.handle_bt:
|
||||
handleTask(v);
|
||||
break;
|
||||
public ProgressLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void initState() {
|
||||
fileName.setText("-");
|
||||
leftTime.setText("");
|
||||
speedOrState.setText("");
|
||||
fileSize.setText("-/-");
|
||||
pb.setProgress(0);
|
||||
}
|
||||
public ProgressLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, -1);
|
||||
}
|
||||
|
||||
private void handleTask(View v) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
listener.resume(v, entity);
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
case IEntity.STATE_WAIT:
|
||||
if (entity.getId() != -1) {
|
||||
listener.resume(v, entity);
|
||||
} else {
|
||||
listener.create(v, entity);
|
||||
public ProgressLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
LayoutInflater.from(context).inflate(R.layout.layout_progress_content, this, true);
|
||||
speedOrState = findViewById(R.id.speed_or_state);
|
||||
fileName = findViewById(R.id.file_name);
|
||||
leftTime = findViewById(R.id.left_time);
|
||||
fileSize = findViewById(R.id.file_size);
|
||||
pb = findViewById(R.id.pb);
|
||||
delBt = findViewById(R.id.del_bt);
|
||||
handleBt = findViewById(R.id.handle_bt);
|
||||
delBt.setOnClickListener(this);
|
||||
handleBt.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setBtListener(OnProgressLayoutBtListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener == null) {
|
||||
ALog.e(TAG, "没有设置OnProgressLayoutBtListener");
|
||||
return;
|
||||
}
|
||||
if (entity == null) {
|
||||
ALog.d(TAG, "entity 为空,请设置信息");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_RUNNING:
|
||||
listener.stop(v, entity);
|
||||
break;
|
||||
default:
|
||||
listener.create(v, entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setInfo(AbsEntity entity) {
|
||||
this.entity = entity;
|
||||
this.currentState = entity.getState();
|
||||
if (entity instanceof AbsNormalEntity) {
|
||||
AbsNormalEntity normalEntity = (AbsNormalEntity) entity;
|
||||
//ALog.d(TAG, "fileName = " + ((AbsNormalEntity) entity).getFileName());
|
||||
fileName.setText(normalEntity.getFileName());
|
||||
} else if (entity instanceof AbsGroupEntity) {
|
||||
AbsGroupEntity groupEntity = (AbsGroupEntity) entity;
|
||||
fileName.setText(
|
||||
groupEntity.getAlias() == null ? groupEntity.getKey() : groupEntity.getAlias());
|
||||
int id = v.getId();
|
||||
if (id == R.id.del_bt) {
|
||||
listener.cancel(v, entity);
|
||||
initState();
|
||||
} else if (id == R.id.handle_bt) {
|
||||
handleTask(v);
|
||||
}
|
||||
}
|
||||
|
||||
String str =
|
||||
formatFileSize(entity.getCurrentProgress()) + "/" + formatFileSize(entity.getFileSize());
|
||||
fileSize.setText(str);
|
||||
leftTime.setText(CommonUtil.formatTime(entity.getTimeLeft()));
|
||||
String btStr = getResources().getString(R.string.start);
|
||||
String stateStr = "";
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_WAIT:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = getResources().getString(R.string.waiting);
|
||||
break;
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = getResources().getString(R.string.state_error);
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
btStr = getResources().getString(R.string.resume);
|
||||
stateStr = getResources().getString(R.string.stopped);
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_RUNNING:
|
||||
btStr = getResources().getString(R.string.stop);
|
||||
stateStr = entity.getConvertSpeed();
|
||||
leftTime.setText(CommonUtil.formatTime(entity.getTimeLeft()));
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
btStr = getResources().getString(R.string.re_start);
|
||||
stateStr = getResources().getString(R.string.completed);
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
initState();
|
||||
break;
|
||||
default:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = "";
|
||||
private void initState() {
|
||||
fileName.setText("-");
|
||||
leftTime.setText("");
|
||||
}
|
||||
this.handleBt.setText(btStr);
|
||||
this.speedOrState.setText(stateStr);
|
||||
if (entity.getState() != IEntity.STATE_CANCEL){
|
||||
this.pb.setProgress(entity.getPercent());
|
||||
}
|
||||
}
|
||||
|
||||
public void setFileName(Character fileName) {
|
||||
this.fileName.setText(fileName);
|
||||
}
|
||||
|
||||
public void setLeftTime(Character leftTime) {
|
||||
this.leftTime.setText(leftTime);
|
||||
}
|
||||
|
||||
public void setFileSize(Character fileSize) {
|
||||
this.fileSize.setText(fileSize);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.pb.setProgress(progress);
|
||||
}
|
||||
|
||||
public void setSpeed(Character speed) {
|
||||
this.speedOrState.setText(speed);
|
||||
}
|
||||
|
||||
public void setState(Character state) {
|
||||
this.speedOrState.setText(state);
|
||||
}
|
||||
|
||||
public String formatFileSize(double size) {
|
||||
if (size < 0) {
|
||||
return "0k";
|
||||
}
|
||||
double kiloByte = size / 1024;
|
||||
if (kiloByte < 1) {
|
||||
return size + "b";
|
||||
speedOrState.setText("");
|
||||
fileSize.setText("-/-");
|
||||
pb.setProgress(0);
|
||||
}
|
||||
|
||||
double megaByte = kiloByte / 1024;
|
||||
if (megaByte < 1) {
|
||||
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
|
||||
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "k";
|
||||
private void handleTask(View v) {
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
case IEntity.STATE_STOP:
|
||||
listener.resume(v, entity);
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
case IEntity.STATE_WAIT:
|
||||
if (entity.getId() != -1) {
|
||||
listener.resume(v, entity);
|
||||
} else {
|
||||
listener.create(v, entity);
|
||||
}
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_RUNNING:
|
||||
listener.stop(v, entity);
|
||||
break;
|
||||
default:
|
||||
listener.create(v, entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double gigaByte = megaByte / 1024;
|
||||
if (gigaByte < 1) {
|
||||
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
|
||||
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "m";
|
||||
public void setInfo(AbsEntity entity) {
|
||||
this.entity = entity;
|
||||
this.currentState = entity.getState();
|
||||
if (entity instanceof AbsNormalEntity) {
|
||||
AbsNormalEntity normalEntity = (AbsNormalEntity) entity;
|
||||
//ALog.d(TAG, "fileName = " + ((AbsNormalEntity) entity).getFileName());
|
||||
fileName.setText(normalEntity.getFileName());
|
||||
} else if (entity instanceof AbsGroupEntity) {
|
||||
AbsGroupEntity groupEntity = (AbsGroupEntity) entity;
|
||||
fileName.setText(
|
||||
groupEntity.getAlias() == null ? groupEntity.getKey() : groupEntity.getAlias());
|
||||
}
|
||||
|
||||
String str =
|
||||
formatFileSize(entity.getCurrentProgress()) + "/" + formatFileSize(entity.getFileSize());
|
||||
fileSize.setText(str);
|
||||
leftTime.setText(CommonUtil.formatTime(entity.getTimeLeft()));
|
||||
String btStr = getResources().getString(R.string.start);
|
||||
String stateStr = "";
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_WAIT:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = getResources().getString(R.string.waiting);
|
||||
break;
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = getResources().getString(R.string.state_error);
|
||||
break;
|
||||
case IEntity.STATE_STOP:
|
||||
btStr = getResources().getString(R.string.resume);
|
||||
stateStr = getResources().getString(R.string.stopped);
|
||||
break;
|
||||
case IEntity.STATE_PRE:
|
||||
case IEntity.STATE_POST_PRE:
|
||||
case IEntity.STATE_RUNNING:
|
||||
btStr = getResources().getString(R.string.stop);
|
||||
stateStr = entity.getConvertSpeed();
|
||||
leftTime.setText(CommonUtil.formatTime(entity.getTimeLeft()));
|
||||
break;
|
||||
case IEntity.STATE_COMPLETE:
|
||||
btStr = getResources().getString(R.string.re_start);
|
||||
stateStr = getResources().getString(R.string.completed);
|
||||
break;
|
||||
case IEntity.STATE_CANCEL:
|
||||
initState();
|
||||
break;
|
||||
default:
|
||||
btStr = getResources().getString(R.string.start);
|
||||
stateStr = "";
|
||||
leftTime.setText("");
|
||||
}
|
||||
this.handleBt.setText(btStr);
|
||||
this.speedOrState.setText(stateStr);
|
||||
if (entity.getState() != IEntity.STATE_CANCEL) {
|
||||
this.pb.setProgress(entity.getPercent());
|
||||
}
|
||||
}
|
||||
|
||||
double teraBytes = gigaByte / 1024;
|
||||
if (teraBytes < 1) {
|
||||
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
|
||||
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "g";
|
||||
public void setFileName(Character fileName) {
|
||||
this.fileName.setText(fileName);
|
||||
}
|
||||
|
||||
public void setLeftTime(Character leftTime) {
|
||||
this.leftTime.setText(leftTime);
|
||||
}
|
||||
|
||||
public void setFileSize(Character fileSize) {
|
||||
this.fileSize.setText(fileSize);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.pb.setProgress(progress);
|
||||
}
|
||||
|
||||
public void setSpeed(Character speed) {
|
||||
this.speedOrState.setText(speed);
|
||||
}
|
||||
|
||||
public void setState(Character state) {
|
||||
this.speedOrState.setText(state);
|
||||
}
|
||||
|
||||
public String formatFileSize(double size) {
|
||||
if (size < 0) {
|
||||
return "0k";
|
||||
}
|
||||
double kiloByte = size / 1024;
|
||||
if (kiloByte < 1) {
|
||||
return size + "b";
|
||||
}
|
||||
|
||||
double megaByte = kiloByte / 1024;
|
||||
if (megaByte < 1) {
|
||||
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
|
||||
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "k";
|
||||
}
|
||||
|
||||
double gigaByte = megaByte / 1024;
|
||||
if (gigaByte < 1) {
|
||||
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
|
||||
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "m";
|
||||
}
|
||||
|
||||
double teraBytes = gigaByte / 1024;
|
||||
if (teraBytes < 1) {
|
||||
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
|
||||
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "g";
|
||||
}
|
||||
BigDecimal result4 = new BigDecimal(teraBytes);
|
||||
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "t";
|
||||
}
|
||||
BigDecimal result4 = new BigDecimal(teraBytes);
|
||||
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "t";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ ext {
|
||||
mavenCentralDeveloperConnection = 'scm:git:ssh://github.com/AriaLyy/Aria.git'
|
||||
mavenCentralTreeURL = 'https://github.com/AriaLyy/KeepassA/tree/master'
|
||||
|
||||
compileSdkVersion = 28
|
||||
compileSdkVersion = 36
|
||||
supportLibVersion = "27.1.1"
|
||||
buildToolsVersion = "29.0.2"
|
||||
targetSdkVersion = 28
|
||||
buildToolsVersion = "36.0.0"
|
||||
targetSdkVersion = 36
|
||||
lifecycleVersion = "1.1.1"
|
||||
minSdkVersion = 15
|
||||
|
||||
|
||||
@@ -82,17 +82,20 @@ afterEvaluate { project ->
|
||||
release(MavenPublication) {
|
||||
// groupId 等信息
|
||||
groupId PUBLISH_GROUP_ID
|
||||
artifactId PUBLISH_ARTIFACT_ID
|
||||
artifactId project.PUBLISH_ARTIFACT_ID
|
||||
version PUBLISH_VERSION
|
||||
|
||||
if (isAndroidProject) {
|
||||
// 移除R文件,移除BuildConfig文件
|
||||
generateReleaseBuildConfig.enabled = false
|
||||
generateDebugBuildConfig.enabled = false
|
||||
generateReleaseResValues.enabled = false
|
||||
generateDebugResValues.enabled = false
|
||||
project.tasks.findByName('generateReleaseBuildConfig')?.enabled = false
|
||||
project.tasks.findByName('generateDebugBuildConfig')?.enabled = false
|
||||
project.tasks.findByName('generateReleaseResValues')?.enabled = false
|
||||
project.tasks.findByName('generateDebugResValues')?.enabled = false
|
||||
// 使用了这个组件,就不需要自己aar、pom.withxml了
|
||||
from components.release
|
||||
def releaseComponent = project.components.findByName('release')
|
||||
if (releaseComponent != null) {
|
||||
from releaseComponent
|
||||
}
|
||||
|
||||
def variants = project.android.libraryVariants.findAll {
|
||||
it.buildType.name.equalsIgnoreCase('debug')
|
||||
@@ -102,15 +105,15 @@ afterEvaluate { project ->
|
||||
|
||||
def getAndroidJar = "${getAndroidSdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar"
|
||||
|
||||
task androidJavadocs(type: Javadoc, dependsOn: assembleDebug) {
|
||||
def androidJavadocs = project.task("androidJavadocs", type: Javadoc, dependsOn: 'assembleDebug') {
|
||||
println("开始打包aar")
|
||||
source = variants.collect { it.getJavaCompileProvider().get().source }
|
||||
classpath = files(
|
||||
classpath = project.files(
|
||||
getAndroidJar,
|
||||
project.file("build/intermediates/classes/debug")
|
||||
)
|
||||
doFirst {
|
||||
classpath += files(variants.collect { it.javaCompile.classpath.files })
|
||||
classpath += project.files(variants.collect { it.javaCompile.classpath.files })
|
||||
}
|
||||
options {
|
||||
links("http://docs.oracle.com/javase/7/docs/api/")
|
||||
@@ -125,30 +128,31 @@ afterEvaluate { project ->
|
||||
exclude "**/BuildConfig.class"
|
||||
}
|
||||
|
||||
def cleanJavadocTask = task("cleanJavadocTask", type: Delete) {
|
||||
def cleanJavadocTask = project.task("cleanJavadocTask", type: Delete) {
|
||||
delete androidJavadocs.destinationDir
|
||||
} as Task
|
||||
}
|
||||
project.clean.dependsOn(cleanJavadocTask)
|
||||
|
||||
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
|
||||
classifier = 'javadoc'
|
||||
from androidJavadocs.destinationDir
|
||||
baseName "${JAR_PREFIX}${project.name}"
|
||||
def androidJavadocsJar = project.task("androidJavadocsJar", type: Jar, dependsOn: androidJavadocs) {
|
||||
archiveClassifier = 'javadoc'
|
||||
archiveBaseName = "${JAR_PREFIX}${project.name}"
|
||||
}
|
||||
|
||||
task androidSourcesJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
def androidSourcesJar = project.task("androidSourcesJar", type: Jar) {
|
||||
archiveClassifier = 'sources'
|
||||
from project.android.sourceSets.main.java.source
|
||||
baseName "${JAR_PREFIX}${project.name}"
|
||||
archiveBaseName = "${JAR_PREFIX}${project.name}"
|
||||
|
||||
exclude "**/R.class"
|
||||
exclude "**/BuildConfig.class"
|
||||
}
|
||||
|
||||
task androidLibraryJar(type: Jar, dependsOn: compileDebugJavaWithJavac
|
||||
/* == variant.javaCompile */) {
|
||||
def compileDebugJavaWithJavac = project.tasks.findByName('compileDebugJavaWithJavac')
|
||||
def androidLibraryJar = project.task("androidLibraryJar", type: Jar, dependsOn: 'compileDebugJavaWithJavac') {
|
||||
// java 编译后的 class文件, build/intermediates/classes/debug/
|
||||
from compileDebugJavaWithJavac.destinationDir
|
||||
if (compileDebugJavaWithJavac != null) {
|
||||
from compileDebugJavaWithJavac.destinationDir
|
||||
}
|
||||
// kotlin 编译后的 class文件
|
||||
from 'build/tmp/kotlin-classes/debug/'
|
||||
// 指定需要被打包成 jar 的文件夹
|
||||
@@ -156,7 +160,7 @@ afterEvaluate { project ->
|
||||
exclude '**/R.class'
|
||||
exclude '**/R$*.class'
|
||||
exclude "**/BuildConfig.class"
|
||||
baseName "${JAR_PREFIX}${project.name}-cache"
|
||||
archiveBaseName = "${JAR_PREFIX}${project.name}-cache"
|
||||
}
|
||||
|
||||
artifact androidLibraryJar
|
||||
@@ -164,16 +168,19 @@ afterEvaluate { project ->
|
||||
artifact androidJavadocsJar
|
||||
|
||||
} else if (project.plugins.hasPlugin('java')) {
|
||||
from components.java
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
def javaComponent = project.components.findByName('java')
|
||||
if (javaComponent != null) {
|
||||
from javaComponent
|
||||
}
|
||||
|
||||
task javadocsJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
def sourcesJar = project.task("sourcesJar", type: Jar, dependsOn: 'classes') {
|
||||
archiveClassifier = 'sources'
|
||||
from project.sourceSets.main.allSource
|
||||
}
|
||||
|
||||
def javadocsJar = project.task("javadocsJar", type: Jar, dependsOn: 'javadoc') {
|
||||
archiveClassifier = 'javadoc'
|
||||
from project.javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifact sourcesJar
|
||||
@@ -181,7 +188,7 @@ afterEvaluate { project ->
|
||||
}
|
||||
|
||||
pom {
|
||||
name = PUBLISH_ARTIFACT_ID
|
||||
name = project.PUBLISH_ARTIFACT_ID
|
||||
description = rootProject.ext.desc
|
||||
url = rootProject.ext.website
|
||||
licenses {
|
||||
|
||||
Reference in New Issue
Block a user