package com.weikou.beibeivideo.ui.recent;
|
|
import java.text.DateFormat;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.res.Resources;
|
import android.database.Cursor;
|
import android.text.TextUtils;
|
import android.text.format.Formatter;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.CheckBox;
|
import android.widget.ImageButton;
|
import android.widget.ImageView;
|
import android.widget.ProgressBar;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.RequestManager;
|
import com.google.gson.FieldNamingPolicy;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.lcjian.library.util.common.ConnectionUtils;
|
import com.mozillaonline.providers.DownloadManager;
|
import com.weikou.beibeivideo.R;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
import com.weikou.beibeivideo.db.DownloadTable;
|
import com.weikou.beibeivideo.entity.VideoDetailInfo;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.ui.media.VideoDetailActivity;
|
import com.weikou.beibeivideo.util.DownloadUtils;
|
import com.weikou.beibeivideo.util.VideoUtil;
|
|
public class DownloadAdapter2 extends BaseAdapter {
|
|
public interface IGetDeleteCallback {
|
public void onGetNum(int count);
|
}
|
|
public interface IGetSelectStatus {
|
public void onGetStatus(boolean status);
|
}
|
|
private IGetDeleteCallback getdeleteNumber = null;
|
private IGetSelectStatus getselectstatus = null;
|
|
public void setDeleteCallback(IGetDeleteCallback getdeleteNumber) {
|
this.getdeleteNumber = getdeleteNumber;
|
}
|
|
public void setSelectStatus(IGetSelectStatus getselectstatus) {
|
this.getselectstatus = getselectstatus;
|
}
|
|
private static final int TYPE_DOWNLOAD_ITEM = 0;
|
|
private static final int TYPE_DOWNLOAD_GROUP_ITEM = 1;
|
|
private ImageLoader imageLoader = ImageLoader.getInstance();
|
|
private RequestManager glide;
|
|
private DisplayImageOptions options;
|
|
private DownloadManager mDownloadManager;
|
|
private Context mContext;
|
private Resources mResources;
|
private DateFormat mDateFormat;
|
private DateFormat mTimeFormat;
|
|
private List<Long> mSelectedIds;
|
private boolean mSelectedMode;
|
|
private List<List<DownloadEntity>> datas;
|
|
public DownloadAdapter2(Context context, List<List<DownloadEntity>> allDatas) {
|
super();
|
mContext = context;
|
mResources = mContext.getResources();
|
glide = Glide.with(context);
|
mDateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
|
mTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
|
|
mSelectedIds = new ArrayList<>();
|
mVideoInfos = new HashMap<>();
|
|
options = new DisplayImageOptions.Builder()
|
.showImageForEmptyUri(R.drawable.ic_default_cover)
|
.showImageOnFail(R.drawable.ic_default_cover)
|
.showImageOnLoading(R.drawable.ic_default_cover)
|
.resetViewBeforeLoading(true).cacheInMemory(true)
|
.cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY)
|
.considerExifParams(true)
|
.displayer(new SimpleBitmapDisplayer()).build();
|
this.mDownloadManager = new DownloadManager(
|
context.getContentResolver(), context.getPackageName());
|
this.mDownloadManager.setAccessAllDownloads(true);
|
this.datas = allDatas;
|
}
|
|
private void bindView(Context context, final int position, View convertView) {
|
final DownloadEntity downloadEntity = getItem(position).get(0);
|
|
final long downloadId = downloadEntity.getId();
|
|
getVideoDetail(context, downloadId, convertView);
|
|
String title = downloadEntity.getTitle();
|
String description = downloadEntity.getDescription();
|
long totalBytes = downloadEntity.getTotalBytes();
|
long currentBytes = downloadEntity.getCurrentBytes();
|
int status = downloadEntity.getStatus();
|
|
// 当下载文件小于1M时默认为下载失败状态
|
if (status == DownloadManager.STATUS_SUCCESSFUL
|
&& currentBytes < 1048576) {
|
status = DownloadManager.STATUS_FAILED;
|
// Toast.makeText(mContext, "下载失败,请删除后重新下载",
|
// Toast.LENGTH_LONG).show();
|
}
|
|
if (title.length() == 0) {
|
title = mResources.getString(R.string.missing_title);
|
}
|
if (description.equals(title)) {
|
setTextForView(convertView, R.id.tv_title, title);
|
} else {
|
setTextForView(convertView, R.id.tv_title,
|
title + System.getProperty("line.separator") + description);
|
}
|
int progress = getProgressValue(totalBytes, currentBytes);
|
|
boolean indeterminate = status == DownloadManager.STATUS_PENDING;
|
ProgressBar progressBar = (ProgressBar) convertView
|
.findViewById(R.id.pb_download_progress);
|
TextView tv_download_progress = (TextView) convertView
|
.findViewById(R.id.tv_download_progress);
|
// progressBar.setIndeterminate(indeterminate);
|
if (!indeterminate) {
|
progressBar.setProgress(progress);
|
tv_download_progress.setText(String.valueOf(progress) + "%");
|
}
|
if (status == DownloadManager.STATUS_FAILED
|
|| status == DownloadManager.STATUS_SUCCESSFUL) {
|
progressBar.setVisibility(View.GONE);
|
tv_download_progress.setVisibility(View.GONE);
|
} else {
|
progressBar.setVisibility(View.VISIBLE);
|
tv_download_progress.setVisibility(View.VISIBLE);
|
}
|
|
setTextForView(convertView, R.id.tv_download_byte,
|
getSizeText(currentBytes) + "/" + getSizeText(totalBytes));
|
setTextForView(convertView, R.id.tv_download_status,
|
mResources.getString(getStatusStringId(status, downloadEntity)));
|
// setTextForView(convertView, R.id.status_text,
|
// mResources.getString(getStatusStringId(status)));
|
// setTextForView(convertView, R.id.last_modified_date,
|
// getDateString());
|
// CheckBox chb_download = (CheckBox) convertView
|
// .findViewById(R.id.chb_download);
|
ImageButton btn_pause_download = (ImageButton) convertView
|
.findViewById(R.id.btn_pause_download);
|
final CheckBox chb_delete = (CheckBox) convertView
|
.findViewById(R.id.chb_delete);
|
ImageButton btn_delete_download = (ImageButton) convertView
|
.findViewById(R.id.btn_delete_download);
|
final Context con = context;
|
|
if (mSelectedMode) {
|
convertView.findViewById(R.id.fl_download).setClickable(false);
|
btn_pause_download.setClickable(false);
|
convertView.findViewById(R.id.fl_video_select).setVisibility(
|
View.VISIBLE);
|
tv_download_progress.setVisibility(View.GONE);
|
btn_delete_download.setVisibility(View.INVISIBLE);
|
chb_delete.setVisibility(View.VISIBLE);
|
convertView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
if (mSelectedIds.contains(downloadId)) {
|
mSelectedIds.remove(downloadId);
|
} else {
|
mSelectedIds.add(downloadId);
|
}
|
chb_delete.setChecked(mSelectedIds.contains(downloadId));
|
if (getdeleteNumber != null)
|
getdeleteNumber.onGetNum(mSelectedIds.size());
|
}
|
});
|
chb_delete.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
if (mSelectedIds.contains(downloadId)) {
|
mSelectedIds.remove(downloadId);
|
} else {
|
mSelectedIds.add(downloadId);
|
}
|
chb_delete.setChecked(mSelectedIds.contains(downloadId));
|
if (getdeleteNumber != null)
|
getdeleteNumber.onGetNum(mSelectedIds.size());
|
}
|
});
|
chb_delete.setChecked(mSelectedIds.contains(downloadId));
|
} else {
|
convertView.findViewById(R.id.fl_video_select).setClickable(true);
|
convertView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
|
// List<DownloadEntity> entities =
|
// (List<DownloadEntity>)getItemAtPosition(position);
|
List<DownloadEntity> entities = getItem(position);
|
if (entities.size() == 1) {
|
long downloadId = entities.get(0).getId();
|
Cursor cursor = con.getContentResolver().query(
|
DownloadTable.CONTENT_URI, null,
|
DownloadTable.TASK_ID + " = ? ",
|
new String[] { String.valueOf(downloadId) },
|
null);
|
if (cursor.moveToFirst()) {
|
final String videoId = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_ID));
|
final String videoDetailId = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_DETAIL_ID));
|
VideoInfo videoInfo = getVideoInfos().get(
|
videoDetailId);
|
if (videoInfo != null) {
|
int playingPosition = 0;
|
for (int i = 0; i < videoInfo.getVideoDetailList().size(); i++) {
|
VideoDetailInfo item = videoInfo.getVideoDetailList().get(i);
|
if (item.getId().equals(videoDetailId)) {
|
playingPosition = i;
|
break;
|
}
|
}
|
Intent intent = new Intent(con,
|
VideoDetailActivity.class);
|
if (!TextUtils.isEmpty(DownloadUtils
|
.getOfflinePath(con, videoId,
|
videoDetailId))) {
|
intent.putExtra("orientation_landscape",
|
true);
|
intent.putExtra("video_info", videoInfo);
|
intent.putExtra("playing_position",
|
playingPosition);
|
con.startActivity(intent);
|
} else {
|
if (!ConnectionUtils
|
.isNetworkAvailable(con)) {
|
Toast.makeText(con,
|
"当前无网络,且影片未缓存完毕无法观看",
|
Toast.LENGTH_LONG).show();
|
} else {
|
intent.putExtra("video_info", videoInfo);
|
intent.putExtra("playing_position",
|
playingPosition);
|
con.startActivity(intent);
|
}
|
}
|
}
|
}
|
cursor.close();
|
} else {
|
}
|
|
}
|
});
|
btn_pause_download.setClickable(true);
|
selectAll(false);
|
convertView.findViewById(R.id.fl_video_select).setVisibility(
|
View.GONE);
|
tv_download_progress.setVisibility(View.VISIBLE);
|
// chb_download.setVisibility(View.INVISIBLE);
|
btn_pause_download.setVisibility(View.VISIBLE);
|
switch (status) {
|
case DownloadManager.STATUS_PENDING:
|
btn_pause_download.setImageResource(R.drawable.ic_pending);
|
break;
|
case DownloadManager.STATUS_RUNNING:
|
btn_pause_download.setImageResource(R.drawable.ic_download1);
|
break;
|
case DownloadManager.STATUS_PAUSED:
|
if (!isPausedForWifi(downloadEntity)) {
|
btn_pause_download.setImageResource(R.drawable.ic_pause);
|
}
|
break;
|
case DownloadManager.STATUS_SUCCESSFUL:
|
// btn_pause_download.setImageResource(R.drawable.ic_play);
|
btn_pause_download.setVisibility(View.GONE);
|
convertView.findViewById(R.id.tv_download_status)
|
.setVisibility(View.GONE);
|
break;
|
case DownloadManager.STATUS_FAILED:
|
btn_pause_download.setImageResource(R.drawable.ic_download1);
|
break;
|
}
|
final int sta = status;
|
final ImageButton btn = btn_pause_download;
|
OnClickListener listener = new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
// TODO Auto-generated method stub
|
|
switch (sta) {
|
case DownloadManager.STATUS_PENDING:
|
btn.setImageResource(R.drawable.ic_pause);
|
case DownloadManager.STATUS_RUNNING:
|
mDownloadManager.pauseDownload(downloadId);
|
break;
|
case DownloadManager.STATUS_PAUSED:
|
if (!isPausedForWifi(downloadEntity)) {
|
mDownloadManager.resumeDownload(downloadId);
|
}
|
break;
|
case DownloadManager.STATUS_SUCCESSFUL: {
|
Cursor cursor = v
|
.getContext()
|
.getContentResolver()
|
.query(DownloadTable.CONTENT_URI,
|
null,
|
DownloadTable.TASK_ID + " = ? ",
|
new String[] { String
|
.valueOf(downloadId) }, null);
|
if (cursor.moveToFirst()) {
|
String videoDetailId = cursor
|
.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_DETAIL_ID));
|
VideoInfo videoInfo = mVideoInfos
|
.get(videoDetailId);
|
if (videoInfo != null) {
|
int playingPosition = 0;
|
for (int i = 0; i < videoInfo.getVideoDetailList().size(); i++) {
|
VideoDetailInfo item = videoInfo.getVideoDetailList().get(i);
|
if (item.getId().equals(videoDetailId)) {
|
playingPosition = i;
|
break;
|
}
|
}
|
Intent intent = new Intent(v.getContext(),
|
VideoDetailActivity.class);
|
intent.putExtra("orientation_landscape", true);
|
intent.putExtra("video_info", videoInfo);
|
intent.putExtra("playing_position",
|
playingPosition);
|
v.getContext().startActivity(intent);
|
}
|
}
|
cursor.close();
|
}
|
break;
|
case DownloadManager.STATUS_FAILED:
|
Toast.makeText(v.getContext(), "将为你重新下载",
|
Toast.LENGTH_LONG).show();
|
try {
|
mDownloadManager.restartDownload(downloadId);
|
} catch (Exception e) {
|
// TODO: handle exception
|
}
|
break;
|
}
|
|
}
|
};
|
convertView.findViewById(R.id.fl_download).setOnClickListener(
|
listener);
|
|
convertView.findViewById(R.id.btn_pause_download)
|
.setOnClickListener(listener);
|
|
}
|
}
|
|
private void bindGroupView(Context context, final int position,
|
View convertView) {
|
final List<DownloadEntity> data = getItem(position);
|
ImageView btn_pause_download = (ImageView) convertView
|
.findViewById(R.id.iv_pause_download);
|
{
|
DownloadEntity downloadEntity = data.get(0);
|
getVideoDetail(context, downloadEntity.getId(), convertView);
|
String title = downloadEntity.getTitle();
|
if (title.length() == 0) {
|
title = mResources.getString(R.string.missing_title);
|
}
|
setTextForView(convertView, R.id.tv_title,
|
title + System.getProperty("line.separator") + data.size()
|
+ "个视频");
|
|
int status = DownloadManager.STATUS_PENDING;
|
int mRunningNum = 0;
|
int mPengdingNum = 0;
|
int mPauseNum = 0;
|
int mFailedNum = 0;
|
int mSuccessNum = 0;
|
|
for (int i = 0; i < data.size(); i++) {
|
if (data.get(i).getStatus() == DownloadManager.STATUS_RUNNING) {
|
mRunningNum++;
|
}
|
if (data.get(i).getStatus() == DownloadManager.STATUS_PENDING) {
|
mPengdingNum++;
|
}
|
if (data.get(i).getStatus() == DownloadManager.STATUS_PAUSED) {
|
mPauseNum++;
|
}
|
if (data.get(i).getStatus() == DownloadManager.STATUS_FAILED) {
|
mFailedNum++;
|
}
|
if (data.get(i).getStatus() == DownloadManager.STATUS_SUCCESSFUL) {
|
mSuccessNum++;
|
}
|
}
|
|
if (mRunningNum > 0 && mRunningNum < data.size()) {
|
status = DownloadManager.STATUS_RUNNING;
|
}
|
if (mPengdingNum > 0
|
&& ((mPengdingNum + mFailedNum + mSuccessNum) == data
|
.size() || (mPengdingNum + mPauseNum + mFailedNum + mSuccessNum) == data
|
.size())) {
|
status = DownloadManager.STATUS_PENDING;
|
}
|
if (mPauseNum > 0
|
&& (mPauseNum + mFailedNum + mSuccessNum) == data.size()) {
|
status = DownloadManager.STATUS_PAUSED;
|
}
|
if (mSuccessNum > 0 && (mSuccessNum + mFailedNum) == data.size()) {
|
status = DownloadManager.STATUS_SUCCESSFUL;
|
}
|
if (mFailedNum > 0 && mFailedNum == data.size()) {
|
status = DownloadManager.STATUS_FAILED;
|
}
|
|
setTextForView(convertView, R.id.tv_download_status,
|
mResources.getString(getStatusStringId(status,
|
downloadEntity)));
|
switch (status) {
|
case DownloadManager.STATUS_PENDING:
|
btn_pause_download.setImageResource(R.drawable.ic_pending);
|
break;
|
case DownloadManager.STATUS_RUNNING:
|
btn_pause_download.setImageResource(R.drawable.ic_download1);
|
break;
|
case DownloadManager.STATUS_PAUSED:
|
if (!isPausedForWifi(downloadEntity)) {
|
btn_pause_download.setImageResource(R.drawable.ic_pause);
|
}
|
break;
|
case DownloadManager.STATUS_SUCCESSFUL:
|
// btn_pause_download.setImageResource(R.drawable.ic_play);
|
btn_pause_download.setVisibility(View.GONE);
|
convertView.findViewById(R.id.tv_download_status)
|
.setVisibility(View.GONE);
|
break;
|
case DownloadManager.STATUS_FAILED:
|
btn_pause_download.setImageResource(R.drawable.ic_download1);
|
break;
|
}
|
}
|
long totalBytes = 0;
|
for (DownloadEntity downloadEntity : data) {
|
totalBytes += downloadEntity.getTotalBytes();
|
}
|
setTextForView(convertView, R.id.tv_total_byte, getSizeText(totalBytes));
|
final Context con = context;
|
|
final CheckBox chb_download = (CheckBox) convertView
|
.findViewById(R.id.chb_download);
|
if (mSelectedMode) {
|
convertView.findViewById(R.id.fl_video_select).setVisibility(
|
View.VISIBLE);
|
convertView.setClickable(false);
|
convertView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
|
if (mSelectedIds.contains(data.get(0).getId())) {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.remove(downloadEntity.getId());
|
}
|
} else {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.add(downloadEntity.getId());
|
}
|
}
|
chb_download.setChecked(mSelectedIds.contains(data.get(0)
|
.getId()));
|
if (getdeleteNumber != null)
|
getdeleteNumber.onGetNum(mSelectedIds.size());
|
|
}
|
});
|
chb_download.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
if (mSelectedIds.contains(data.get(0).getId())) {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.remove(downloadEntity.getId());
|
}
|
} else {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.add(downloadEntity.getId());
|
}
|
}
|
((CheckBox) v).setChecked(mSelectedIds.contains(data.get(0)
|
.getId()));
|
if (getdeleteNumber != null)
|
getdeleteNumber.onGetNum(mSelectedIds.size());
|
}
|
});
|
chb_download.setChecked(mSelectedIds.contains(data.get(0).getId()));
|
} else {
|
convertView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
// TODO Auto-generated method stub
|
List<DownloadEntity> entities = getItem(position);
|
long downloadId = entities.get(0).getId();
|
Cursor cursor = con.getContentResolver().query(
|
DownloadTable.CONTENT_URI, null,
|
DownloadTable.TASK_ID + " = ? ",
|
new String[] { String.valueOf(downloadId) }, null);
|
if (cursor.moveToFirst()) {
|
String videoId = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_ID));
|
String videoDetailId = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_DETAIL_ID));
|
Intent intent = new Intent(con, DownLoadActivity.class);
|
intent.putExtra("video_id", videoId);
|
intent.putExtra("video_info",
|
getVideoInfos().get(videoDetailId));
|
intent.putExtra("video_name",
|
getVideoInfos().get(videoDetailId).getName());
|
con.startActivity(intent);
|
}
|
cursor.close();
|
|
}
|
});
|
convertView.findViewById(R.id.fl_video_select).setVisibility(
|
View.GONE);
|
}
|
}
|
|
public int getProgressValue(long totalBytes, long currentBytes) {
|
if (totalBytes == -1) {
|
return 0;
|
}
|
return (int) (currentBytes * 100 / totalBytes);
|
}
|
|
private String getSizeText(long totalBytes) {
|
String sizeText = "";
|
if (totalBytes >= 0) {
|
sizeText = Formatter.formatFileSize(mContext, totalBytes);
|
}
|
return sizeText;
|
}
|
|
private int getStatusStringId(int status, DownloadEntity downloadEntity) {
|
switch (status) {
|
case DownloadManager.STATUS_FAILED:
|
return R.string.download_error;
|
|
case DownloadManager.STATUS_SUCCESSFUL:
|
return R.string.download_success;
|
|
case DownloadManager.STATUS_PENDING:
|
return 0;
|
case DownloadManager.STATUS_RUNNING:
|
return R.string.download_running;
|
|
case DownloadManager.STATUS_PAUSED:
|
if (downloadEntity.getReason() == DownloadManager.PAUSED_QUEUED_FOR_WIFI) {
|
return R.string.download_queued;
|
} else {
|
return R.string.download_paused;
|
}
|
}
|
throw new IllegalStateException("Unknown status: " + status);
|
}
|
|
private void setTextForView(View parent, int textViewId, String text) {
|
TextView view = (TextView) parent.findViewById(textViewId);
|
view.setText(text);
|
}
|
|
private boolean isPausedForWifi(DownloadEntity downloadEntity) {
|
return downloadEntity.getReason() == DownloadManager.PAUSED_QUEUED_FOR_WIFI;
|
}
|
|
private Map<String, VideoInfo> mVideoInfos;
|
|
private void getVideoDetail(Context context, long downloadId,
|
final View convertView) {
|
final ImageView iconView = (ImageView) convertView
|
.findViewById(R.id.iv_cover);
|
Cursor cursor = context.getContentResolver().query(
|
DownloadTable.CONTENT_URI, null,
|
DownloadTable.TASK_ID + " = ? ",
|
new String[] { String.valueOf(downloadId) }, null);
|
if (cursor.moveToFirst()) {
|
String videoDetailId = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_DETAIL_ID));
|
|
convertView.setTag(videoDetailId);
|
VideoInfo videoInfo = mVideoInfos.get(videoDetailId);
|
if (videoInfo != null) {
|
// imageLoader.displayImage(videoInfo.getPicture(), iconView,
|
// options);
|
try {
|
glide.load(videoInfo.getPicture())
|
.placeholder(R.drawable.ic_default_cover)
|
.error(R.drawable.ic_default_cover)
|
.into(iconView);
|
}catch (IllegalArgumentException e){
|
e.printStackTrace();
|
}
|
} else {
|
String videoInfoStr = cursor.getString(cursor
|
.getColumnIndexOrThrow(DownloadTable.VIDEO_DETAIL));
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
videoInfo = gson.fromJson(videoInfoStr,
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
if (videoInfo != null) {
|
mVideoInfos.put(videoDetailId, videoInfo);
|
if (convertView.getTag().equals(videoDetailId)) {
|
// imageLoader.displayImage(videoInfo.getPicture(),
|
// iconView, options);
|
glide.load(videoInfo.getPicture())
|
.placeholder(R.drawable.ic_default_cover)
|
.error(R.drawable.ic_default_cover)
|
.into(iconView);
|
}
|
}
|
}
|
}
|
cursor.close();
|
}
|
|
public List<Long> getSelectedIds() {
|
return mSelectedIds;
|
}
|
|
public boolean isSelectedMode() {
|
return mSelectedMode;
|
}
|
|
public void setSelectedMode(boolean selectedMode) {
|
this.mSelectedMode = selectedMode;
|
if (getselectstatus != null) {
|
getselectstatus.onGetStatus(mSelectedMode);
|
}
|
notifyDataSetChanged();
|
}
|
|
public Map<String, VideoInfo> getVideoInfos() {
|
return mVideoInfos;
|
}
|
|
public void selectAll(boolean isSelected) {
|
if (isSelected) {
|
mSelectedIds.clear();
|
for (List<DownloadEntity> data : datas) {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.add(downloadEntity.getId());
|
}
|
}
|
} else {
|
for (List<DownloadEntity> data : datas) {
|
for (DownloadEntity downloadEntity : data) {
|
mSelectedIds.remove(downloadEntity.getId());
|
}
|
}
|
}
|
if (getdeleteNumber != null)
|
getdeleteNumber.onGetNum(mSelectedIds.size());
|
notifyDataSetChanged();
|
}
|
|
@Override
|
public int getViewTypeCount() {
|
return 2;
|
}
|
|
@Override
|
public int getItemViewType(int position) {
|
return ((List<DownloadEntity>) getItem(position)).size() > 1 ? TYPE_DOWNLOAD_GROUP_ITEM
|
: TYPE_DOWNLOAD_ITEM;
|
}
|
|
@Override
|
public int getCount() {
|
return datas == null ? 0 : datas.size();
|
}
|
|
@Override
|
public List<DownloadEntity> getItem(int position) {
|
return datas.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(int position, View convertView, ViewGroup parent) {
|
if (convertView == null) {
|
if (getItemViewType(position) == TYPE_DOWNLOAD_ITEM) {
|
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
R.layout.download_item, parent, false);
|
} else {
|
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
R.layout.download_group_item, parent, false);
|
}
|
}
|
if (getItemViewType(position) == TYPE_DOWNLOAD_ITEM) {
|
bindView(mContext, position, convertView);
|
} else {
|
bindGroupView(mContext, position, convertView);
|
}
|
return convertView;
|
}
|
|
}
|