package com.weikou.beibeivideo.ui.media;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import android.graphics.Color;
|
import android.text.TextUtils;
|
import android.text.TextUtils.TruncateAt;
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.TextView;
|
|
import com.weikou.beibeivideo.R;
|
import com.weikou.beibeivideo.entity.VideoDetailInfo;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.util.DownloadUtils;
|
import com.weikou.beibeivideo.util.VideoUtil;
|
|
/**
|
* 收起时显示的剧集适配器
|
*/
|
public class EpisodeAdapter2 extends BaseAdapter {
|
|
private VideoInfo mVideoInfo;
|
private int mPlayingPosition;
|
private List<VideoDetailInfo> mList;
|
|
public EpisodeAdapter2(VideoInfo videoInfo, int playingPosition) {
|
super();
|
mList = new ArrayList<VideoDetailInfo>();
|
this.mVideoInfo = videoInfo;
|
this.mPlayingPosition = playingPosition;
|
}
|
|
@Override
|
public int getCount() {
|
mList.clear();
|
mList.addAll(VideoUtil.videoEpisodeList);
|
int count = mList.size();
|
if (mVideoInfo.getShowType() == 1) {// 电影
|
// return count;
|
// } else if (mStretch == 1) {// 综艺
|
if (count > 2) {
|
return 2;
|
} else {
|
return count;
|
}
|
} else {// 电视剧什么的,需要特殊处理,第一集显示用户选择的那集
|
// 如果mPlayingPosition 为12 就添加原集合中的 position 1-12 一共12个数据到集合中
|
// 首先,
|
if (mPlayingPosition >= 10) {// 从1开始到12结束
|
mList.clear();
|
for (int i = mPlayingPosition - 9; i <= mPlayingPosition; i++) {
|
mList.add(VideoUtil.videoEpisodeList.get(i));
|
}
|
// 再重新赋值
|
count = mList.size();
|
}
|
// 再对后续数据显示处理
|
if (count > 10) {
|
return 10;
|
} else {
|
return count;
|
}
|
}
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return mList.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(int position, View convertView, ViewGroup parent) {
|
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_episode, null);
|
TextView tv_episode = convertView.findViewById(R.id.tv_episode);
|
VideoDetailInfo videoDetailInfo = (VideoDetailInfo) getItem(position);
|
// 此处的position 从0开始 mPlayingPosition为12时 position应该是从1-12
|
// mPlayingPosition为18时 position应该是从7-18
|
if (mPlayingPosition >= 12 && position == mList.size() - 1) {// 用户选择大于12集以上内容时
|
|
|
tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_selected);
|
tv_episode.setTextColor(Color.parseColor("#FFFFFF"));
|
|
|
} else if (position == mPlayingPosition) {
|
tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_selected);
|
tv_episode.setTextColor(Color.parseColor("#FFFFFF"));
|
} else {
|
if (TextUtils.isEmpty(DownloadUtils.getOfflinePath(
|
parent.getContext(), mVideoInfo.getId(),
|
videoDetailInfo.getId()))) {
|
tv_episode.setBackgroundResource(R.drawable.episode_offlined);
|
}
|
tv_episode.setBackgroundResource(R.drawable.shape_video_detail_episode_unselected);
|
tv_episode.setTextColor(Color.parseColor("#232323"));
|
}
|
if (mVideoInfo.getShowType() == 1) {
|
// ((TextView) convertView).setText(videoDetailInfo.getName());
|
// } else if (mStretch == 1) {
|
if (videoDetailInfo.getIntroduction() == null) {
|
videoDetailInfo.setIntroduction("");
|
}
|
tv_episode.setText(TextUtils.isEmpty(videoDetailInfo
|
.getTag()) ? ""
|
: (videoDetailInfo.getTag() + videoDetailInfo
|
.getIntroduction()));
|
} else {
|
tv_episode.setText(videoDetailInfo.getTag());
|
}
|
return convertView;
|
}
|
}
|