|
|
package com.yinhebairong.shejiao.mine.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.text.TextUtils;
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.ViewTreeObserver;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
import com.yinhebairong.shejiao.R;
|
|
|
import com.yinhebairong.shejiao.base.BaseRvAdapter;
|
|
|
import com.yinhebairong.shejiao.base.BaseViewHolder;
|
|
|
import com.yinhebairong.shejiao.base.Config;
|
|
|
import com.yinhebairong.shejiao.base.Constants;
|
|
|
import com.yinhebairong.shejiao.base.ItemDivider;
|
|
|
import com.yinhebairong.shejiao.square.adapter.OnMomentItemListener;
|
|
|
import com.yinhebairong.shejiao.square.adapter.ZoneImageAdapter2;
|
|
|
import com.yinhebairong.shejiao.square.model.MomentModel;
|
|
|
import com.yinhebairong.shejiao.topic.model.TopicRankModel;
|
|
|
import com.yinhebairong.shejiao.util.GridLayoutHelper;
|
|
|
import com.yinhebairong.shejiao.util.ScreenUtil;
|
|
|
import com.yinhebairong.shejiao.util.SharedPreferenceUtil;
|
|
|
import com.yinhebairong.shejiao.util.TopicUtil;
|
|
|
import com.yinhebairong.shejiao.view.FlowLayout;
|
|
|
import com.yinhebairong.shejiao.view.LikeButton;
|
|
|
import com.yinhebairong.shejiao.view.MyGSYVideoPlayer;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @ClassName: MomentAdapter
|
|
|
* @Author: Lau
|
|
|
* @CreateDate: 2020/9/29 15:07
|
|
|
* @Description:
|
|
|
*/
|
|
|
public class CreatorOpusAdapter extends BaseRvAdapter<MomentModel> {
|
|
|
|
|
|
public static final String TYPE_IMAGE = "img";
|
|
|
public static final String TYPE_VIDEO = "mp4";
|
|
|
public static final String TYPE_TEXT_ONLY = "not";
|
|
|
public final int ITEM_TYPE_IMAGE = 1;
|
|
|
public final int ITEM_TYPE_VIDEO = 2;
|
|
|
public final int ITEM_TYPE_TEXT_ONLY = 3;
|
|
|
|
|
|
private List<BaseViewHolder> viewHolderList = new ArrayList<>();
|
|
|
|
|
|
private OnCreatorOpusItemClickListener onCreatorOpusItemClickListener = new CreatorOpusItemListener(this, mContext) {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void onLikeClick(View view, int position, MomentModel data) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFollowClick(ImageView imageView, MomentModel data) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
private boolean isUserPage;
|
|
|
//推荐的时间需要显示成xx秒/分钟/小时/天前推荐
|
|
|
private boolean isSuggest;
|
|
|
private long lastRefreshTime = 0;
|
|
|
|
|
|
public CreatorOpusAdapter(Context mContext, boolean isUserPage) {
|
|
|
super(mContext);
|
|
|
this.isUserPage = isUserPage;
|
|
|
}
|
|
|
|
|
|
public CreatorOpusAdapter setSuggest(boolean suggest) {
|
|
|
isSuggest = suggest;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
public void setLastRefreshTime(long lastRefreshTime) {
|
|
|
this.lastRefreshTime = lastRefreshTime;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected int getLayoutId(int viewType) {
|
|
|
switch (viewType) {
|
|
|
case ITEM_TYPE_TEXT_ONLY:
|
|
|
case ITEM_TYPE_VIDEO:
|
|
|
// return R.layout.item_zone_video;
|
|
|
case ITEM_TYPE_IMAGE:
|
|
|
return R.layout.item_creator_opus;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getItemViewType(int position) {
|
|
|
if (getData(position).getType() == null) {
|
|
|
return ITEM_TYPE_TEXT_ONLY;
|
|
|
}
|
|
|
if (getData(position).getType().equals(TYPE_VIDEO)) {
|
|
|
return ITEM_TYPE_VIDEO;
|
|
|
} else if (getData(position).getType().equals(TYPE_IMAGE)) {
|
|
|
return ITEM_TYPE_IMAGE;
|
|
|
} else {
|
|
|
return ITEM_TYPE_TEXT_ONLY;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
|
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
BaseViewHolder holder = super.onCreateViewHolder(parent, viewType);
|
|
|
this.viewHolderList.add(holder);
|
|
|
return holder;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onAfterInflaterView(View itemView, int viewType) {
|
|
|
if (viewType == ITEM_TYPE_IMAGE) {
|
|
|
RecyclerView rvImage = itemView.findViewById(R.id.rv);
|
|
|
rvImage.setLayoutManager(new GridLayoutManager(mContext, Constants.MOMENT_IMAGE_SPAN));
|
|
|
// rvImage.setAdapter(new ZoneImageAdapter2(R.layout.item_zone_image2, new ArrayList<>(), rvImage));
|
|
|
} else if (viewType == ITEM_TYPE_VIDEO) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void bindData(BaseViewHolder holder, MomentModel data, int position) {
|
|
|
if (isUserPage) {
|
|
|
holder.getView(R.id.vg_padding_left).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
|
|
|
holder.getView(R.id.vg_padding_left2).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
|
|
|
holder.getView(R.id.vg_padding_left3).setPadding(ScreenUtil.dp2px(14), 0, ScreenUtil.dp2px(14), 0);
|
|
|
holder.getView(R.id.vg_options).setPadding(0, 0, 0, 0);
|
|
|
|
|
|
//权限:look=广场可见,my=自己可见,index=主页可见
|
|
|
holder.setText(R.id.tv_permission, data.getAuth().equals("look") ? "广场可见" : data.getAuth().equals("my") ? "自己可见" : "主页可见")
|
|
|
.setVisibility(R.id.iv_option, data.getUser_id() == Config.USER_ID ? View.VISIBLE : View.GONE)
|
|
|
.setVisibility(R.id.tv_permission, data.getUser_id() == Config.USER_ID ? View.VISIBLE : View.GONE)
|
|
|
.setVisibility(R.id.iv_header, View.GONE)
|
|
|
.setVisibility(R.id.tv_name, View.GONE)
|
|
|
.setVisibility(R.id.iv_vip, View.GONE)
|
|
|
.setVisibility(R.id.tv_top, data.getTop_id() == 0 ? View.GONE : View.VISIBLE);
|
|
|
holder.setImage(R.id.iv_certification, data.getRen_id() != 0 ?
|
|
|
R.mipmap.icon_bigv3x :
|
|
|
data.getStudent_id() == 1 ?
|
|
|
R.mipmap.icon_student_certification : R.mipmap.icon_bigv3x)
|
|
|
.setVisibility(R.id.iv_certification,
|
|
|
(data.getRen_id() != 0 || data.getStudent_id() == 1) ?
|
|
|
View.VISIBLE : View.GONE);
|
|
|
} else {
|
|
|
holder.setVisibility(R.id.iv_option, data.getUser_id() == Config.USER_ID ? View.GONE : View.VISIBLE)
|
|
|
.setVisibility(R.id.tv_permission, View.GONE)
|
|
|
// .setVisibility(R.id.iv_header, View.VISIBLE)
|
|
|
// .setVisibility(R.id.tv_name, View.VISIBLE)
|
|
|
.setVisibility(R.id.iv_vip, data.getUser().getVip_id() == 1 ? View.VISIBLE : View.GONE)
|
|
|
.setImage(R.id.iv_header, R.mipmap.icon_loading_head3x, data.getUser().getAvatar2())
|
|
|
// .setText(R.id.tv_name, data.getUser().getNickname2())
|
|
|
.setVisibility(R.id.tv_top, View.GONE); //认证 优先顺序:大V>学生>不显示
|
|
|
holder.setImage(R.id.iv_certification, data.getUser().getRen_id() != 0 ?
|
|
|
R.mipmap.icon_bigv3x :
|
|
|
data.getUser().isStudent() ?
|
|
|
R.mipmap.icon_student_certification : R.mipmap.icon_bigv3x)
|
|
|
.setVisibility(R.id.iv_certification,
|
|
|
(data.getUser().getRen_id() != 0 || data.getUser().isStudent()) ?
|
|
|
View.VISIBLE : View.GONE);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置textView点击时间
|
|
|
TextView tvContent = holder.getView(R.id.tv_content);
|
|
|
TextView tvTips = holder.getView(R.id.tv_tips);
|
|
|
tvContent.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
|
//通用的数据
|
|
|
holder.setText(R.id.tv_title, data.getTitle2())
|
|
|
.setVisibility(R.id.tv_title, TextUtils.isEmpty(data.getTitle2()) ? View.GONE : View.VISIBLE)
|
|
|
.setText(R.id.tv_content, TopicUtil.getSpStr(data.getCnt(),holder.itemView.getContext(),data.getHua_arr()))
|
|
|
.setVisibility(R.id.tv_content, TextUtils.isEmpty(data.getCnt()) ? View.GONE : View.VISIBLE)
|
|
|
.setText(R.id.tv_place, data.getArea())
|
|
|
.setVisibility(R.id.vg_place, TextUtils.isEmpty(data.getArea()) ? View.GONE : View.VISIBLE)
|
|
|
.setImage(R.id.iv_zan, data.getZan_id() == 0 ? R.mipmap.icon_like_not : R.mipmap.icon_like_yet)
|
|
|
.setText(R.id.tv_zan, data.getZan_num() + "")
|
|
|
.setText(R.id.tv_ping, data.getPing_num() + "")
|
|
|
.<LikeButton>getView(R.id.lb_like).setCheck(data.getZan_id() == 1);
|
|
|
|
|
|
// 去掉文字块点击出现背景色
|
|
|
tvContent.setHighlightColor(ContextCompat.getColor(mContext, android.R.color.transparent));
|
|
|
LinearLayout linearLayoutTips = holder.getView(R.id.vg_close_tip_off);
|
|
|
ImageView imageViewCloseTips = holder.getView(R.id.iv_close_tip_off);
|
|
|
|
|
|
imageViewCloseTips.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
linearLayoutTips.setVisibility(View.GONE);
|
|
|
SharedPreferenceUtil.put(mContext,"close_tips",true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//时间
|
|
|
boolean closeTips = (boolean) SharedPreferenceUtil.get(mContext,"close_tips",false);
|
|
|
|
|
|
|
|
|
if (isSuggest) {
|
|
|
long duration = System.currentTimeMillis() - lastRefreshTime;
|
|
|
if (duration < 1000) {//一秒以内
|
|
|
holder.setText(R.id.tv_time, "刚刚推荐");
|
|
|
} else if (duration < 1000 * 60) {//一分钟以内
|
|
|
holder.setText(R.id.tv_time, duration / 1000 + "秒前推荐");
|
|
|
} else if (duration < 1000 * 60 * 60) {//一小时以内
|
|
|
holder.setText(R.id.tv_time, duration / 60000 + "分钟前推荐");
|
|
|
} else if (duration < 1000 * 60 * 60 * 24) {//一天以内
|
|
|
holder.setText(R.id.tv_time, duration / 3600000 + "小时前推荐");
|
|
|
} else {
|
|
|
holder.setText(R.id.tv_time, duration / 3600000 * 24 + "小时前推荐");
|
|
|
}
|
|
|
if (!closeTips){
|
|
|
if (position == 4){
|
|
|
tvTips.setText("获得礼物打赏可以转化为金币哟");
|
|
|
linearLayoutTips.setVisibility(View.VISIBLE);
|
|
|
}else if (position == 7){
|
|
|
tvTips.setText("金币可以进行现金兑换");
|
|
|
linearLayoutTips.setVisibility(View.VISIBLE);
|
|
|
} else{
|
|
|
linearLayoutTips.setVisibility(View.GONE);
|
|
|
}
|
|
|
}else {
|
|
|
linearLayoutTips.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
holder.setText(R.id.tv_time, data.getFa_time());
|
|
|
linearLayoutTips.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
//设置文字内容是否折叠(查看全部)
|
|
|
// TextView textView = holder.<TextView>getView(R.id.tv_content);
|
|
|
holder.<TextView>getView(R.id.tv_content).getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
@Override
|
|
|
public boolean onPreDraw() {
|
|
|
holder.<TextView>getView(R.id.tv_content).getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
if (holder.<TextView>getView(R.id.tv_content).getLineCount() > holder.<TextView>getView(R.id.tv_content).getMaxLines()) {
|
|
|
holder.setVisibility(R.id.tv_show_all_content, View.VISIBLE);
|
|
|
} else {
|
|
|
holder.setVisibility(R.id.tv_show_all_content, View.GONE);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//点击事件
|
|
|
View.OnClickListener onClickListener = v -> {
|
|
|
switch (v.getId()) {
|
|
|
case R.id.vg_user:
|
|
|
onCreatorOpusItemClickListener.onUserClick(v, position, data);
|
|
|
break;
|
|
|
case R.id.iv_option:
|
|
|
onCreatorOpusItemClickListener.onOptionClick(v, position, data);
|
|
|
break;
|
|
|
case R.id.vg_share:
|
|
|
onCreatorOpusItemClickListener.onShareClick(v, position, data);
|
|
|
break;
|
|
|
case R.id.vg_like:
|
|
|
if (data.getZan_id() == 0) {
|
|
|
data.setZan_id(1);
|
|
|
data.setZan_num(data.getZan_num() + 1);
|
|
|
holder.<LikeButton>getView(R.id.lb_like).setCheck(true, true);
|
|
|
holder.setText(R.id.tv_zan, data.getZan_num() + "");
|
|
|
} else {
|
|
|
data.setZan_id(0);
|
|
|
data.setZan_num(data.getZan_num() - 1);
|
|
|
holder.<LikeButton>getView(R.id.lb_like).setCheck(false, false);
|
|
|
holder.setText(R.id.tv_zan, data.getZan_num() + "");
|
|
|
}
|
|
|
onCreatorOpusItemClickListener.onLikeClick(v, position, data);
|
|
|
break;
|
|
|
case R.id.vg_ping:
|
|
|
onCreatorOpusItemClickListener.onCommentClick(v, position, data);
|
|
|
break;
|
|
|
default:
|
|
|
onCreatorOpusItemClickListener.onItemClick(v, position, data);
|
|
|
}
|
|
|
};
|
|
|
holder.setOnViewClickListener(R.id.vg_user, onClickListener)
|
|
|
.setOnViewClickListener(R.id.iv_option, onClickListener)
|
|
|
.setOnViewClickListener(R.id.vg_share, onClickListener)
|
|
|
.setOnViewClickListener(R.id.vg_like, onClickListener)
|
|
|
.setOnViewClickListener(R.id.vg_ping, onClickListener)
|
|
|
.getRootView().setOnClickListener(onClickListener);
|
|
|
//显示类型
|
|
|
switch (getItemViewType(position)) {
|
|
|
case ITEM_TYPE_TEXT_ONLY:
|
|
|
holder.setVisibility(R.id.rv, View.GONE)
|
|
|
.setVisibility(R.id.video_player, View.GONE);
|
|
|
break;
|
|
|
case ITEM_TYPE_IMAGE:
|
|
|
holder.setVisibility(R.id.rv, View.VISIBLE)
|
|
|
.setVisibility(R.id.video_player, View.GONE);
|
|
|
break;
|
|
|
case ITEM_TYPE_VIDEO:
|
|
|
holder.setVisibility(R.id.rv, View.GONE)
|
|
|
.setVisibility(R.id.video_player, View.VISIBLE);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (getItemViewType(position) == ITEM_TYPE_IMAGE) {
|
|
|
//图片
|
|
|
// if (data.getImg_arr() != null && data.getImg_arr().size() > 9) {
|
|
|
// data.setImg_arr(data.getImg_arr().subList(0, 9));
|
|
|
// }
|
|
|
//
|
|
|
if (holder.<RecyclerView>getView(R.id.rv).getAdapter() == null) {
|
|
|
holder.<RecyclerView>getView(R.id.rv).setAdapter(
|
|
|
new ZoneImageAdapter2(R.layout.item_zone_image2, new ArrayList<>(), holder.getView(R.id.rv)));
|
|
|
}
|
|
|
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setUserPageOrDetail(isUserPage);
|
|
|
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setMomentModel(data);
|
|
|
((ZoneImageAdapter2) holder.<RecyclerView>getView(R.id.rv).getAdapter()).setNewData(data.getImg_arr());
|
|
|
|
|
|
GridLayoutHelper.setOnMarginClickListener(holder.getView(R.id.rv), v -> onCreatorOpusItemClickListener.onItemClick(v, position, data));
|
|
|
|
|
|
} else if (getItemViewType(position) == ITEM_TYPE_VIDEO) {
|
|
|
//视频
|
|
|
holder.<MyGSYVideoPlayer>getView(R.id.video_player).initPlayer(data.getMp4_info(), position, isUserPage ?
|
|
|
ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(16 * 2) :
|
|
|
ScreenUtil.getScreenWidth() - ScreenUtil.dp2px(68 * 2), false, data.getId());
|
|
|
}
|
|
|
|
|
|
//话题
|
|
|
if (data.getHua_arr().isEmpty()) {
|
|
|
holder.setVisibility(R.id.flow_topic, View.GONE);
|
|
|
} else {
|
|
|
holder.setVisibility(R.id.flow_topic, View.VISIBLE)
|
|
|
.<FlowLayout>getView(R.id.flow_topic)
|
|
|
.addChildren(data.getHua_arr(), R.layout.flow_moment_topic)
|
|
|
.setDivider(30, 20)
|
|
|
.setOnBindData(new FlowLayout.OnChildDataBind<TopicRankModel>() {
|
|
|
@Override
|
|
|
public void onBindData(FlowLayout flowLayout, View itemView, int childPosition, TopicRankModel childData) {
|
|
|
TextView tvTopicName = itemView.findViewById(R.id.tv_topic_name);
|
|
|
tvTopicName.setText(childData.getName());
|
|
|
}
|
|
|
})
|
|
|
.setOnChildClickListener((flowLayout, itemView, childPosition, childData) -> onCreatorOpusItemClickListener.onTopicClick(itemView, position, data, childPosition, (TopicRankModel) childData));
|
|
|
}
|
|
|
|
|
|
//榜单
|
|
|
if (data.getBang() == null) {
|
|
|
holder.setVisibility(R.id.vg_bang, View.GONE);
|
|
|
} else {
|
|
|
holder.setVisibility(R.id.vg_bang, View.VISIBLE)
|
|
|
.setText(R.id.tv_bang, data.getBang().getStr())
|
|
|
.setOnViewClickListener(R.id.tv_hits, new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
onCreatorOpusItemClickListener.onHitsBangClick(v, position, data);
|
|
|
}
|
|
|
})
|
|
|
.setOnViewClickListener(R.id.vg_bang, new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
onCreatorOpusItemClickListener.onBangClick(v, position, data);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 分割线
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public RecyclerView.ItemDecoration getDivider() {
|
|
|
return new ItemDivider(2, mContext.getResources().getColor(R.color.divider));
|
|
|
}
|
|
|
|
|
|
public void setOnCreatorOpusItemClickListener(OnCreatorOpusItemClickListener
|
|
|
onCreatorOpusItemClickListener) {
|
|
|
this.onCreatorOpusItemClickListener = onCreatorOpusItemClickListener;
|
|
|
}
|
|
|
|
|
|
public List<BaseViewHolder> getViewHolderList() {
|
|
|
return viewHolderList;
|
|
|
}
|
|
|
|
|
|
public interface OnCreatorOpusItemClickListener {
|
|
|
//item
|
|
|
void onItemClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//用户
|
|
|
void onUserClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//更多选项
|
|
|
void onOptionClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//分享
|
|
|
void onShareClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//点赞
|
|
|
void onLikeClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//评论
|
|
|
void onCommentClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//话题
|
|
|
void onTopicClick(View view, int position, MomentModel data, int childPosition, TopicRankModel topicData);
|
|
|
|
|
|
//榜单
|
|
|
void onBangClick(View view, int position, MomentModel data);
|
|
|
|
|
|
//打榜
|
|
|
void onHitsBangClick(View view, int position, MomentModel data);
|
|
|
}
|
|
|
} |
...
|
...
|
|