| | |
| | | import android.app.Activity; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.graphics.Canvas; |
| | | import android.graphics.Rect; |
| | | import android.support.v7.widget.GridLayoutManager; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.AdapterView; |
| | | import android.widget.ImageView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| | | import com.bytedance.sdk.openadsdk.TTAdDislike; |
| | | 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.express2.AdEventListener; |
| | | import com.qq.e.ads.nativ.NativeUnifiedADData; |
| | | import com.qq.e.ads.nativ.widget.NativeAdContainer; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.video.VideoContent; |
| | | import com.weikou.beibeivideo.entity.recommend.holder.RecommendVideoAdHolder; |
| | | import com.weikou.beibeivideo.entity.video.VideoContent; |
| | | 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.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.VideoUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.yeshi.buwanshequ.R; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | import com.weikou.beibeivideo.util.ad.GDTNativeADUnifiedManager; |
| | | import com.weikou.beibeivideo.R; |
| | | |
| | | 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 List<VideoContent> contentList; |
| | | private ExpressAdManager expressAdManager; |
| | | private LayoutInflater inflater; |
| | | private IVideoClickListener itemClickListener; |
| | | private ExpressAdManager.IAdShowListener showListener; |
| | | private Activity activity; |
| | | private int columns; |
| | | |
| | | String TAG = "VideoColumn2Adapter"; |
| | | |
| | | private View headerView; |
| | | |
| | | private View footerView; |
| | | |
| | | private Integer itemWidth;//条目宽度 |
| | | |
| | | private final static int TYPE_HEADER = 10001; |
| | | private final static int TYPE_FOOTER = 10002; |
| | | |
| | | |
| | | public VideoColumn2Adapter(Activity activity, Context context, List<VideoInfo> videoList, boolean needAd, IVideoClickListener itemClickListener) { |
| | | 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 |
| | | 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 == 0) { |
| | | outRect.left = minWidth * 2; //第一列左边贴边 |
| | | outRect.right = minWidth; |
| | | } else if (index == total - 1) { |
| | | outRect.right = minWidth; |
| | | outRect.left = minWidth; |
| | | } else { |
| | | outRect.right = minWidth * 2; //第一列左边贴边 |
| | | outRect.left = minWidth; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | RecyclerView.ItemDecoration itemDecoration3 = 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(1, view.getContext()); |
| | | if (index % 3 == 0) { |
| | | outRect.left = 0; //第一列左边贴边 |
| | | outRect.right = minWidth * 2; |
| | | } else if (index % 3 == 1) { |
| | | outRect.right = minWidth * 1; |
| | | outRect.left = minWidth * 1; |
| | | } else { |
| | | outRect.right = 0; //第一列左边贴边 |
| | | outRect.left = minWidth * 2; |
| | | } |
| | | |
| | | if (index - 2 > 0) { |
| | | outRect.top = minWidth * 3; |
| | | } else |
| | | outRect.top = 0; |
| | | |
| | | if (total > 3) { |
| | | if (index < ((total - 1) / 3) * 3) |
| | | outRect.bottom = minWidth * 3; |
| | | else |
| | | outRect.bottom = 0; |
| | | } else |
| | | outRect.bottom = 0; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * 获取每行的宽度 |
| | | * |
| | | * @param activity |
| | | * @param column |
| | | * @return |
| | | */ |
| | | 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; |
| | | else if (column == 2) |
| | | return (deviceWidth - DimenUtils.dip2px(activity, 3) - padding) / 2; |
| | | else |
| | | return (int) (deviceWidth / 2.5f); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置列表的显示样式(一行2列) |
| | | * |
| | | * @param rv |
| | | */ |
| | | public void initRecyclerViewDisplayWidthColumn2(RecyclerView rv) { |
| | | if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof GridLayoutManager)) { |
| | | RecyclerView.LayoutManager layoutManager = new GridLayoutManager(rv.getContext(), 6); |
| | | rv.setLayoutManager(layoutManager); |
| | | } |
| | | //统一分为2列 |
| | | ((GridLayoutManager) rv.getLayoutManager()).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { |
| | | @Override |
| | | public int getSpanSize(int position) { |
| | | int type = getItemViewType(position); |
| | | if (type == TYPE_FOOTER || type == TYPE_HEADER) |
| | | return 6; |
| | | else |
| | | return 3; |
| | | } |
| | | }); |
| | | for (int i = 0; i < rv.getItemDecorationCount(); i++) { |
| | | rv.removeItemDecoration(rv.getItemDecorationAt(i)); |
| | | i--; |
| | | } |
| | | |
| | | int padding = 0; |
| | | padding += rv.getPaddingLeft(); |
| | | padding += rv.getPaddingRight(); |
| | | |
| | | itemWidth = getItemWidth(activity, 2, padding); |
| | | rv.addItemDecoration(itemDecoration2); |
| | | } |
| | | |
| | | |
| | | public void initRecyclerViewDisplayWidthRow1(RecyclerView rv) { |
| | | // if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof LinearLayoutManager)) { |
| | | LinearLayoutManager layoutManager = new LinearLayoutManager(rv.getContext()); |
| | | layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
| | | rv.setLayoutManager(layoutManager); |
| | | // } else { |
| | | // ((LinearLayoutManager) rv.getLayoutManager()).setOrientation(LinearLayoutManager.HORIZONTAL); |
| | | // } |
| | | for (int i = 0; i < rv.getItemDecorationCount(); i++) { |
| | | rv.removeItemDecoration(rv.getItemDecorationAt(i)); |
| | | i--; |
| | | } |
| | | int padding = 0; |
| | | padding += rv.getPaddingLeft(); |
| | | padding += rv.getPaddingRight(); |
| | | itemWidth = getItemWidth(activity, Integer.MAX_VALUE, padding); |
| | | rv.addItemDecoration(itemDecorationRow); |
| | | } |
| | | |
| | | /** |
| | | * 设置列表的显示样式(一行3列) |
| | | * |
| | | * @param rv |
| | | */ |
| | | public void initRecyclerViewDisplayWidthColumn3(RecyclerView rv) { |
| | | if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof GridLayoutManager)) { |
| | | RecyclerView.LayoutManager layoutManager = new GridLayoutManager(rv.getContext(), 6); |
| | | rv.setLayoutManager(layoutManager); |
| | | } |
| | | //统一分为2列 |
| | | ((GridLayoutManager) rv.getLayoutManager()).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { |
| | | @Override |
| | | public int getSpanSize(int position) { |
| | | int type = getItemViewType(position); |
| | | if (type == TYPE_FOOTER || type == TYPE_HEADER) |
| | | return 6; |
| | | else |
| | | return 2; |
| | | } |
| | | }); |
| | | for (int i = 0; i < rv.getItemDecorationCount(); i++) { |
| | | rv.removeItemDecoration(rv.getItemDecorationAt(i)); |
| | | i--; |
| | | } |
| | | int padding = 0; |
| | | padding += rv.getPaddingLeft(); |
| | | padding += rv.getPaddingRight(); |
| | | itemWidth = getItemWidth(activity, 3, padding); |
| | | rv.addItemDecoration(itemDecoration3); |
| | | rv.getItemDecorationCount(); |
| | | } |
| | | |
| | | public VideoColumn2Adapter() { |
| | | |
| | | } |
| | | |
| | | public void refreshAd() { |
| | | if (contentList == null || contentList.size() == 0) |
| | | return; |
| | | |
| | | GDTNativeADUnifiedManager.loadAD(columns == 3 ? GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN3 : GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN2, 1, mContext, new GDTNativeADUnifiedManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<NativeUnifiedADData> adList) { |
| | | if (adList != null && adList.size() > 0) |
| | | VideoColumn2Adapter.this.addAdToPosition(0, new ExpressAdContainer(adList.get(0))); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void setVideoList(List<VideoInfo> videoList) { |
| | | if (contentList == null) |
| | | contentList = new ArrayList<>(); |
| | | contentList.clear(); |
| | | for (VideoInfo video : videoList) { |
| | | contentList.add(VideoContent.createVideoContent(video)); |
| | | } |
| | | } |
| | | |
| | | public void setColumns(int columns) { |
| | | 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, IVideoClickListener itemClickListener, ExpressAdManager.IAdShowListener showListener) { |
| | | if (activity == null || context == null) |
| | | return; |
| | | this.mContext = context; |
| | |
| | | this.contentList = new ArrayList<>(); |
| | | inflater = LayoutInflater.from(context); |
| | | this.itemClickListener = itemClickListener; |
| | | this.columns = columns; |
| | | this.showListener = showListener; |
| | | |
| | | for (VideoInfo video : videoList) { |
| | | contentList.add(VideoContent.createVideoContent(video)); |
| | | } |
| | | |
| | | if (needAd) { |
| | | if (expressAdManager == null) |
| | | expressAdManager = new ExpressAdManager(AdUtil.getSmallExpressAdType(), mContext); |
| | | expressAdManager.loadRecommendCategorySmallAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | if (adList != null && adList.size() > 0) { |
| | | if (contentList != null && contentList.size() > 0 && contentList.get(0).getType() == VideoContent.TYPE_VIDEO) { |
| | | contentList.add(0, VideoContent.createAdContent(adList.get(0))); |
| | | notifyDataSetChanged(); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | refreshAd(); |
| | | } |
| | | } |
| | | |
| | | // 把返回的 广告 添加到数据集里面去 |
| | | 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()); |
| | | if (showListener != null) |
| | | showListener.show(); |
| | | |
| | | Log.d(TAG, "addAdToPosition:" + VideoColumn2Adapter.this.toString()); |
| | | } |
| | | } |
| | | |
| | | // 移除 广告 的时候是一条一条移除的 |
| | | void removeADView(int position, ExpressAdContainer ad) { |
| | | if (contentList.get(position).getAd() == null) |
| | | return; |
| | | contentList.remove(position); |
| | | notifyItemRemoved(position); |
| | | notifyItemRangeChanged(0, contentList.size() - 1); |
| | | } |
| | | |
| | | @Override |
| | | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) { |
| | | |
| | | switch (type) { |
| | | case TYPE_HEADER: |
| | | return new HeaderViewHolder(headerView); |
| | | case TYPE_FOOTER: |
| | | return new FooterViewHolder(footerView); |
| | | case VideoContent.TYPE_AD: |
| | | return new RecommendVideoAdHolder(inflater.inflate(R.layout.item_ad_list_small, parent, false)); |
| | | case VideoContent.TYPE_VIDEO: |
| | |
| | | |
| | | @Override |
| | | public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int p) { |
| | | if ((viewHolder instanceof HeaderViewHolder) || (viewHolder instanceof FooterViewHolder)) { |
| | | return; |
| | | } |
| | | if (headerView != null) |
| | | p = p - 1; |
| | | |
| | | final VideoContent content = contentList.get(p); |
| | | |
| | | if (itemWidth != null) { |
| | | ViewGroup.LayoutParams params = viewHolder.itemView.getLayoutParams(); |
| | | params.width = itemWidth; |
| | | } |
| | | |
| | | if (viewHolder instanceof VideoHolder) { |
| | | VideoHolder holder = (VideoHolder) viewHolder; |
| | | final VideoInfo info = content.getVideo(); |
| | | //设置内容 |
| | | holder.ll_video_show.setVisibility(View.VISIBLE); |
| | | if (StringUtils.isEmpty(info.getPicture())) { |
| | | Glide.with(mContext).load(info.getPicture()) |
| | | .placeholder(R.drawable.ic_default_cover) |
| | | .error(R.drawable.ic_default_cover) |
| | | .centerCrop().crossFade() |
| | | .diskCacheStrategy(DiskCacheStrategy.SOURCE) |
| | | 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(info.getPicture()) |
| | | .placeholder(R.drawable.ic_default_cover) |
| | | .error(R.drawable.ic_default_cover) |
| | | .centerCrop().crossFade() |
| | | .diskCacheStrategy(DiskCacheStrategy.SOURCE) |
| | | 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(); |
| | | } |
| | | } |
| | | holder.tv_movie_title.setText(info.getName()); |
| | | holder.tv_movie_rating.setText(StringUtils.isBlank(info |
| | | .getTag()) ? "" : info |
| | | .getTag()); |
| | | |
| | | 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(StringUtils.isBlank(info |
| | | .getWatchCount()) ? "0" : (Integer.parseInt(info |
| | | .getWatchCount())) / 10000 > 0 ? df.format(Integer.parseInt(info |
| | | .getWatchCount()) / 10000f) + "万" : info |
| | | .getWatchCount()); |
| | | 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() { |
| | |
| | | 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; |
| | | holder.fl_container.removeAllViews(); |
| | | |
| | | final ExpressAdContainer ad = content.getAd(); |
| | | if (ad == null) {//广告为空 |
| | | holder.view.setVisibility(View.GONE); |
| | | } else { |
| | | holder.view.setVisibility(View.VISIBLE); |
| | | if (ad.getGdt() != null) { |
| | | holder.rl_container.setRatio(0.88f); |
| | | holder.tv_movie_title.setVisibility(View.GONE); |
| | | ad.getGdt().render(); |
| | | holder.fl_container.addView(ad.getGdt()); |
| | | holder.tv_movie_play_num.setText("112"); |
| | | |
| | | } else if (ad.getCsj() != null) { |
| | | holder.rl_container.setRatio(0.88f); |
| | | holder.tv_movie_title.setVisibility(View.GONE); |
| | | ad.getCsj().setDislikeCallback(activity, new TTAdDislike.DislikeInteractionCallback() { |
| | | |
| | | @Override |
| | | public void onSelected(int i, String s) { |
| | | contentList.remove(content); |
| | | notifyDataSetChanged(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRefuse() { |
| | | |
| | | } |
| | | }); |
| | | ad.getCsj().render(); |
| | | holder.fl_container.addView(ad.getCsj().getExpressAdView()); |
| | | } |
| | | if (columns == 2) { |
| | | holder.rl_container.setRatio(0.625f); |
| | | } else if (columns == 3) { |
| | | holder.rl_container.setRatio(1.4f); |
| | | } |
| | | ExpressAdContainer ad = content.getAd(); |
| | | View v = inflater.inflate(R.layout.item_ad_list_small_gdt2, null); |
| | | ImageView iv_picture = v.findViewById(R.id.iv_picture); |
| | | NativeAdContainer nv = v.findViewById(R.id.native_ad_container); |
| | | GDTNativeADUnifiedManager.renderSinglePicture(iv_picture, holder.tv_movie_title, nv, ad.getGdt2Unfied()); |
| | | holder.fl_container.removeAllViews(); |
| | | holder.fl_container.addView(v); |
| | | // ExpressAdManager.fillAd(ad, holder.fl_container); |
| | | } |
| | | } |
| | | |
| | |
| | | int count = 0; |
| | | if (contentList != null) |
| | | count = contentList.size(); |
| | | return count % 2 == 0 ? count : count - 1; |
| | | if (columns < 4) |
| | | count = count % columns == 0 ? count : ((count / columns) * columns); |
| | | if (headerView != null) |
| | | count++; |
| | | if (footerView != null) |
| | | count++; |
| | | return count; |
| | | } |
| | | |
| | | @Override |
| | | public int getItemViewType(int position) { |
| | | if (columns == 0) |
| | | return -1; |
| | | |
| | | int count = contentList == null ? 0 : contentList.size(); |
| | | int contentCount = count; |
| | | |
| | | if (columns < 4) |
| | | contentCount = count % columns == 0 ? count : ((count / columns) * columns); |
| | | |
| | | if (position == 0) { |
| | | if (headerView != null) |
| | | return TYPE_HEADER; |
| | | else if (this.contentList.size() > 0) |
| | | return this.contentList.get(position).getType(); |
| | | else if (footerView != null) |
| | | return TYPE_FOOTER; |
| | | else |
| | | return -1; |
| | | } else if (position < (contentCount + (headerView == null ? 0 : 1))) { |
| | | if (headerView != null) |
| | | position--; |
| | | this.contentList.get(position).getType(); |
| | | } else if (footerView != null) |
| | | return TYPE_FOOTER; |
| | | else |
| | | return -1; |
| | | return this.contentList.get(position).getType(); |
| | | } |
| | | |
| | |
| | | private void myClick(VideoInfo info, final View v) { |
| | | Intent intent = new Intent(v.getContext(), VideoDetailActivity.class); |
| | | intent.putExtra("video_info", info); |
| | | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | v.getContext().startActivity(intent); |
| | | } |
| | | |
| | | } |