| | |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.request.RequestOptions; |
| | | import com.lcjian.library.util.common.DimenUtils; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.qq.e.ads.nativ.NativeUnifiedADData; |
| | | import com.qq.e.ads.nativ.widget.NativeAdContainer; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.recommend.holder.RecommendVideoAdHolder; |
| | |
| | | import com.weikou.beibeivideo.entity.video.holder.FooterViewHolder; |
| | | import com.weikou.beibeivideo.entity.video.holder.HeaderViewHolder; |
| | | import com.weikou.beibeivideo.entity.video.holder.VideoHolder; |
| | | import com.weikou.beibeivideo.ui.media.VideoDetailActivity; |
| | | import com.weikou.beibeivideo.ui.media.VideoDetailActivity2; |
| | | import com.weikou.beibeivideo.util.VideoUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | import com.weikou.beibeivideo.util.ad.GDTNativeADUnifiedManager; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.util.video.VideoUIUtil; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade; |
| | | |
| | | public class VideoColumn2Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
| | | private Context mContext; |
| | |
| | | private final static int TYPE_HEADER = 10001; |
| | | private final static int TYPE_FOOTER = 10002; |
| | | |
| | | private String from; |
| | | |
| | | |
| | | public void setHeaderView(View headerView) { |
| | | this.headerView = headerView; |
| | |
| | | public void setFooterView(View footerView) { |
| | | this.footerView = footerView; |
| | | } |
| | | |
| | | RecyclerView.ItemDecoration itemDecoration2 = new RecyclerView.ItemDecoration() { |
| | | @Override |
| | | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { |
| | | super.onDraw(c, parent, state); |
| | | } |
| | | |
| | | @Override |
| | | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { |
| | | super.onDrawOver(c, parent, state); |
| | | } |
| | | |
| | | @Override |
| | | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { |
| | | super.getItemOffsets(outRect, view, parent, state); |
| | | int index = parent.getChildAdapterPosition(view); |
| | | int total = parent.getAdapter().getItemCount(); |
| | | int minWidth = DimenUtils.dipToPixels(2, view.getContext()); |
| | | if (index % 2 == 0) { |
| | | outRect.left = 0; //第一列左边贴边 |
| | | outRect.right = minWidth; |
| | | } else { |
| | | outRect.right = 0; //第一列左边贴边 |
| | | outRect.left = minWidth; |
| | | } |
| | | |
| | | if (index - 1 > 0) { |
| | | outRect.top = minWidth * 2; |
| | | } else |
| | | outRect.top = 0; |
| | | |
| | | if (total % 2 == 0) { |
| | | if (total > 2 && (index < total - 2)) |
| | | outRect.bottom = minWidth * 2; |
| | | else |
| | | outRect.bottom = 0; |
| | | } else { |
| | | if (total > 2 && (index < total - 1)) |
| | | outRect.bottom = minWidth * 2; |
| | | else |
| | | outRect.bottom = 0; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | RecyclerView.ItemDecoration itemDecorationRow = new RecyclerView.ItemDecoration() { |
| | | @Override |
| | |
| | | } |
| | | } |
| | | }; |
| | | RecyclerView.ItemDecoration itemDecoration2 = new RecyclerView.ItemDecoration() { |
| | | @Override |
| | | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { |
| | | super.onDraw(c, parent, state); |
| | | } |
| | | |
| | | @Override |
| | | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { |
| | | super.onDrawOver(c, parent, state); |
| | | } |
| | | |
| | | @Override |
| | | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { |
| | | super.getItemOffsets(outRect, view, parent, state); |
| | | int index = parent.getChildAdapterPosition(view); |
| | | int total = parent.getAdapter().getItemCount(); |
| | | int minWidth = DimenUtils.dipToPixels(3, view.getContext()); |
| | | if (index % 2 == 0) { |
| | | outRect.left = 0; //第一列左边贴边 |
| | | outRect.right = minWidth; |
| | | } else { |
| | | outRect.right = 0; //第一列左边贴边 |
| | | outRect.left = minWidth; |
| | | } |
| | | |
| | | if (index - 1 > 0) { |
| | | outRect.top = minWidth * 2; |
| | | } else |
| | | outRect.top = 0; |
| | | |
| | | if (total % 2 == 0) { |
| | | if (total > 2 && (index < total - 2)) |
| | | outRect.bottom = minWidth * 2; |
| | | else |
| | | outRect.bottom = 0; |
| | | } else { |
| | | if (total > 2 && (index < total - 1)) |
| | | outRect.bottom = minWidth * 2; |
| | | else |
| | | outRect.bottom = 0; |
| | | } |
| | | } |
| | | }; |
| | | RecyclerView.ItemDecoration itemDecoration3 = new RecyclerView.ItemDecoration() { |
| | | @Override |
| | | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { |
| | |
| | | super.getItemOffsets(outRect, view, parent, state); |
| | | int index = parent.getChildAdapterPosition(view); |
| | | int total = parent.getAdapter().getItemCount(); |
| | | int minWidth = DimenUtils.dipToPixels(1, view.getContext()); |
| | | int minWidth = DimenUtils.dipToPixels(2, view.getContext()); |
| | | if (index % 3 == 0) { |
| | | outRect.left = 0; //第一列左边贴边 |
| | | outRect.right = minWidth * 2; |
| | |
| | | public static int getItemWidth(Activity activity, int column, int padding) { |
| | | int deviceWidth = DimenUtils.getScreenWidth(activity); |
| | | if (column == 3) |
| | | return (deviceWidth - DimenUtils.dip2px(activity, 3 * 2) - padding) / 3; |
| | | return (deviceWidth - DimenUtils.dip2px(activity, 9 * 2) - padding) / 3; |
| | | else if (column == 2) |
| | | return (deviceWidth - DimenUtils.dip2px(activity, 3) - padding) / 2; |
| | | return (deviceWidth - DimenUtils.dip2px(activity, 8) - padding) / 2; |
| | | else |
| | | return (int) (deviceWidth / 2.5f); |
| | | } |
| | |
| | | padding += rv.getPaddingLeft(); |
| | | padding += rv.getPaddingRight(); |
| | | |
| | | itemWidth = getItemWidth(activity, 2, padding); |
| | | //itemWidth = getItemWidth(activity, 2, padding); |
| | | rv.addItemDecoration(itemDecoration2); |
| | | } |
| | | |
| | |
| | | int padding = 0; |
| | | padding += rv.getPaddingLeft(); |
| | | padding += rv.getPaddingRight(); |
| | | itemWidth = getItemWidth(activity, 3, padding); |
| | | // itemWidth = getItemWidth(activity, 3, padding); |
| | | rv.addItemDecoration(itemDecoration3); |
| | | rv.getItemDecorationCount(); |
| | | } |
| | |
| | | this.columns = columns; |
| | | } |
| | | |
| | | public VideoColumn2Adapter(final Activity activity, Context context, List<VideoInfo> videoList, boolean needAd, int columns, IVideoClickListener itemClickListener) { |
| | | this(activity, context, videoList, needAd, columns, itemClickListener, null); |
| | | public VideoColumn2Adapter(final Activity activity, Context context, List<VideoInfo> videoList, boolean needAd, int columns, String from, IVideoClickListener itemClickListener) { |
| | | this(activity, context, videoList, needAd, columns, from, itemClickListener, null); |
| | | } |
| | | |
| | | |
| | | public VideoColumn2Adapter(final Activity activity, Context context, List<VideoInfo> videoList, boolean needAd, int columns, IVideoClickListener itemClickListener, ExpressAdManager.IAdShowListener showListener) { |
| | | public VideoColumn2Adapter(final Activity activity, Context context, List<VideoInfo> videoList, boolean needAd, int columns, String from, IVideoClickListener itemClickListener, ExpressAdManager.IAdShowListener showListener) { |
| | | if (activity == null || context == null) |
| | | return; |
| | | this.mContext = context; |
| | |
| | | this.itemClickListener = itemClickListener; |
| | | this.columns = columns; |
| | | this.showListener = showListener; |
| | | this.from = from; |
| | | |
| | | for (VideoInfo video : videoList) { |
| | | contentList.add(VideoContent.createVideoContent(video)); |
| | |
| | | void addAdToPosition(int position, ExpressAdContainer ad) { |
| | | if (position >= 0 && position < contentList.size() && ad != null) { |
| | | contentList.add(position, VideoContent.createAdContent(ad)); |
| | | notifyItemInserted(position); |
| | | notifyItemRangeChanged(0, contentList.size()); |
| | | notifyDataSetChanged(); |
| | | // notifyItemInserted(position); |
| | | // notifyItemRangeChanged(0, contentList.size()); |
| | | if (showListener != null) |
| | | showListener.show(); |
| | | |
| | |
| | | VideoHolder holder = (VideoHolder) viewHolder; |
| | | final VideoInfo info = content.getVideo(); |
| | | //设置内容 |
| | | holder.ll_video_show.setVisibility(View.VISIBLE); |
| | | String defaultPicture = ""; |
| | | if (columns == 2) { |
| | | defaultPicture = info.getHpicture(); |
| | | } else if (columns == 3) { |
| | | defaultPicture = info.getVpicture(); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(defaultPicture)) { |
| | | Glide.with(mContext).load(info.getPicture()).transition(withCrossFade()) |
| | | .apply(new RequestOptions().centerCrop().placeholder(R.drawable.shape_default_cover).error(R.drawable.shape_default_cover)) |
| | | .into(holder.iv_movie_cover); |
| | | } else { |
| | | try { |
| | | Glide.with(mContext).load(defaultPicture).transition(withCrossFade()) |
| | | .apply(new RequestOptions().centerCrop().placeholder(R.drawable.shape_default_cover).error(R.drawable.shape_default_cover)) |
| | | .into(holder.iv_movie_cover); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | VideoUIUtil.setVideoListItem(mContext, holder, new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(final View v) { |
| | | //跳转到商品视频播放页 |
| | | if (itemClickListener == null) |
| | | myClick(info, v); |
| | | else |
| | | itemClickListener.onClick(info); |
| | | } |
| | | } |
| | | //vip标识 |
| | | if (info.getFree() == 1) { |
| | | holder.iv_vip.setVisibility(View.VISIBLE); |
| | | } else { |
| | | holder.iv_vip.setVisibility(View.GONE); |
| | | } |
| | | }, info, columns,-1); |
| | | |
| | | |
| | | holder.tv_movie_title.setText(info.getName()); |
| | | |
| | | String tag = StringUtils.isBlank(info.getTag()) ? "" : info |
| | | .getTag(); |
| | | holder.tv_movie_rating.setText(tag); |
| | | if (StringUtils.isBlank(tag)) { |
| | | holder.tv_movie_rating.setVisibility(View.GONE); |
| | | } else { |
| | | holder.tv_movie_rating.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | DecimalFormat df = new DecimalFormat("###.0"); |
| | | holder.tv_movie_play_num.setText(VideoUtil.getWatchCountShortName(info.getWatchCount())); |
| | | holder.tv_movie_comment_num.setText(StringUtils.isBlank(info.getCommentCount()) ? "0" : info.getCommentCount()); |
| | | holder.ll_video_show |
| | | .setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(final View v) { |
| | | //跳转到商品视频播放页 |
| | | if (itemClickListener == null) |
| | | myClick(info, v); |
| | | else |
| | | itemClickListener.onClick(info); |
| | | } |
| | | }); |
| | | holder.tv_movie_play_num.setVisibility(View.GONE); |
| | | |
| | | if (columns == 2) { |
| | | holder.rl_ratio.setRatio(0.625f); |
| | | } else if (columns == 3) { |
| | | holder.rl_ratio.setRatio(1.4f); |
| | | } |
| | | |
| | | } else if (viewHolder instanceof RecommendVideoAdHolder) {//广告 |
| | | final RecommendVideoAdHolder holder = (RecommendVideoAdHolder) viewHolder; |
| | | if (columns == 2) { |
| | | holder.rl_container.setRatio(0.625f); |
| | | holder.rl_container.setRatio(0.562f); |
| | | } else if (columns == 3) { |
| | | holder.rl_container.setRatio(1.4f); |
| | | holder.rl_container.setRatio(1.39f); |
| | | } |
| | | ExpressAdContainer ad = content.getAd(); |
| | | View v = inflater.inflate(R.layout.item_ad_list_small_gdt2, null); |
| | |
| | | private void myClick(VideoInfo info, final View v) { |
| | | Intent intent = new Intent(v.getContext(), VideoDetailActivity2.class); |
| | | intent.putExtra("video_info", info); |
| | | intent.putExtra("from", from); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | v.getContext().startActivity(intent); |
| | | } |