任务组bug 修复

This commit is contained in:
AriaLyy
2017-07-17 18:10:37 +08:00
parent 041df07617
commit b8a86890a7
31 changed files with 449 additions and 72 deletions

View File

@ -60,6 +60,14 @@ public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
bindData(holder, position, mData.get(position));
}
@Override public void onBindViewHolder(Holder holder, int position, List<Object> payloads) {
if (payloads == null || payloads.isEmpty()) {
bindData(holder, position, mData.get(position));
} else {
bindData(holder, position, mData.get(position), payloads);
}
}
public Context getContext() {
return mContext;
}
@ -74,4 +82,8 @@ public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
protected abstract int setLayoutId(int type);
protected abstract void bindData(Holder holder, int position, T item);
protected void bindData(Holder holder, int position, T item, List<Object> payloads) {
}
}

View File

@ -69,7 +69,9 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
case R.id.start:
Aria.download(this)
.load(mUrls)
.setDownloadDirPath(Environment.getExternalStorageDirectory().getPath() + "/group_test")
.setDownloadDirPath(Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
.setGroupAlias("任务组测试")
.setSubTaskFileName(getModule(GroupModule.class).getSubName())
.start();
break;
case R.id.stop:

View File

@ -32,12 +32,18 @@ public class GroupModule extends BaseModule {
List<String> getUrls() {
List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.download_url);
//String[] str = getContext().getResources().getStringArray(R.array.group_urls);
String[] str = getContext().getResources().getStringArray(R.array.group_urls);
Collections.addAll(urls, str);
return urls;
}
List<String> getSubName(){
List<String> names = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_names);
Collections.addAll(names, str);
return names;
}
//NormalList<String> convertPath(NormalList<String> urls){
// NormalList<String> paths = new ArrayList<>();
//

View File

@ -21,6 +21,7 @@ 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;
@ -111,6 +112,9 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
}
/**
* 更新进度
*/
public synchronized void setProgress(AbsEntity entity) {
String url = entity.getKey();
int position = indexItem(url);
@ -119,7 +123,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
mData.set(position, entity);
notifyItemChanged(position);
notifyItemChanged(position, entity);
}
private synchronized int indexItem(String url) {
@ -136,6 +140,24 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
handleProgress(holder, item);
}
@Override protected void bindData(SimpleHolder holder, int position, AbsEntity item,
List<Object> payloads) {
AbsEntity entity = (AbsEntity) payloads.get(0);
updateSpeed(holder, entity);
}
/**
* 只更新速度
*/
private void updateSpeed(SimpleHolder holder, final AbsEntity entity) {
long size = entity.getFileSize();
long progress = entity.getCurrentProgress();
int current = size == 0 ? 0 : (int) (progress * 100 / size);
holder.speed.setText(entity.getConvertSpeed());
holder.fileSize.setText(covertCurrentSize(progress) + "/" + CommonUtil.formatFileSize(size));
holder.progress.setProgress(current);
}
@SuppressLint("SetTextI18n")
private void handleProgress(SimpleHolder holder, final AbsEntity entity) {
String str = "";
@ -189,6 +211,11 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
});
}
private void handleSubChild(GroupHolder holder, final AbsEntity entity){
if (holder.childList.getVisibility() == View.GONE) return;
}
private boolean isSimpleDownload(AbsEntity entity) {
return entity instanceof DownloadEntity;
}
@ -260,7 +287,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
}
class GroupHolder extends SimpleHolder {
@Bind(R.id.child_list) NoScrollListView childList;
@Bind(R.id.child_list) LinearLayout childList;
GroupHolder(View itemView) {
super(itemView);

View File

@ -0,0 +1,92 @@
package com.arialyy.simple.widget;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.simple.R;
import java.util.LinkedList;
import java.util.List;
/**
* Created by Aria.Lao on 2017/7/17.
*/
public class SubStateLinearLayout extends LinearLayout {
List<DownloadEntity> mSubData = new LinkedList<>();
public SubStateLinearLayout(Context context) {
super(context);
}
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public SubStateLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void addData(List<DownloadEntity> datas) {
removeAllViews();
mSubData.clear();
mSubData.addAll(datas);
createShowView();
int i = 1;
for (DownloadEntity entity : datas) {
TextView view = createView(entity);
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));
}
}
private TextView createView(DownloadEntity entity) {
TextView view =
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null);
view.setText(entity.getFileName() + ": " + getPercent(entity));
return view;
}
private void createShowView() {
TextView view =
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null);
view.setText("点击显示子任务");
view.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
if (getVisibility() == GONE) {
showChild(true);
((TextView) v).setText("点击隐藏子任务");
} else {
showChild(false);
((TextView) v).setText("点击显示子任务");
}
}
});
addView(view, 0);
}
private void showChild(boolean show) {
for (int i = 1, count = getChildCount(); i < count; i++) {
getChildAt(i).setVisibility(show ? VISIBLE : GONE);
}
}
private int getPercent(DownloadEntity entity) {
long size = entity.getFileSize();
long progress = entity.getCurrentProgress();
int current = size == 0 ? 0 : (int) (progress * 100 / size);
return current;
}
}