package com.weikou.beibeivideo.ui.category;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.print.PrintAttributes;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.RequestManager;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.ui.media.VideoDetailActivity;
|
import com.weikou.beibeivideo.util.AdPromptDialog;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.yeshi.buwanshequ.R;
|
|
import java.text.DecimalFormat;
|
import java.util.List;
|
|
/**
|
* Created by weikou2015 on 2016/8/18.
|
*/
|
public class CategoryRecommendAdapter extends BaseAdapter {
|
|
private List<VideoInfo> mList;
|
|
private Context mContext;
|
|
public CategoryRecommendAdapter(List<VideoInfo> list, Context context) {
|
mList = list;
|
mContext = context;
|
}
|
|
@Override
|
public int getCount() {
|
if (mList.size() % 2 == 0) {
|
return mList == null ? 0 : (mList.size() / 2);
|
} else {
|
return mList == null ? 0 : (mList.size() / 2 + 1);
|
}
|
}
|
|
@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 view, ViewGroup parent) {
|
ViewHolder holder;
|
if (view == null) {
|
holder = new ViewHolder();
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_item3, null);
|
|
holder.ll_video_show1 = view
|
.findViewById(R.id.ll_video_show1);
|
holder.ll_video_show2 = view
|
.findViewById(R.id.ll_video_show2);
|
holder.iv_movie_cover = view
|
.findViewById(R.id.iv_movie_cover);
|
holder.tv_movie_title = view
|
.findViewById(R.id.tv_movie_title);
|
holder.tv_movie_rating = view
|
.findViewById(R.id.tv_movie_rating);
|
holder.tv_movie_play_num = view
|
.findViewById(R.id.tv_movie_play_num);
|
holder.tv_movie_comment_num = view
|
.findViewById(R.id.tv_movie_comment_num);
|
holder.iv_movie_cover1 = view
|
.findViewById(R.id.iv_movie_cover1);
|
holder.tv_movie_title1 = view
|
.findViewById(R.id.tv_movie_title1);
|
holder.tv_movie_rating1 = view
|
.findViewById(R.id.tv_movie_rating1);
|
holder.tv_movie_play_num1 = view
|
.findViewById(R.id.tv_movie_play_num1);
|
holder.tv_movie_comment_num1 = view
|
.findViewById(R.id.tv_movie_comment_num1);
|
holder.fl_ad = view
|
.findViewById(R.id.fl_ad);
|
|
view.setTag(holder);
|
} else {
|
holder = (ViewHolder) view.getTag();
|
}
|
VideoInfo info = null;
|
VideoInfo info1 = null;
|
|
int startP = position * 2;
|
info = mList.get(startP);
|
if (startP + 1 < mList.size()) {
|
info1 = mList.get(startP + 1);
|
}
|
if (info == null)
|
return view;
|
if (info1 == null)
|
return view;
|
|
if (info != null) {
|
if (null == info.getAdView()) {
|
holder.fl_ad.setVisibility(View.GONE);
|
holder.ll_video_show1.setVisibility(View.VISIBLE);
|
try {
|
Glide.with(mContext).load(info.getPicture())
|
.placeholder(R.drawable.ic_default_cover)
|
.error(R.drawable.ic_default_cover)
|
.centerCrop().crossFade()
|
.into(holder.iv_movie_cover);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
|
holder.tv_movie_title.setText(info.getName());
|
holder.tv_movie_rating.setText(StringUtils.isBlank(info
|
.getTag()) ? "" : info
|
.getTag());
|
// holder.tv_movie_play_num.setText(StringUtils.isBlank(info
|
// .getWatchCount()) ? "0" : info.getWatchCount());
|
DecimalFormat df = new DecimalFormat("###.0");
|
holder.tv_movie_play_num.setText(StringUtils.isBlank(info
|
.getWatchCount()) ? "0" : (Integer.parseInt(info
|
.getWatchCount())) / 10000 > 0 ? df.format(Integer.parseInt(info
|
.getWatchCount()) / 10000f) + "万" : info
|
.getWatchCount() + "");
|
holder.tv_movie_comment_num.setText(StringUtils.isBlank(info
|
.getCommentCount()) ? "0" : info.getCommentCount());
|
} else {
|
holder.fl_ad.setVisibility(View.VISIBLE);
|
holder.ll_video_show1.setVisibility(View.GONE);
|
FrameLayout parentAd = (FrameLayout) info.getAdView().getParent();
|
info.getAdView().render();
|
if (null != parentAd) {
|
parentAd.removeAllViews();
|
}
|
holder.fl_ad.addView(info.getAdView());
|
}
|
|
} else {
|
holder.ll_video_show1.setVisibility(View.INVISIBLE);
|
}
|
if (info1 != null) {
|
holder.ll_video_show2.setVisibility(View.VISIBLE);
|
if (StringUtils.isEmpty(info1.getPicture())) {
|
// imageLoader.displayImage(info1.getVideo().getPicture(),
|
// holder.iv_movie_cover1, options);
|
Glide.with(mContext).load(info1.getPicture())
|
.placeholder(R.drawable.ic_default_cover)
|
.error(R.drawable.ic_default_cover)
|
.centerCrop().crossFade()
|
.into(holder.iv_movie_cover1);
|
} else {
|
try {
|
Glide.with(mContext).load(info1.getPicture())
|
.placeholder(R.drawable.ic_default_cover)
|
.error(R.drawable.ic_default_cover)
|
.centerCrop().crossFade()
|
.into(holder.iv_movie_cover1);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
// imageLoader.displayImage(info1.getPicture(),
|
// holder.iv_movie_cover1, options);
|
}
|
holder.tv_movie_title1.setText(info1.getName());
|
holder.tv_movie_rating1.setText(StringUtils.isBlank(info1
|
.getTag()) ? "" : info1
|
.getTag());
|
// holder.tv_movie_play_num1.setText(StringUtils.isBlank(info1
|
// .getWatchCount()) ? "0" : info1.getWatchCount());
|
DecimalFormat df = new DecimalFormat("###.0");
|
holder.tv_movie_play_num1.setText(StringUtils.isBlank(info1
|
.getWatchCount()) ? "0" : (Integer.parseInt(info1
|
.getWatchCount())) / 10000 > 0 ? df.format(Integer.parseInt(info1
|
.getWatchCount()) / 10000f) + "万" : info1
|
.getWatchCount() + "");
|
holder.tv_movie_comment_num1.setText(StringUtils.isBlank(info1
|
.getCommentCount()) ? "0" : info1.getCommentCount());
|
|
if (info1.getAdInfo() != null)
|
info1.getAdInfo().onExposured(holder.ll_video_show1);
|
} else {
|
holder.ll_video_show2.setVisibility(View.INVISIBLE);
|
}
|
if (info != null) {
|
final VideoInfo myInfo = info;
|
holder.ll_video_show1
|
.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
public void onClick(final View v) {
|
if (myInfo.getAdInfo() == null) {
|
myClick(myInfo, v);
|
} else {
|
if (myInfo.getAdInfo().isAPP() && BeibeiConstant.AD_CLICK_DOWNLOAD) {
|
DialogInterface.OnClickListener dialogOnclicListener = new DialogInterface.OnClickListener() {
|
|
@Override
|
public void onClick(DialogInterface dialog,
|
int which) {
|
switch (which) {
|
case Dialog.BUTTON_POSITIVE:
|
myInfo.getAdInfo().onClicked(v);
|
dialog.dismiss();
|
break;
|
case Dialog.BUTTON_NEGATIVE:
|
dialog.dismiss();
|
break;
|
}
|
}
|
};
|
AdPromptDialog.Builder builder = new AdPromptDialog.Builder(
|
v.getContext()); // 先得到构造器
|
builder.setPositiveButton("确认", dialogOnclicListener);
|
builder.setNegativeButton("取消", dialogOnclicListener);
|
builder.create().show();
|
} else {
|
myInfo.getAdInfo().onClicked(v);
|
}
|
}
|
}
|
});
|
}
|
if (info1 != null) {
|
final VideoInfo myInfo1 = info1;
|
|
holder.ll_video_show2
|
.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
public void onClick(final View v) {
|
if (myInfo1.getAdInfo() == null) {
|
myClick(myInfo1, v);
|
} else {
|
if (myInfo1.getAdInfo().isAPP() && BeibeiConstant.AD_CLICK_DOWNLOAD) {
|
DialogInterface.OnClickListener dialogOnclicListener = new DialogInterface.OnClickListener() {
|
|
@Override
|
public void onClick(DialogInterface dialog,
|
int which) {
|
switch (which) {
|
case Dialog.BUTTON_POSITIVE:
|
myInfo1.getAdInfo().onClicked(v);
|
dialog.dismiss();
|
break;
|
case Dialog.BUTTON_NEGATIVE:
|
dialog.dismiss();
|
break;
|
}
|
}
|
};
|
AdPromptDialog.Builder builder = new AdPromptDialog.Builder(
|
v.getContext()); // 先得到构造器
|
builder.setPositiveButton("确认", dialogOnclicListener);
|
builder.setNegativeButton("取消", dialogOnclicListener);
|
builder.create().show();
|
} else {
|
myInfo1.getAdInfo().onClicked(v);
|
}
|
}
|
}
|
});
|
}
|
|
return view;
|
}
|
|
private static class ViewHolder {
|
ImageView iv_movie_cover;
|
TextView tv_movie_title;
|
TextView tv_movie_rating;
|
TextView tv_movie_play_num;
|
TextView tv_movie_comment_num;
|
TextView tv_movie_title1;
|
ImageView iv_movie_cover1;
|
TextView tv_movie_rating1;
|
TextView tv_movie_play_num1;
|
TextView tv_movie_comment_num1;
|
LinearLayout ll_video_show1;
|
LinearLayout ll_video_show2;
|
FrameLayout fl_ad;
|
}
|
|
private void myClick(VideoInfo videoInfo, View v) {
|
Intent intent = new Intent(v.getContext(), VideoDetailActivity.class);
|
intent.putExtra("video_info", videoInfo);
|
v.getContext().startActivity(intent);
|
}
|
}
|