1、修复restart的一个空指针问题

2、优化Ftp demo的代码
v3.6.6
laoyuyu 6 years ago
parent 7b15d4c052
commit f0bc470b75
  1. 30
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  2. 1
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java
  3. 11
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DNormalDelegate.java
  5. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  6. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  7. 22
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
  8. 17
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  9. 10
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java
  10. 2
      app/src/main/assets/help_code/FtpDownload.java
  11. 92
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  12. 111
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadModule.java
  13. 23
      app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  14. 6
      app/src/main/java/com/arialyy/simple/core/download/KotlinDownloadActivity.kt
  15. 13
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  16. 52
      app/src/main/res/layout/activity_ftp_download.xml
  17. 2
      build.gradle

@ -81,7 +81,11 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
* 发送等待状态
*/
void sendWaitState() {
sendWaitState(getTask());
AbsTask task = getTask();
if (task == null) {
task = createTask();
}
sendWaitState(task);
}
/**
@ -105,14 +109,22 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
* 停止任务
*/
void stopTask() {
mQueue.stopTask(getTask());
AbsTask task = getTask();
if (task == null) {
task = createTask();
}
mQueue.stopTask(task);
}
/**
* 删除任务
*/
void removeTask() {
mQueue.cancelTask(getTask());
AbsTask task = getTask();
if (task == null) {
task = createTask();
}
mQueue.cancelTask(task);
}
/**
@ -130,14 +142,22 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
* 启动任务
*/
void startTask() {
mQueue.startTask(getTask());
AbsTask task = getTask();
if (task == null){
task = createTask();
}
mQueue.startTask(task);
}
/**
* 恢复任务
*/
void resumeTask() {
mQueue.resumeTask(getTask());
AbsTask task = getTask();
if (task == null){
task = createTask();
}
mQueue.resumeTask(task);
}
/**

@ -36,6 +36,7 @@ class StopCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
AbsTask task = getTask();
if (task == null) {
if (mTaskWrapper.getEntity().getState() == IEntity.STATE_RUNNING) {
createTask();
stopTask();
} else {
ALog.w(TAG, "停止命令执行失败,【调度器中没有该任务】");

@ -56,8 +56,15 @@ public class BaseDListener extends BaseListener<DownloadEntity, DTaskWrapper, Do
mEntity.setState(state);
if (state == IEntity.STATE_CANCEL) {
CommonUtil.delTaskRecord(mEntity.getDownloadPath(), 1, mTaskWrapper.isRemoveFile(),
getTask().getSchedulerType() != TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY);
int sType = getTask().getSchedulerType();
if (sType == TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY) {
mEntity.setComplete(false);
mEntity.setState(IEntity.STATE_WAIT);
CommonUtil.delTaskRecord(mEntity.getFilePath(), 1, mTaskWrapper.isRemoveFile(), false);
} else {
CommonUtil.delTaskRecord(mEntity.getFilePath(), 1, mTaskWrapper.isRemoveFile(), true);
}
return;
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());

@ -128,7 +128,7 @@ class DNormalDelegate<TARGET extends AbsDTarget> implements INormalTarget {
}
//设置文件保存路径,如果新文件路径和旧文件路径不同,则修改路径
if (!filePath.equals(mEntity.getDownloadPath())) {
if (!filePath.equals(mEntity.getFilePath())) {
// 检查路径冲突
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) {
if (!forceDownload) {

@ -111,8 +111,16 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
return downloadPath;
}
/**
* 后面会删除该方法请使用{@link #setFilePath(String)}
*/
@Deprecated
public DownloadEntity setDownloadPath(String downloadPath) {
this.downloadPath = downloadPath;
return setFilePath(downloadPath);
}
public DownloadEntity setFilePath(String filePath) {
this.downloadPath = filePath;
return this;
}

