| | |
| | | }); |
| | | } |
| | | |
| | | private void fillAD(List<ExpressAdContainer> adList) { |
| | | if (adList != null) { |
| | | SearchResultActivity.this.adList.addAll(adList); |
| | | } |
| | | private synchronized void fillAD(List<ExpressAdContainer> adList) { |
| | | |
| | | if (adList.size() > 0) { |
| | | boolean hasAd = false; |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) |
| | | for (VideoContent vc : mVideoInfos) { |
| | | if (vc.getType() == VideoContent.TYPE_AD) { |
| | | hasAd = true; |
| | | break; |
| | | } |
| | | //判断当前页面是否需要广告 |
| | | int albumCount = 0; |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) |
| | | for (int i = 0; i < mVideoInfos.size(); i++) { |
| | | VideoContent vc = mVideoInfos.get(i); |
| | | if (vc.getType() == VideoContent.TYPE_AD) { |
| | | //更新广告 |
| | | vc.setAd(adList.get(0)); |
| | | adapter.notifyItemChanged(i); |
| | | return; |
| | | } else if (vc.getVideo().getShowType() == 1) { |
| | | albumCount++; |
| | | } |
| | | //不存在广告 |
| | | if (!hasAd && mVideoInfos.size() > 2) { |
| | | //TODO 测试 |
| | | VideoContent videoContent = VideoContent.createAdContent(SearchResultActivity.this.adList.get(0)); |
| | | mVideoInfos.add(2, videoContent); |
| | | SearchResultActivity.this.adList.remove(0); |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | if (albumCount >= 2) { |
| | | VideoContent videoContent = VideoContent.createAdContent(adList.get(0)); |
| | | mVideoInfos.add(2, videoContent); |
| | | adapter.notifyItemInserted(2); |
| | | } |
| | | |
| | | } |
| | |
| | | // SearchResultAdManager.getInstance(getApplicationContext()).autoLoadAd(); |
| | | // } |
| | | |
| | | private List<ExpressAdContainer> adList = new ArrayList<>(); |
| | | |
| | | private void search(String key, String videoType) { |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | if (adList.size() > 0) { |
| | | int adPosition = (int) (videoContentList.size() * Math.random()); |
| | | if (mCurrentPage == 1) |
| | | adPosition = 0; |
| | | videoContentList.add(adPosition, VideoContent.createAdContent(adList.get(0))); |
| | | adList.remove(0); |
| | | } |
| | | //记录当前的广告信息 |
| | | VideoContent adContent = null; |
| | | int adContentP = -1; |
| | | if (mCurrentPage <= 1) { |
| | | for (int i = 0; i < mVideoInfos.size(); i++) { |
| | | if (mVideoInfos.get(i).getType() == VideoContent.TYPE_AD) { |
| | | adContent = mVideoInfos.get(i); |
| | | adContentP = i; |
| | | } |
| | | } |
| | | mVideoInfos.clear(); |
| | | } |
| | | |
| | | mVideoInfos.addAll(videoContentList); |
| | | if (adContent != null && mVideoInfos.size() >= adContentP) { |
| | | mVideoInfos.add(adContentP, adContent); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0) { |
| | |
| | | rl_search_result.setVisibility(View.GONE); |
| | | } |
| | | |
| | | //加载下一次要用的广告 |
| | | if (videoInfos.size() > 0) { |
| | | if (adList.size() < 1) |
| | | loadAd(); |
| | | if (mCurrentPage == 1) { |
| | | loadAd(); |
| | | } |
| | | } |
| | | } |