任务组bug修复,修复子任务下载完成后重新下载的问题

pull/330/head
AriaLyy 7 years ago
parent b8a86890a7
commit 489f44c0f9
  1. 3
      Aria/build.gradle
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DListener.java
  3. 18
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  4. 71
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  5. 55
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  7. 68
      Aria/src/main/java/com/arialyy/aria/core/inf/IEventListener.java
  8. 54
      Aria/src/main/java/com/arialyy/aria/core/upload/IUploadListener.java
  9. 5
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadListener.java
  10. 17
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  11. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
  12. 14
      Aria/src/main/res/layout/activity_aria_file_shange.xml
  13. 51
      Aria/src/main/res/layout/item_file.xml
  14. 8
      Aria/src/main/res/values/strings.xml
  15. 7
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  16. 20
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  17. 2
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
  18. 45
      app/src/main/java/com/arialyy/simple/widget/SubStateLinearLayout.java
  19. 6
      app/src/main/res/layout/activity_download_group.xml
  20. 2
      app/src/main/res/layout/content_single.xml
  21. 5
      app/src/main/res/layout/item_group_download.xml
  22. 3
      app/src/main/res/layout/layout_child_state.xml
  23. 8
      app/src/main/res/values/strings.xml
  24. 1
      aria/src/main/AndroidManifest.xml
  25. 1
      aria/src/main/java/com/arialyy/aria/core/Configuration.java
  26. 2
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  27. 2
      build.gradle

@ -23,7 +23,6 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
// compile project(':AriaCompiler')
compile project(':AriaAnnotations')
compile project(':AriaAnnotations') //gradle
}
apply from: 'bintray-release.gradle'
//apply from: 'jcenter.gradle'

