任务组bug修复,修复子任务下载完成后重新下载的问题
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user