|
|
@ -25,16 +25,11 @@ import android.widget.TextView; |
|
|
|
import butterknife.Bind; |
|
|
|
import butterknife.Bind; |
|
|
|
import com.arialyy.absadapter.common.AbsHolder; |
|
|
|
import com.arialyy.absadapter.common.AbsHolder; |
|
|
|
import com.arialyy.absadapter.recycler_view.AbsRVAdapter; |
|
|
|
import com.arialyy.absadapter.recycler_view.AbsRVAdapter; |
|
|
|
import com.arialyy.downloadutil.core.Aria; |
|
|
|
import com.arialyy.aria.core.Aria; |
|
|
|
import com.arialyy.downloadutil.core.DownloadEntity; |
|
|
|
import com.arialyy.aria.core.DownloadEntity; |
|
|
|
import com.arialyy.downloadutil.core.DownloadManager; |
|
|
|
import com.arialyy.aria.util.CommonUtil; |
|
|
|
import com.arialyy.downloadutil.core.command.CmdFactory; |
|
|
|
|
|
|
|
import com.arialyy.downloadutil.core.command.IDownloadCmd; |
|
|
|
|
|
|
|
import com.arialyy.downloadutil.util.CommonUtil; |
|
|
|
|
|
|
|
import com.arialyy.simple.R; |
|
|
|
import com.arialyy.simple.R; |
|
|
|
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; |
|
|
|
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
@ -46,22 +41,16 @@ import java.util.concurrent.ConcurrentHashMap; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> { |
|
|
|
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> { |
|
|
|
private static final String TAG = "DownloadAdapter"; |
|
|
|
private static final String TAG = "DownloadAdapter"; |
|
|
|
private DownloadManager mManager; |
|
|
|
|
|
|
|
private CmdFactory mFactory; |
|
|
|
|
|
|
|
private Map<String, Integer> mPositions = new ConcurrentHashMap<>(); |
|
|
|
private Map<String, Integer> mPositions = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
public DownloadAdapter(Context context, List<DownloadEntity> data) { |
|
|
|
public DownloadAdapter(Context context, List<DownloadEntity> data) { |
|
|
|
super(context, data); |
|
|
|
super(context, data); |
|
|
|
mFactory = CmdFactory.getInstance(); |
|
|
|
|
|
|
|
mManager = DownloadManager.getInstance(); |
|
|
|
|
|
|
|
List<IDownloadCmd> addCmd = new ArrayList<>(); |
|
|
|
|
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
for (DownloadEntity entity : data) { |
|
|
|
for (DownloadEntity entity : data) { |
|
|
|
mPositions.put(entity.getDownloadUrl(), i); |
|
|
|
mPositions.put(entity.getDownloadUrl(), i); |
|
|
|
addCmd.add(mFactory.createCmd(entity, CmdFactory.TASK_CREATE)); |
|
|
|
Aria.whit(getContext()).load(entity).add(); |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
mManager.setCmds(addCmd).exe(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override protected MyHolder getViewHolder(View convertView, int viewType) { |
|
|
|
@Override protected MyHolder getViewHolder(View convertView, int viewType) { |
|
|
@ -152,14 +141,13 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte |
|
|
|
@Override public void onClick(View v) { |
|
|
|
@Override public void onClick(View v) { |
|
|
|
mData.remove(item); |
|
|
|
mData.remove(item); |
|
|
|
notifyDataSetChanged(); |
|
|
|
notifyDataSetChanged(); |
|
|
|
IDownloadCmd cancelCmd = mFactory.createCmd(item, CmdFactory.TASK_CANCEL); |
|
|
|
Aria.whit(getContext()).load(item).cancel(); |
|
|
|
mManager.setCmd(cancelCmd).exe(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setDownloadNum(int num) { |
|
|
|
public void setDownloadNum(int num) { |
|
|
|
mManager.getTaskQueue().setDownloadNum(num); |
|
|
|
Aria.get(getContext()).setDownloadNum(num); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String covertCurrentSize(long currentSize) { |
|
|
|
private String covertCurrentSize(long currentSize) { |
|
|
|