@ -28,7 +28,7 @@ import java.lang.ref.WeakReference;
/**
* 下载监听类
*/
final class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
extends DownloadListener {
private WeakReference<Handler> outHandler;
private long lastLen = 0; //上一次发送长度
@ -81,7 +81,6 @@ final class DListener<ENTITY extends AbsEntity, TASK extends AbsTask<ENTITY>>
}
@Override public void onStop(long stopLocation) {
//saveData(IEntity.STATE_STOP, stopLocation);
saveData(isWait ? IEntity.STATE_WAIT : IEntity.STATE_STOP, stopLocation);
handleSpeed(0);
sendInState2Target(ISchedulers.STOP);

@ -106,10 +106,11 @@ public class DownloadGroupUtil implements IDownloadUtil {
mTotalSize += entity.getFileSize();
mCompleteNum++;
mInitNum++;
mCurrentLocation += entity.getFileSize();
} else {
mExeMap.put(entity.getDownloadUrl(), createChildDownloadTask(entity));
mCurrentLocation += entity.getCurrentProgress();
}
mCurrentLocation += entity.getCurrentProgress();
}
}
@ -284,6 +285,7 @@ public class DownloadGroupUtil implements IDownloadUtil {
private DownloadTaskEntity createChildDownloadTask(DownloadEntity entity) {
DownloadTaskEntity taskEntity = mTasksMap.get(entity.getDownloadUrl());
if (taskEntity != null) {
taskEntity.entity = entity;
return taskEntity;
}
taskEntity = new DownloadTaskEntity();
@ -335,16 +337,21 @@ public class DownloadGroupUtil implements IDownloadUtil {
}
@Override public void onProgress(long currentLocation) {
mCurrentLocation += (currentLocation - lastLen);
long speed = currentLocation - lastLen;
mCurrentLocation += speed;
lastLen = currentLocation;
entity.setCurrentProgress(currentLocation);
handleSpeed(speed);
}
@Override public void onStop(long stopLocation) {
saveData(IEntity.STATE_STOP, stopLocation);
handleSpeed(0);
}
@Override public void onCancel() {
saveData(IEntity.STATE_CANCEL, -1);
handleSpeed(0);
}
@Override public void onComplete() {
@ -354,11 +361,13 @@ public class DownloadGroupUtil implements IDownloadUtil {
closeTimer();
mListener.onComplete();
}
handleSpeed(0);
}
@Override public void onFail() {
entity.setFailNum(entity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, -1);
handleSpeed(0);
reTry();
}
@ -374,6 +383,11 @@ public class DownloadGroupUtil implements IDownloadUtil {
}
}
private void handleSpeed(long speed) {
entity.setSpeed(speed);
entity.setConvertSpeed(speed <= 0 ? "" : CommonUtil.formatFileSize(speed) + "/s");
}
private void saveData(int state, long location) {
entity.setState(state);
entity.setComplete(state == IEntity.STATE_COMPLETE);

@ -90,28 +90,18 @@ class Downloader implements Runnable, IDownloadUtil {
mListener.onPostPre(mEntity.getFileSize());
mConstance.cleanState();
mConstance.isDownloading = true;
try {
if (!mTaskEntity.isSupportBP) {
mThreadNum = 1;
mConstance.THREAD_NUM = mThreadNum;
handleNoSupportBreakpointDownload();
} else {
mThreadNum = isNewTask ? (mEntity.getFileSize() <= SUB_LEN ? 1
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum())
: mRealThreadNum;
mConstance.THREAD_NUM = mThreadNum;
mFixedThreadPool = Executors.newFixedThreadPool(mThreadNum);
handleBreakpoint();
}
startTimer();
} catch (IOException e) {
failDownload("下载失败【downloadUrl:"
+ mEntity.getDownloadUrl()
+ "】\n【filePath:"
+ mEntity.getDownloadPath()
+ "】\n"
+ CommonUtil.getPrintException(e));
if (!mTaskEntity.isSupportBP) {
mThreadNum = 1;
mConstance.THREAD_NUM = mThreadNum;
handleNoSupportBreakpointDownload();
} else {
mThreadNum = isNewTask ? (mEntity.getFileSize() <= SUB_LEN ? 1
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum()) : mRealThreadNum;
mConstance.THREAD_NUM = mThreadNum;
mFixedThreadPool = Executors.newFixedThreadPool(mThreadNum);
handleBreakpoint();
}
startTimer();
}
/**
@ -170,6 +160,7 @@ class Downloader implements Runnable, IDownloadUtil {
@Override public void stopDownload() {
closeTimer();
if (mConstance.isComplete()) return;
mConstance.isStop = true;
mConstance.isDownloading = false;
if (mFixedThreadPool != null) {
@ -326,7 +317,7 @@ class Downloader implements Runnable, IDownloadUtil {
/**
* 处理断点
*/
private void handleBreakpoint() throws IOException {
private void handleBreakpoint() {
long fileLength = mEntity.getFileSize();
Properties pro = CommonUtil.loadConfig(mConfigFile);
int blockSize = (int) (fileLength / mThreadNum);
@ -336,14 +327,8 @@ class Downloader implements Runnable, IDownloadUtil {
}
int rl = 0;
if (isNewTask) {
CommonUtil.createFile(mTempFile.getPath());
BufferedRandomAccessFile file =
new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
//设置文件长度
file.setLength(fileLength);
file.close();
createNewFile(fileLength);
}
for (int i = 0; i < mThreadNum; i++) {
long startL = i * blockSize, endL = (i + 1) * blockSize;
Object state = pro.getProperty(mTempFile.getName() + "_state_" + i);
@ -375,6 +360,34 @@ class Downloader implements Runnable, IDownloadUtil {
startSingleTask(recordL);
}
/**
* 创建新的下载文件
*/
private void createNewFile(long fileLength) {
CommonUtil.createFile(mTempFile.getPath());
BufferedRandomAccessFile file = null;
try {
file = new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
//设置文件长度
file.setLength(fileLength);
} catch (IOException e) {
failDownload("下载失败【downloadUrl:"
+ mEntity.getDownloadUrl()
+ "】\n【filePath:"
+ mEntity.getDownloadPath()
+ "】\n"
+ CommonUtil.getPrintException(e));
} finally {
if (file != null) {
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 处理不支持断点的下载
*/

@ -16,70 +16,27 @@
package com.arialyy.aria.core.download.downloader;
import com.arialyy.aria.core.inf.IEventListener;
/**
* 下载监听
*/
public interface IDownloadListener {
interface IDownloadListener extends IEventListener {
/**
* 支持断点回调
*
* @param support true,支持false 不支持
*/
public void supportBreakpoint(boolean support);
/**
* 取消下载
*/
public void onCancel();
/**
* 下载失败
*/
public void onFail();
/**
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
*/
public void onPre();
/**
* 预处理完成,准备下载---开始下载之间
*/
public void onPostPre(long fileSize);
/**
* 下载监听
*/
public void onProgress(long currentLocation);
void supportBreakpoint(boolean support);
/**
* 单一线程的结束位置
*/
public void onChildComplete(long finishLocation);
/**
* 开始
*/
public void onStart(long startLocation);
void onChildComplete(long finishLocation);
/**
* 子程恢复下载的位置
*/
public void onChildResume(long resumeLocation);
/**
* 恢复位置
*/
public void onResume(long resumeLocation);
/**
* 停止
*/
public void onStop(long stopLocation);
/**
* 下载完成
*/
public void onComplete();
void onChildResume(long resumeLocation);
}

@ -31,7 +31,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
/**
* 单位转换后的速度
*/
@Ignore private String convertSpeed = "0b/s";
@Ignore private String convertSpeed = "";
/**
* 下载失败计数每次开始都重置为0
*/

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

@ -15,60 +15,12 @@
*/
package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.inf.IEventListener;
/**
* Created by lyy on 2017/2/9.
* 上传监听
*/
public interface IUploadListener {
/**
* 预处理
*/
public void onPre();
/**
* 预处理完成
*/
public void onPostPre(long fileSize);
/**
* 开始上传
*/
public void onStart();
/**
* 恢复上传
*
* @param resumeLocation 上次上传停止位置
*/
public void onResume(long resumeLocation);
/**
* 停止上传
*
* @param stopLocation 上传停止位置
*/
public void onStop(long stopLocation);
/**
* 上传进度
*
* @param currentLocation 当前进度
*/
public void onProgress(long currentLocation);
/**
* 取消上传
*/
public void onCancel();
/**
* 上传成功
*/
public void onComplete();
interface IUploadListener extends IEventListener {
/**
* 上传失败
*/
public void onFail();
}

@ -18,8 +18,7 @@ package com.arialyy.aria.core.upload;
/**
* Created by lyy on 2017/2/23.
*/
public class UploadListener implements IUploadListener {
class UploadListener implements IUploadListener {
@Override public void onPre() {
}
@ -28,7 +27,7 @@ public class UploadListener implements IUploadListener {
}
@Override public void onStart() {
@Override public void onStart(long startLocation) {
}

@ -28,10 +28,10 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
UploadTarget(String filePath, String targetName) {
this.mTargetName = targetName;
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "groupName=?", filePath);
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath);
if (mTaskEntity == null) {
mTaskEntity = new UploadTaskEntity();
mTaskEntity.entity = new UploadEntity();
mTaskEntity.entity = getUploadEntity(filePath);
}
if (mTaskEntity.entity == null) {
mTaskEntity.entity = getUploadEntity(filePath);
@ -43,13 +43,14 @@ public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, Up
UploadEntity entity = UploadEntity.findFirst(UploadEntity.class, "filePath=?", filePath);
if (entity == null) {
entity = new UploadEntity();
String regex = "[/|\\\\|//]";
Pattern p = Pattern.compile(regex);
String[] strs = p.split(filePath);
String fileName = strs[strs.length - 1];
entity.setFileName(fileName);
entity.setFilePath(filePath);
entity.insert();
}
String regex = "[/|\\\\|//]";
Pattern p = Pattern.compile(regex);
String[] strs = p.split(filePath);
String fileName = strs[strs.length - 1];
entity.setFileName(fileName);
entity.setFilePath(filePath);
return entity;
}

@ -109,7 +109,7 @@ final class UploadUtil implements Runnable {
for (String key : keys) {
addFormField(writer, key, mTaskEntity.formFields.get(key));
}
mListener.onStart();
mListener.onStart(0);
uploadFile(writer, mTaskEntity.attachment, uploadFile);
Log.d(TAG, finish(writer) + "");
} catch (IOException e) {

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
/>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/checkbox"
android:layout_toRightOf="@+id/img"
android:ellipsize="end"
android:maxLines="1"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title"
android:layout_below="@+id/title"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/checkbox"
/>
</RelativeLayout>

@ -1,8 +0,0 @@
<resources>
<string name="app_name">Aria</string>
<string name="error_entity_null">下载实体不能为空</string>
<string name="error_download_url_null">下载链接不能为空</string>
<string name="error_download_path_null">存储地址不能为空</string>
<string name="error_file_name_null">文件名不能为空</string>
</resources>

@ -30,6 +30,7 @@ import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
import com.arialyy.simple.widget.SubStateLinearLayout;
import java.util.List;
/**
@ -40,6 +41,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@Bind(R.id.child_list) SubStateLinearLayout mChildList;
List<String> mUrls;
@Override protected void init(Bundle savedInstanceState) {
@ -50,6 +52,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
DownloadGroupTaskEntity entity = Aria.download(this).getDownloadGroupTask(mUrls);
if (entity != null && entity.getEntity() != null) {
DownloadGroupEntity groupEntity = entity.getEntity();
mChildList.addData(groupEntity.getSubTask());
getBinding().setFileSize(groupEntity.getConvertFileSize());
if (groupEntity.getFileSize() == 0) {
getBinding().setProgress(0);
@ -69,7 +72,8 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
case R.id.start:
Aria.download(this)
.load(mUrls)
.setDownloadDirPath(Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
.setDownloadDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
.setGroupAlias("任务组测试")
.setSubTaskFileName(getModule(GroupModule.class).getSubName())
.start();
@ -99,6 +103,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
mChildList.updateChildProgress(task.getEntity().getSubTask());
}
@DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) {

@ -21,7 +21,6 @@ import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
@ -34,7 +33,7 @@ import com.arialyy.simple.R;
import com.arialyy.simple.base.adapter.AbsHolder;
import com.arialyy.simple.base.adapter.AbsRVAdapter;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import com.arialyy.simple.widget.NoScrollListView;
import com.arialyy.simple.widget.SubStateLinearLayout;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -156,6 +155,9 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
holder.speed.setText(entity.getConvertSpeed());
holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size));
holder.progress.setProgress(current);
//if (holder instanceof GroupHolder){
// handleSubChild((GroupHolder) holder, entity);
//}
}
@SuppressLint("SetTextI18n")
@ -209,11 +211,17 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
}
});
//if (holder instanceof GroupHolder){
// handleSubChild((GroupHolder) holder, entity);
//}
}
private void handleSubChild(GroupHolder holder, final AbsEntity entity){
if (holder.childList.getVisibility() == View.GONE) return;
private void handleSubChild(GroupHolder holder, final AbsEntity entity) {
if (holder.childList.getSubData().size() > 0){
holder.childList.updateChildProgress(((DownloadGroupEntity)entity).getSubTask());
}else {
holder.childList.addData(((DownloadGroupEntity)entity).getSubTask());
}
}
private boolean isSimpleDownload(AbsEntity entity) {
@ -287,7 +295,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
class GroupHolder extends SimpleHolder {
@Bind(R.id.child_list) LinearLayout childList;
@Bind(R.id.child_list) SubStateLinearLayout childList;
GroupHolder(View itemView) {
super(itemView);

@ -85,7 +85,7 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
@OnClick(R.id.upload) void upload() {
Aria.upload(this)
.load(FILE_PATH)
.setUploadUrl("http://172.18.104.228:8080/upload/sign_file")
.setUploadUrl("http://172.18.104.129:8080/upload/sign_file")
.setAttachment("file")
.start();
}

@ -11,24 +11,36 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.simple.R;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
/**
* Created by Aria.Lao on 2017/7/17.
*/
public class SubStateLinearLayout extends LinearLayout {
interface OnShowCallback {
void onShow(boolean visibility);
}
OnShowCallback callback;
List<DownloadEntity> mSubData = new LinkedList<>();
Map<String, Integer> mPosition = new WeakHashMap<>();
public SubStateLinearLayout(Context context) {
super(context);
setOrientation(VERTICAL);
}
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
}
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOrientation(VERTICAL);
}
public void addData(List<DownloadEntity> datas) {
@ -39,22 +51,38 @@ public class SubStateLinearLayout extends LinearLayout {
int i = 1;
for (DownloadEntity entity : datas) {
TextView view = createView(entity);
mPosition.put(entity.getDownloadPath(), i);
addView(view, i);
i++;
}
}
public void update(DownloadEntity entity) {
int position = mSubData.indexOf(entity) + 1;
if (position != 0) {
((TextView) getChildAt(position)).setText(entity.getFileName() + ": " + getPercent(entity));
public void setOnShowCallback(OnShowCallback callback) {
this.callback = callback;
}
public List<DownloadEntity> getSubData() {
return mSubData;
}
public void updateChildProgress(List<DownloadEntity> entities) {
for (DownloadEntity entity : entities) {
Integer i = mPosition.get(entity.getDownloadPath());
if (i == null) return;
int position = i;
if (position != -1) {
TextView child = ((TextView) getChildAt(position));
int p = getPercent(entity);
child.setText(entity.getFileName() + ": " + p + "%" + " | " + entity.getConvertSpeed());
child.invalidate();
}
}
}
private TextView createView(DownloadEntity entity) {
TextView view =
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null);
view.setText(entity.getFileName() + ": " + getPercent(entity));
view.setText(entity.getFileName() + ": " + getPercent(entity) + "%");
return view;
}
@ -65,7 +93,8 @@ public class SubStateLinearLayout extends LinearLayout {
view.setText("点击显示子任务");
view.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
if (getVisibility() == GONE) {
int visibility = getChildAt(1).getVisibility();
if (visibility == GONE) {
showChild(true);
((TextView) v).setText("点击隐藏子任务");
} else {
@ -80,13 +109,13 @@ public class SubStateLinearLayout extends LinearLayout {
private void showChild(boolean show) {
for (int i = 1, count = getChildCount(); i < count; i++) {
getChildAt(i).setVisibility(show ? VISIBLE : GONE);
invalidate();
}
}
private int getPercent(DownloadEntity entity) {
long size = entity.getFileSize();
long progress = entity.getCurrentProgress();
int current = size == 0 ? 0 : (int) (progress * 100 / size);
return current;
return size == 0 ? 0 : (int) (progress * 100 / size);
}
}

@ -31,7 +31,11 @@
bind:progress="@{progress}"
bind:speed="@{speed}"
/>
<View
<com.arialyy.simple.widget.SubStateLinearLayout
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:id="@+id/child_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

@ -21,7 +21,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.arialyy.simple.download.SingleTaskActivity"
tools:showIn="@layout/activity_single"

@ -10,16 +10,15 @@
/>
<LinearLayout
<com.arialyy.simple.widget.SubStateLinearLayout
android:visibility="gone"
android:id="@+id/child_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/include"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
/>

@ -2,7 +2,6 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:textColor="@color/black"
android:textSize="20sp"
android:textSize="14sp"
/>

@ -48,8 +48,12 @@
<string-array name="group_urls">
<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>
<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>
<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
<item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item>
</string-array>
<string-array name="group_names">

@ -3,7 +3,6 @@
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>

@ -168,6 +168,7 @@ class Configuration {
}
field.setAccessible(true);
String value = properties.getProperty(field.getName());
if (TextUtils.isEmpty(value) || value.equalsIgnoreCase("null")) continue;
Class<?> type = field.getType();
if (type == String.class) {
field.set(this, value);

@ -110,7 +110,7 @@ public class UploadTask extends AbsNormalTask<UploadEntity> {
saveData(IEntity.STATE_POST_PRE, 0);
}
@Override public void onStart() {
@Override public void onStart(long startLocation) {
sendInState2Target(ISchedulers.START);
saveData(IEntity.STATE_RUNNING, 0);
}

@ -38,7 +38,7 @@ ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
// publishVersion = '0.0.8'
publishVersion = '3.2.0'
publishVersion = '3.2.3_dev'
repoName='maven'
desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save