| | |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Intent; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.text.SpannableString; |
| | | import android.text.Spanned; |
| | | import android.text.style.AbsoluteSizeSpan; |
| | | |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.request.RequestOptions; |
| | | import com.bumptech.glide.request.target.DrawableImageViewTarget; |
| | | import com.bytedance.sdk.openadsdk.TTAdDislike; |
| | | import com.google.gson.FieldNamingPolicy; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.lcjian.library.util.common.DimenUtils; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.lcjian.library.widget.RatioLayout; |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.HomeType; |
| | | import com.weikou.beibeivideo.entity.HomeVideo; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.VideoType; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.recommend.HomeTypeContent; |
| | | import com.weikou.beibeivideo.entity.recommend.RecommendContent; |
| | | 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.common.VideosLiveActivity; |
| | | import com.weikou.beibeivideo.ui.discover.StarsActivity; |
| | | import com.weikou.beibeivideo.ui.media.VideoDetailActivity2; |
| | | import com.weikou.beibeivideo.ui.video.VideoRecommendAdapter; |
| | | import com.weikou.beibeivideo.util.JsonUtil; |
| | | import com.weikou.beibeivideo.util.JumpActivityUtil; |
| | | import com.weikou.beibeivideo.util.VideoUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.video.VideoUIUtil; |
| | | import com.weikou.beibeivideo.util.downutil.StringUtils; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONArray; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | |
| | | private TreeSet mADSet = new TreeSet(); |
| | | |
| | | public final int TYPE_HEADER = 10001; |
| | | public final int TYPE_FOOTER = 10002; |
| | | |
| | | private Gson gson = new GsonBuilder().setVersion(1.0).setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | |
| | | |
| | | private View headerView; |
| | | private View footerView; |
| | | |
| | | public void setHeaderView(View view) { |
| | | this.headerView = view; |
| | | } |
| | | |
| | | public RecommendNewAdapter(Activity context, List contentList) { |
| | | public void setFooterView(View view) { |
| | | this.footerView = view; |
| | | if (contentList != null) { |
| | | notifyItemChanged(contentList.size() + (headerView != null ? 1 : 0)); |
| | | } |
| | | } |
| | | |
| | | public void removeFooterView() { |
| | | if (footerView != null) { |
| | | notifyItemRemoved(contentList.size() + (headerView != null ? 1 : 0)); |
| | | this.footerView = null; |
| | | } |
| | | } |
| | | |
| | | |
| | | public RecommendNewAdapter(Activity context, List contentList, int recyclerViewWidth) { |
| | | this.mContext = context; |
| | | this.contentList = contentList; |
| | | this.recyclerViewWidth = recyclerViewWidth; |
| | | inflater = LayoutInflater.from(mContext); |
| | | } |
| | | |
| | |
| | | switch (viewType) { |
| | | case TYPE_HEADER: |
| | | return new HeaderViewHolder(headerView); |
| | | case TYPE_FOOTER: |
| | | return new FooterViewHolder(footerView); |
| | | case RecommendContent.TYPE_HOMETYPE: |
| | | return new HomeTypeHolder(inflater.inflate(R.layout.item_recommend_home_type, null, false), new RecyclerView.RecycledViewPool()); |
| | | case RecommendContent.TYPE_AD: |
| | |
| | | } |
| | | |
| | | |
| | | private int recyclerViewWidth = -1; |
| | | |
| | | @Override |
| | | public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) { |
| | | if (viewHolder instanceof HeaderViewHolder) |
| | | return; |
| | | if (viewHolder instanceof FooterViewHolder) |
| | | return; |
| | | int p = i; |
| | | if (headerView != null) |
| | |
| | | if (viewHolder instanceof HomeTypeHolder) { |
| | | final HomeType homeType = (HomeType) contentList.get(p); |
| | | |
| | | |
| | | final HomeTypeHolder holder = (HomeTypeHolder) viewHolder; |
| | | |
| | | if (homeType == null) { |
| | | holder.view.setVisibility(View.GONE); |
| | | return; |
| | |
| | | if (homeType.getVideoInfoList() == null) { |
| | | homeType.setVideoInfoList(new ArrayList<>()); |
| | | } |
| | | |
| | | |
| | | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | holder.view.setLayoutParams(params); |
| | |
| | | homeType.getVideoInfoList().add(homeType.getHomeVideoList().get(j).getVideo()); |
| | | } |
| | | |
| | | holder.view.setVisibility(View.VISIBLE); |
| | | //隐藏 |
| | | if (homeType.getVideoInfoList() != null && homeType.getVideoInfoList().size() > 0) |
| | | holder.view.setVisibility(View.VISIBLE); |
| | | else |
| | | holder.view.setVisibility(View.GONE); |
| | | |
| | | VideoRecommendAdapter adapter = null; |
| | | |
| | | holder.rv_content.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); |
| | | |
| | | |
| | | int contentWidth = recyclerViewWidth - DimenUtils.dip2px(mContext, 16); |
| | | if (homeType.getColumns() > 3) {//第一排为小视频 |
| | | adapter = new VideoRecommendAdapter(mContext, mContext, homeType.getVideoInfoList(), homeType.isNeedAd(), Integer.MAX_VALUE, "recommend", homeType.getName(), null, new ExpressAdManager.IAdShowListener() { |
| | | @Override |
| | |
| | | holder.rv_content.scrollToPosition(0); |
| | | } |
| | | }); |
| | | adapter.initRecyclerViewDisplayWidthRow1(holder.rv_content); |
| | | adapter.initRecyclerViewDisplayWidthRow1(holder.rv_content, contentWidth); |
| | | } else { |
| | | adapter = new VideoRecommendAdapter(mContext, mContext, homeType.getVideoInfoList(), homeType.isNeedAd(), homeType.getColumns(), "recommend", homeType.getName(), null); |
| | | if (homeType.getColumns() == 2) |
| | | adapter.initRecyclerViewDisplayWidthColumn2(holder.rv_content, bigPictureIndex); |
| | | adapter.initRecyclerViewDisplayWidthColumn2(holder.rv_content, contentWidth, bigPictureIndex); |
| | | else if (homeType.getColumns() == 3) |
| | | adapter.initRecyclerViewDisplayWidthColumn3(holder.rv_content); |
| | | adapter.initRecyclerViewDisplayWidthColumn3(holder.rv_content, contentWidth); |
| | | else |
| | | adapter.initRecyclerViewDisplayWidthRow1(holder.rv_content); |
| | | adapter.initRecyclerViewDisplayWidthRow1(holder.rv_content, contentWidth); |
| | | } |
| | | |
| | | |
| | | if (homeType.getVideoInfoList() != null && homeType.getVideoInfoList().size() > 0) { |
| | | holder.rv_content.setAdapter(adapter); |
| | | } |
| | |
| | | //更多 |
| | | if (Boolean.parseBoolean(homeType.getHasMore())) { |
| | | holder.tv_more.setVisibility(View.VISIBLE); |
| | | if (!StringUtils.isEmpty(homeType.getMoreTag())) { |
| | | if (!StringUtils.isNullOrEmpty(homeType.getMoreTag())) { |
| | | holder.tv_more.setText(homeType.getMoreTag()); |
| | | } else { |
| | | holder.tv_more.setText("更多" + homeType.getName()); |
| | |
| | | } |
| | | |
| | | //不足一页不显示刷新 |
| | | if (homeType.getCount() <= homeType.getPageSize()) { |
| | | if (homeType.getCount() <= homeType.getNumber()) { |
| | | refreshP = 0; |
| | | } |
| | | |
| | |
| | | List<HomeVideo> homeList = new ArrayList<>(); |
| | | if (homeArray != null && homeArray.length() > 0) { |
| | | for (int j = 0; j < homeArray.length(); j++) { |
| | | homeList.add(gson.fromJson(homeArray |
| | | homeList.add(JsonUtil.videoGson.fromJson(homeArray |
| | | .optJSONObject(j).toString(), |
| | | HomeVideo.class)); |
| | | } |
| | |
| | | int count = this.contentList.size(); |
| | | if (headerView != null) |
| | | count++; |
| | | if (footerView != null) |
| | | count++; |
| | | return count; |
| | | } |
| | | |
| | |
| | | |
| | | if (headerView != null) |
| | | position--; |
| | | |
| | | if (position >= contentList.size()) |
| | | return TYPE_FOOTER; |
| | | |
| | | if (contentList.get(position) instanceof HomeType) |
| | | return RecommendContent.TYPE_HOMETYPE; |
| | | else |
| | | return RecommendContent.TYPE_AD; |
| | | |
| | | } |
| | | |
| | | class HomeTypeHolder extends RecyclerView.ViewHolder { |