@ -135,8 +135,14 @@ class DownloadGroupListener
mTaskWrapper.setState(state);
mEntity.setState(state);
if (state == IEntity.STATE_CANCEL) {
CommonUtil.delGroupTaskRecord(mEntity, mTaskWrapper.isRemoveFile(),
getTask().getSchedulerType() != TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY);
int sType = getTask().getSchedulerType();
if (sType == TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY) {
mEntity.setComplete(false);
mEntity.setState(IEntity.STATE_WAIT);
CommonUtil.delGroupTaskRecord(mEntity, mTaskWrapper.isRemoveFile(), false);
} else {
CommonUtil.delGroupTaskRecord(mEntity, mTaskWrapper.isRemoveFile(), true);
}
return;
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());

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

@ -71,6 +71,10 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
* @param task 需要恢复的任务
*/
@Override public void resumeTask(TASK task) {
if (task == null){
ALog.w(TAG, "resume task fail, task is null");
return;
}
if (mExecutePool.size() >= getMaxTaskNum()) {
task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT);
mCachePool.putTaskToFirst(task);
@ -204,12 +208,19 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
* @param task {@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}
*/
void addTask(TASK task) {
if (task == null){
ALog.w(TAG, "add task fail, task is null");
return;
}
if (!mCachePool.taskExits(task.getKey())) {
mCachePool.putTask(task);
}
}
@Override public void startTask(TASK task) {
if (task == null){
ALog.w(TAG, "start fail, task is null");
}
if (mExecutePool.taskExits(task.getKey())) {
ALog.w(TAG, String.format("任务【%s】执行中", task.getKey()));
return;
@ -221,6 +232,10 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
}
@Override public void stopTask(TASK task) {
if (task == null) {
ALog.w(TAG, "stop fail, task is null");
return;
}
int state = task.getState();
boolean canStop = false;
switch (state) {
@ -267,7 +282,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
@Override public void reTryStart(TASK task) {
if (task == null) {
ALog.e(TAG, "任务重试失败,原因:task 为null");
ALog.e(TAG, "reTry fail, task is null");
return;
}

@ -37,8 +37,14 @@ class BaseUListener extends BaseListener<UploadEntity, UTaskWrapper, UploadTask>
mTaskWrapper.setState(state);
mEntity.setState(state);
if (state == IEntity.STATE_CANCEL) {
CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskWrapper.isRemoveFile(),
getTask().getSchedulerType() != TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY);
int sType = getTask().getSchedulerType();
if (sType == TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY) {
mEntity.setComplete(false);
mEntity.setState(IEntity.STATE_WAIT);
CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskWrapper.isRemoveFile(), false);
} else {
CommonUtil.delTaskRecord(mEntity.getFilePath(), 2, mTaskWrapper.isRemoveFile(), true);
}
} else if (state == IEntity.STATE_STOP) {
mEntity.setStopTime(System.currentTimeMillis());
} else if (state == IEntity.STATE_COMPLETE) {

@ -19,7 +19,7 @@ import java.io.File;
public class FtpDownload extends BaseActivity<ActivityTestBinding> {
String TAG = "TestFTPActivity";
private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar";
private final String FILE_PATH = "/mnt/sdcard/";
@Override protected int setLayoutId() {
return R.layout.activity_test;

@ -15,64 +15,110 @@
*/
package com.arialyy.simple.core.download;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.FtpDownloadTarget;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.common.DirChooseDialog;
import com.arialyy.simple.common.ModifyUrlDialog;
import com.arialyy.simple.databinding.ActivityFtpDownloadBinding;
import com.arialyy.simple.util.AppUtil;
import java.io.File;
import java.io.IOException;
/**
* Created by lyy on 2017/7/25.
* Ftp下载测试
* Ftp下载
*/
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
private final String URL = "ftp://9.9.9.205:2121/Cyberduck-6.9.4.30164.zip";
//private final String URL = "ftp://182.92.180.213:21/video/572fed5c2ad48_1024.jpg";
//private final String URL = "ftp://182.92.180.213:21/DATA/20180205/rar/1111.rar";
//private final String URL = "ftp://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4";
private String mUrl, mFilePath;
private FtpDownloadModule mModule;
private FtpDownloadTarget mTarget;
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTitle("FTP文件下载");
Aria.download(this).register();
DownloadEntity entity = Aria.download(this).getDownloadEntity(URL);
if (entity != null) {
getBinding().setFileSize(entity.getConvertFileSize());
if (entity.getFileSize() == 0) {
getBinding().setProgress(0);
} else {
mModule = ViewModelProviders.of(this).get(FtpDownloadModule.class);
mModule.getFtpDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
@Override public void onChanged(@Nullable DownloadEntity entity) {
if (entity == null) {
return;
}
mTarget = Aria.download(FtpDownloadActivity.this).loadFtp(entity.getUrl());
if (mTarget.getTaskState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume));
} else if (mTarget.isRunning()) {
getBinding().setStateStr(getString(R.string.stop));
}
if (entity.getFileSize() != 0) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
getBinding().setUrl(entity.getUrl());
getBinding().setFilePath(entity.getFilePath());
mUrl = entity.getUrl();
mFilePath = entity.getFilePath();
}
});
getBinding().setViewModel(this);
try {
getBinding().codeView.setSource(AppUtil.getHelpCode(this, "FtpDownload.java"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.download(this).loadFtp(URL)
.login("N0rI", "0qcK")
.setFilePath("/mnt/sdcard/", true)
if (mTarget.isRunning()) {
getBinding().setStateStr(getString(R.string.resume));
Aria.download(this).loadFtp(mUrl).stop();
} else {
getBinding().setStateStr(getString(R.string.stop));
Aria.download(this).loadFtp(mUrl).login("N0rI", "0qcK")
.setFilePath(mFilePath, true)
.start();
break;
case R.id.stop:
Aria.download(this).loadFtp(URL).stop();
}
break;
case R.id.cancel:
Aria.download(this).loadFtp(URL).cancel();
Aria.download(this).loadFtp(mUrl).cancel();
break;
}
}
public void chooseUrl() {
ModifyUrlDialog dialog =
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);
dialog.show(getSupportFragmentManager(), "ModifyUrlDialog");
}
public void chooseFilePath() {
DirChooseDialog dirChooseDialog = new DirChooseDialog(this);
dirChooseDialog.show(getSupportFragmentManager(), "DirChooseDialog");
}
@Download.onPre() protected void onPre(DownloadTask task) {
L.d(TAG, "ftp pre");
}
@ -119,4 +165,14 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
@Override protected int setLayoutId() {
return R.layout.activity_ftp_download;
}
@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 == DirChooseDialog.DIR_CHOOSE_DIALOG_RESULT) {
mModule.updateFilePath(this, String.valueOf(data));
}
}
}

@ -0,0 +1,111 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.simple.core.download;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.frame.base.BaseViewModule;
import com.arialyy.simple.util.AppUtil;
import java.io.File;
public class FtpDownloadModule extends BaseViewModule {
private final String FTP_URL_KEY = "FTP_URL_KEY";
private final String FTP_PATH_KEY = "FTP_PATH_KEY";
private final String ftpDefUrl = "ftp://9.9.9.205:2121/Cyberduck-6.9.4.30164.zip";
private final String ftpDefPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
private MutableLiveData<DownloadEntity> liveData = new MutableLiveData<>();
private DownloadEntity singDownloadInfo;
/**
* xx
* 单任务下载的信息
*/
LiveData<DownloadEntity> getFtpDownloadInfo(Context context) {
String url = AppUtil.getConfigValue(context, FTP_URL_KEY, ftpDefUrl);
String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, ftpDefPath);
singDownloadInfo = Aria.download(context).getDownloadEntity(url);
if (singDownloadInfo == null) {
singDownloadInfo = new DownloadEntity();
singDownloadInfo.setUrl(url);
String name = getFileName(ftpDefUrl);
singDownloadInfo.setFileName(name);
singDownloadInfo.setFilePath(filePath + name);
} else {
AppUtil.setConfigValue(context, FTP_PATH_KEY, singDownloadInfo.getFilePath());
AppUtil.setConfigValue(context, FTP_URL_KEY, singDownloadInfo.getUrl());
}
liveData.postValue(singDownloadInfo);
return liveData;
}
/**
* 更新文件保存路径
*
* @param dirPath 文件保存文件夹
*/
void updateFilePath(Context context, String dirPath) {
if (TextUtils.isEmpty(dirPath)) {
ALog.e(TAG, "文件保存路径为空");
return;
}
AppUtil.setConfigValue(context, FTP_PATH_KEY, dirPath);
singDownloadInfo.setFilePath(dirPath + singDownloadInfo.getFileName());
liveData.postValue(singDownloadInfo);
}
/**
* 更新url
*/
void uploadUrl(Context context, String url) {
if (TextUtils.isEmpty(url)) {
ALog.e(TAG, "下载地址为空");
return;
}
AppUtil.setConfigValue(context, FTP_URL_KEY, url);
File file = new File(singDownloadInfo.getFilePath());
String name = getFileName(url);
singDownloadInfo.setFilePath(file.getParent() + name);
singDownloadInfo.setFileName(name);
singDownloadInfo.setUrl(url);
liveData.postValue(singDownloadInfo);
}
/**
* 通过url获取文件名
*
* @param url ftp地址
* @return "/aria.text"
*/
private String getFileName(String url) {
Uri uri = Uri.parse(url);
String path = uri.getPath();
int index = path.lastIndexOf("/");
return path.substring(index);
}
}

