任务组bug 修复
This commit is contained in:
@ -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) {
|
||||
|
||||
}
|
||||
}
|
@ -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:
|
||||
|
@ -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<>();
|
||||
//
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -4,15 +4,23 @@
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_item_progress"
|
||||
<include
|
||||
layout="@layout/layout_item_progress"
|
||||
android:id="@+id/include"
|
||||
/>
|
||||
|
||||
<com.arialyy.simple.widget.NoScrollListView
|
||||
|
||||
<LinearLayout
|
||||
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"
|
||||
/>
|
||||
|
||||
|
||||
</RelativeLayout>
|
8
app/src/main/res/layout/layout_child_state.xml
Normal file
8
app/src/main/res/layout/layout_child_state.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
/>
|
@ -47,17 +47,15 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_urls">
|
||||
<item>http://img.sc115.com/uploads/allimg/110420/20110420225600154.jpg</item>
|
||||
<item>http://img05.tooopen.com/images/20160121/tooopen_sy_155168162826.jpg</item>
|
||||
<item>http://img03.tooopen.com/images/20130811/tooopen_15265353.jpg</item>
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<!--<item></item>-->
|
||||
<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>
|
||||
<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>
|
||||
<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_names">
|
||||
<item>王者荣耀.apk</item>
|
||||
<item>战斗吧剑灵.apk</item>
|
||||
<item>天魔幻想.apk</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user