@ -28,14 +28,15 @@ import com.arialyy.frame.base.BaseViewModule;
import com.arialyy.simple.util.AppUtil;
import java.io.File;
public class DownloadModule1 extends BaseViewModule {
private final String DOWNLOAD_URL_KEY = "DOWNLOAD_URL_KEY";
private final String DOWNLOAD_PATH_KEY = "DOWNLOAD_PATH_KEY";
public class HttpDownloadModule extends BaseViewModule {
private final String HTTP_URL_KEY = "HTTP_URL_KEY";
private final String HTTP_PATH_KEY = "HTTP_PATH_KEY";
private final String defUrl =
"http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk";
private final String defFilePath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
+ "/test.apk";
private MutableLiveData<DownloadEntity> liveData = new MutableLiveData<>();
private DownloadEntity singDownloadInfo;
@ -43,9 +44,9 @@ public class DownloadModule1 extends BaseViewModule {
/**
* 单任务下载的信息
*/
LiveData<DownloadEntity> getSingDownloadInfo(Context context) {
String url = AppUtil.getConfigValue(context, DOWNLOAD_URL_KEY, defUrl);
String filePath = AppUtil.getConfigValue(context, DOWNLOAD_PATH_KEY, defFilePath);
LiveData<DownloadEntity> getHttpDownloadInfo(Context context) {
String url = AppUtil.getConfigValue(context, HTTP_URL_KEY, defUrl);
String filePath = AppUtil.getConfigValue(context, HTTP_PATH_KEY, defFilePath);
singDownloadInfo = Aria.download(context).getDownloadEntity(url);
if (singDownloadInfo == null) {
@ -55,8 +56,8 @@ public class DownloadModule1 extends BaseViewModule {
singDownloadInfo.setDownloadPath(filePath);
singDownloadInfo.setFileName(temp.getName());
} else {
AppUtil.setConfigValue(context, DOWNLOAD_PATH_KEY, singDownloadInfo.getDownloadPath());
AppUtil.setConfigValue(context, DOWNLOAD_URL_KEY, singDownloadInfo.getUrl());
AppUtil.setConfigValue(context, HTTP_PATH_KEY, singDownloadInfo.getDownloadPath());
AppUtil.setConfigValue(context, HTTP_URL_KEY, singDownloadInfo.getUrl());
}
liveData.postValue(singDownloadInfo);
@ -74,7 +75,7 @@ public class DownloadModule1 extends BaseViewModule {
return;
}
File temp = new File(filePath);
AppUtil.setConfigValue(context, DOWNLOAD_PATH_KEY, filePath);
AppUtil.setConfigValue(context, HTTP_PATH_KEY, filePath);
singDownloadInfo.setFileName(temp.getName());
singDownloadInfo.setDownloadPath(filePath);
liveData.postValue(singDownloadInfo);
@ -88,7 +89,7 @@ public class DownloadModule1 extends BaseViewModule {
ALog.e(TAG, "下载地址为空");
return;
}
AppUtil.setConfigValue(context, DOWNLOAD_URL_KEY, url);
AppUtil.setConfigValue(context, HTTP_URL_KEY, url);
singDownloadInfo.setUrl(url);
liveData.postValue(singDownloadInfo);
}

@ -53,7 +53,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
private var mUrl: String? = null
private var mFilePath: String? = null
private var mModule: DownloadModule1? = null
private var mModule: HttpDownloadModule? = null
private var mTarget: DownloadTarget? = null
internal var receiver: BroadcastReceiver = object : BroadcastReceiver() {
@ -93,8 +93,8 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
Aria.download(this)
.register()
mModule = ViewModelProviders.of(this)
.get(DownloadModule1::class.java)
mModule!!.getSingDownloadInfo(this)
.get(HttpDownloadModule::class.java)
mModule!!.getHttpDownloadInfo(this)
.observe(this, Observer { entity ->
if (entity == null) {
return@Observer

@ -55,7 +55,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private String mUrl;
private String mFilePath;
private DownloadModule1 mModule;
private HttpDownloadModule mModule;
private DownloadTarget mTarget;
BroadcastReceiver receiver = new BroadcastReceiver() {
@ -89,8 +89,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
super.init(savedInstanceState);
setTitle("单任务下载");
Aria.download(this).register();
mModule = ViewModelProviders.of(this).get(DownloadModule1.class);
mModule.getSingDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
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) {
@ -194,6 +194,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
void taskStart(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().setFileSize(task.getConvertFileSize());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
}
}
@ -236,9 +237,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
}
/**
*
*/
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
if (task.getKey().equals(mUrl)) {
@ -274,9 +272,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
startD();
}
break;
case R.id.stop:
Aria.download(this).load(mUrl).stop();
break;
case R.id.cancel:
Aria.download(this).load(mUrl).cancel(true);
break;

@ -2,6 +2,7 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="fileSize"
@ -15,21 +16,70 @@
name="progress"
type="int"
/>
<variable
name="stateStr"
type="String"
/>
<variable
name="url"
type="String"
/>
<variable
name="filePath"
type="String"
/>
<variable
name="viewModel"
type="com.arialyy.simple.core.download.FtpDownloadActivity"
/>
</data>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".core.download.SingleTaskActivity"
>
<include layout="@layout/layout_bar"/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
bind:iconClickListener="@{() -> viewModel.chooseUrl()}"
bind:svg_text_view_icon="@drawable/ic_modify"
bind:text="@{@string/url(url)}"
/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
bind:iconClickListener="@{() -> viewModel.chooseFilePath()}"
bind:svg_text_view_icon="@drawable/ic_choose_file"
bind:text="@{@string/file_path(filePath)}"
/>
<include
layout="@layout/content_single"
layout="@layout/layout_content_single"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
bind:stateStr="@{stateStr}"
/>
<com.arialyy.simple.widget.CodeView
android:id="@+id/code_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>

@ -43,7 +43,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.6.5_dev_1'
publishVersion = '3.6.5_dev_4'
// publishVersion = '1.0.4' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save