496 lines
20 KiB
Java
496 lines
20 KiB
Java
package com.xscm.modulemain.adapter;
|
||
|
||
import android.annotation.SuppressLint;
|
||
import android.content.Context;
|
||
import android.text.SpannableString;
|
||
import android.text.Spanned;
|
||
import android.text.TextUtils;
|
||
import android.text.style.ForegroundColorSpan;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.widget.ImageView;
|
||
import android.widget.TextView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||
import androidx.core.content.ContextCompat;
|
||
import androidx.recyclerview.widget.RecyclerView;
|
||
|
||
import com.alibaba.android.arouter.launcher.ARouter;
|
||
import com.xscm.modulemain.R;
|
||
import com.xscm.modulemain.activity.room.activity.RoomActivity;
|
||
import com.xscm.modulemain.activity.user.activity.MyRoomActivity;
|
||
import com.makeramen.roundedimageview.RoundedImageView;
|
||
import com.xscm.modulemain.manager.RoomManager;
|
||
import com.xscm.moduleutil.RoomAutionTimeBean;
|
||
import com.xscm.moduleutil.bean.MyCpRoom;
|
||
import com.xscm.moduleutil.bean.MyFootResp;
|
||
import com.xscm.moduleutil.bean.MyRoomBean;
|
||
import com.xscm.moduleutil.bean.RoomData;
|
||
import com.xscm.moduleutil.bean.RoomRelationBean;
|
||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||
import com.xscm.moduleutil.bean.ViewItem;
|
||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||
import com.xscm.moduleutil.dialog.ConfirmDialog;
|
||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||
import com.xscm.moduleutil.utils.ColorManager;
|
||
import com.xscm.moduleutil.utils.ImageUtils;
|
||
import com.xscm.moduleutil.widget.GifAvatarOvalView;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
public class MyCreateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||
|
||
private List<ViewItem> viewItems = new ArrayList<>();
|
||
private int selectedRelationPosition = -1;
|
||
private int selectedTimePosition = -1;
|
||
private int selectedGiftPosition = -1;
|
||
|
||
private MyRoomActivity myRoomActivity;
|
||
|
||
public void setMyRoomActivity(MyRoomActivity myRoomActivity) {
|
||
this.myRoomActivity = myRoomActivity;
|
||
}
|
||
|
||
public void submitList(List<ViewItem> items) {
|
||
if (items == null || items.isEmpty()) {
|
||
viewItems.clear();
|
||
notifyDataSetChanged();
|
||
return;
|
||
}
|
||
|
||
List<ViewItem> filteredList = new ArrayList<>();
|
||
for (ViewItem item : items) {
|
||
int type = item.getType();
|
||
Object data = item.getData();
|
||
|
||
// 判断是否为空数据
|
||
boolean isValid = true;
|
||
|
||
switch (type) {
|
||
case ViewItem.TYPE_TEXT:
|
||
// 文本类型直接展示(字符串不会为 null)
|
||
break;
|
||
|
||
case ViewItem.TYPE_RELATION:
|
||
isValid = data instanceof MyRoomBean && ((MyRoomBean) data).getRoom_name() != null; // 假设你有一个 isValid() 方法判断是否为空
|
||
break;
|
||
|
||
case ViewItem.TYPE_GIFT:
|
||
isValid = data instanceof MyCpRoom && !TextUtils.isEmpty(((MyCpRoom) data).getRoom_name()); // 示例判断字段非空
|
||
break;
|
||
|
||
case ViewItem.TYPE_IMAGE_SELECTION:
|
||
isValid = data instanceof MyFootResp && !TextUtils.isEmpty(((MyFootResp) data).getRoom_name());
|
||
break;
|
||
|
||
default:
|
||
isValid = false; // 默认不展示未知类型
|
||
break;
|
||
}
|
||
|
||
if (isValid) {
|
||
filteredList.add(item);
|
||
}
|
||
}
|
||
|
||
viewItems.clear();
|
||
viewItems.addAll(filteredList);
|
||
notifyDataSetChanged();
|
||
}
|
||
|
||
|
||
@Override
|
||
public int getItemViewType(int position) {
|
||
return viewItems.get(position).getType();
|
||
}
|
||
|
||
@NonNull
|
||
@Override
|
||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||
|
||
switch (viewType) {
|
||
case ViewItem.TYPE_TEXT:
|
||
return new TextViewHolder(inflater.inflate(R.layout.room_li_bu, parent, false));
|
||
case ViewItem.TYPE_RELATION:
|
||
return new RelationViewHolder(inflater.inflate(R.layout.room_fragment_my_room_list, parent, false));
|
||
case ViewItem.TYPE_GIFT:
|
||
return new RelationViewTimHolder(myRoomActivity,inflater.inflate(R.layout.room_fragment_my_room_cp_list, parent, false));
|
||
case ViewItem.TYPE_IMAGE_SELECTION:
|
||
return new GiftViewHolder(myRoomActivity,inflater.inflate(R.layout.room_index_item_chatroom_my_foot, parent, false));
|
||
default:
|
||
throw new IllegalArgumentException("Unknown view type");
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
|
||
ViewItem item = viewItems.get(position);
|
||
|
||
switch (item.getType()) {
|
||
case ViewItem.TYPE_TEXT:
|
||
RoomData roomData = (RoomData) item.getData();
|
||
((TextViewHolder) holder).bind((roomData));
|
||
break;
|
||
case ViewItem.TYPE_RELATION:
|
||
MyRoomBean relationBean = (MyRoomBean) item.getData();
|
||
((RelationViewHolder) holder).bind(relationBean);
|
||
|
||
break;
|
||
case ViewItem.TYPE_IMAGE_SELECTION:
|
||
MyFootResp myFootResp = (MyFootResp) item.getData();
|
||
((GiftViewHolder) holder).bind(myFootResp);
|
||
break;
|
||
case ViewItem.TYPE_GIFT:
|
||
|
||
MyCpRoom roomAutionTimeBean = (MyCpRoom) item.getData();
|
||
((RelationViewTimHolder) holder).bind(roomAutionTimeBean);
|
||
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
public interface OnItemSelectedListener {
|
||
void onItemSelected(int viewType, int position);
|
||
}
|
||
|
||
private OnItemSelectedListener listener;
|
||
|
||
public void setOnItemSelectedListener(OnItemSelectedListener listener) {
|
||
this.listener = listener;
|
||
}
|
||
|
||
public RoomRelationBean getSelectedRelation() {
|
||
if (selectedRelationPosition != -1) {
|
||
ViewItem item = viewItems.get(selectedRelationPosition);
|
||
if (item.getData() instanceof RoomRelationBean) {
|
||
return (RoomRelationBean) item.getData();
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public RoomAutionTimeBean getSelectedTime() {
|
||
if (selectedTimePosition != -1) {
|
||
ViewItem item = viewItems.get(selectedTimePosition);
|
||
if (item.getData() instanceof RoomAutionTimeBean) {
|
||
return (RoomAutionTimeBean) item.getData();
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public RoonGiftModel getSelectedGift() {
|
||
if (selectedGiftPosition != -1) {
|
||
ViewItem item = viewItems.get(selectedGiftPosition);
|
||
if (item.getData() instanceof RoonGiftModel) {
|
||
return (RoonGiftModel) item.getData();
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
// 定义接口
|
||
public interface OnImageClickListener {
|
||
void onImageClick(View view, RoomData roomData);
|
||
}
|
||
|
||
// 添加接口类型的变量
|
||
private static OnImageClickListener onImageClickListener;
|
||
|
||
// 提供一个方法来设置接口变量
|
||
public void setOnImageClickListener(OnImageClickListener listener) {
|
||
this.onImageClickListener = listener;
|
||
}
|
||
|
||
@Override
|
||
public int getItemCount() {
|
||
return viewItems.size();
|
||
}
|
||
|
||
static class TextViewHolder extends RecyclerView.ViewHolder {
|
||
TextView textView;
|
||
ImageView imageView1, imageView2;
|
||
|
||
TextViewHolder(View itemView) {
|
||
super(itemView);
|
||
textView = itemView.findViewById(R.id.tv_title);
|
||
imageView1 = itemView.findViewById(R.id.iv_footprint);
|
||
imageView2 = itemView.findViewById(R.id.iv_delete_foot);
|
||
}
|
||
|
||
void bind(RoomData roomData) {
|
||
textView.setText(roomData.getTitle());
|
||
if (roomData.getTitleType() == 0) {
|
||
imageView2.setVisibility(View.INVISIBLE);
|
||
} else {
|
||
imageView2.setVisibility(View.VISIBLE);
|
||
imageView2.setImageResource(roomData.getTitleType());
|
||
}
|
||
imageView1.setImageResource(roomData.getTitleIcon());
|
||
|
||
imageView2.setOnClickListener(new View.OnClickListener() {
|
||
|
||
@Override
|
||
public void onClick(View view) {
|
||
if (onImageClickListener != null) {
|
||
onImageClickListener.onImageClick(view, roomData);
|
||
}
|
||
}
|
||
});
|
||
|
||
}
|
||
}
|
||
|
||
class RelationViewHolder extends RecyclerView.ViewHolder {
|
||
RoundedImageView riv;
|
||
ImageView iv_play, im_sh;
|
||
TextView tv_name;
|
||
TextView tv_sy;
|
||
TextView tv_user_id, tv_gz, tv_zx, tv_fw, rl_mx, tv_room_bt;
|
||
ConstraintLayout cl_my_room_list;
|
||
|
||
RelationViewHolder(View itemView) {
|
||
super(itemView);
|
||
riv = itemView.findViewById(R.id.riv);
|
||
iv_play = itemView.findViewById(R.id.iv_play);
|
||
tv_name = itemView.findViewById(R.id.tv_name);
|
||
tv_sy = itemView.findViewById(R.id.tv_sy);
|
||
tv_user_id = itemView.findViewById(R.id.tv_user_id);
|
||
tv_gz = itemView.findViewById(R.id.tv_gz);
|
||
tv_zx = itemView.findViewById(R.id.tv_zx);
|
||
tv_fw = itemView.findViewById(R.id.tv_fw);
|
||
rl_mx = itemView.findViewById(R.id.rl_mx);
|
||
tv_room_bt = itemView.findViewById(R.id.tv_room_bt);
|
||
im_sh = itemView.findViewById(R.id.im_sh);
|
||
cl_my_room_list = itemView.findViewById(R.id.cl_my_room_list);
|
||
}
|
||
|
||
void bind(MyRoomBean item) {
|
||
|
||
|
||
ImageUtils.loadImageView(item.getRoom_cover(), riv);
|
||
if (item.getLabel_icon() != null) {
|
||
ImageUtils.loadImageView(item.getLabel_icon(), iv_play);
|
||
}
|
||
tv_name.setText(item.getRoom_name());
|
||
tv_sy.setText(item.getToday_profit() + "");
|
||
tv_user_id.setText("ID: " + item.getRoom_number());
|
||
|
||
String concernText = "关注:" + item.getFollow_num();
|
||
SpannableString spannableString = new SpannableString(concernText);
|
||
// 设置关注数字部分的颜色为黑色
|
||
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(itemView.getContext(), R.color.black)), 2, concernText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||
tv_gz.setText(spannableString);
|
||
|
||
|
||
String concernText1 = "在线:" + item.getOnline_num();
|
||
SpannableString spannableString1 = new SpannableString(concernText1);
|
||
// 设置关注数字部分的颜色为黑色
|
||
spannableString1.setSpan(new ForegroundColorSpan(ContextCompat.getColor(itemView.getContext(), R.color.black)), 2, concernText1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||
tv_zx.setText(spannableString1);
|
||
|
||
String concernText2 = "访问:" + item.getVisit_num();
|
||
SpannableString spannableString2 = new SpannableString(concernText2);
|
||
// 设置关注数字部分的颜色为黑色
|
||
spannableString2.setSpan(new ForegroundColorSpan(ContextCompat.getColor(itemView.getContext(), R.color.black)), 2, concernText2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||
tv_fw.setText(spannableString2);
|
||
|
||
rl_mx.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
// TODO: 跳转到房间详情页面
|
||
if (item.getApply_status().equals("1")) {
|
||
queren(itemView.getContext());
|
||
return;
|
||
}
|
||
if (myRoomActivity != null)
|
||
myRoomActivity.isShowLoading(true);
|
||
// startActivity(new Intent(getContext(), RoomDetailsActivity.class));
|
||
ARouter.getInstance().build(ARouteConstants.MY_ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||
}
|
||
});
|
||
cl_my_room_list.setOnClickListener(new View.OnClickListener() {//跳转房间
|
||
@Override
|
||
public void onClick(View v) {
|
||
if (item.getApply_status().equals("1")) {
|
||
queren(itemView.getContext());
|
||
return;
|
||
}
|
||
if (myRoomActivity != null)
|
||
myRoomActivity.isShowLoading(true);
|
||
RoomManager.getInstance().fetchRoomDataAndEnter(itemView.getContext(), item.getRoom_id() + "", "",null);
|
||
|
||
// TODO: 跳转到房间
|
||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", item.getRoom_id() + "").navigation();
|
||
}
|
||
});
|
||
tv_room_bt.setOnClickListener(new View.OnClickListener() {
|
||
|
||
@Override
|
||
public void onClick(View v) {//房间补贴
|
||
if (item.getApply_status().equals("1")) {
|
||
queren(itemView.getContext());
|
||
return;
|
||
}
|
||
RoomManager.getInstance().fetchRoomDataAndEnter(itemView.getContext(), item.getRoom_id() + "", "",null);
|
||
|
||
// ARouter.getInstance().build(ARouteConstants.ROOM_ALLOWANCE).withString("from", "我的界面").withString("roomId", item.getRoom_id() + "").navigation();
|
||
}
|
||
});
|
||
|
||
if (item.getApply_status().equals("2")) {
|
||
im_sh.setVisibility(View.GONE);
|
||
} else if (item.getApply_status().equals("1")) {
|
||
im_sh.setVisibility(View.VISIBLE);
|
||
}
|
||
|
||
ThemeableDrawableUtils.setThemeableRoundedBackground(rl_mx, itemView.getContext().getColor(com.xscm.moduleutil.R.color.color6c49e25), 53);
|
||
rl_mx.setTextColor(ColorManager.getInstance().getPrimaryColorInt());
|
||
ThemeableDrawableUtils.setThemeableRoundedBackground(tv_room_bt, itemView.getContext().getColor(com.xscm.moduleutil.R.color.colorCDEB52E), 53);
|
||
tv_room_bt.setTextColor(ContextCompat.getColor(itemView.getContext(), com.xscm.moduleutil.R.color.colorC58600));
|
||
}
|
||
}
|
||
|
||
private static void queren(Context context) {
|
||
// 创建并显示确认对话框
|
||
new ConfirmDialog(context,
|
||
"温馨提示",
|
||
"您创建的房间正在审核中,请耐心等待或联系人工客服解决处理",
|
||
"知道了",
|
||
"",
|
||
v -> {
|
||
// 点击“确认”按钮时执行删除操作
|
||
},
|
||
v -> {
|
||
// 点击“取消”按钮时什么都不做
|
||
}, false, 0).show();
|
||
}
|
||
|
||
static class RelationViewTimHolder extends RecyclerView.ViewHolder {
|
||
|
||
ConstraintLayout cl_my_room_list;
|
||
GifAvatarOvalView user_avatar1, user_avatar2;
|
||
TextView tv_gx, tv_name, tv_sy, tv_user_id, room_head_top2, room_head_top3, rl_mx, tv_time;
|
||
ImageView iv_play;
|
||
private MyRoomActivity myRoomActivity;
|
||
RelationViewTimHolder(MyRoomActivity myRoomActivity ,View itemView) {
|
||
super(itemView);
|
||
this.myRoomActivity = myRoomActivity;
|
||
cl_my_room_list = itemView.findViewById(R.id.cl_my_room_list);
|
||
user_avatar1 = itemView.findViewById(R.id.user_avatar1);
|
||
user_avatar2 = itemView.findViewById(R.id.user_avatar2);
|
||
tv_gx = itemView.findViewById(R.id.tv_gx);
|
||
iv_play = itemView.findViewById(R.id.iv_play);
|
||
tv_name = itemView.findViewById(R.id.tv_name);
|
||
tv_sy = itemView.findViewById(R.id.tv_sy);
|
||
tv_user_id = itemView.findViewById(R.id.tv_user_id);
|
||
room_head_top2 = itemView.findViewById(R.id.room_head_top2);
|
||
room_head_top3 = itemView.findViewById(R.id.room_head_top3);
|
||
rl_mx = itemView.findViewById(R.id.rl_mx);
|
||
tv_time = itemView.findViewById(R.id.tv_time);
|
||
}
|
||
|
||
void bind(MyCpRoom item) {
|
||
ImageUtils.loadImageView(item.getUser1_avatar(), user_avatar1);
|
||
ImageUtils.loadImageView(item.getUser2_avatar(), user_avatar2);
|
||
tv_gx.setText(item.getRelation());
|
||
tv_name.setText(item.getRoom_name());
|
||
tv_sy.setText(item.getEarnings() + "");
|
||
tv_user_id.setText("ID: " + item.getRoom_number());
|
||
// room_head_top2.setText();
|
||
tv_time.setText(formatTimestampToDaysHours(Long.parseLong(item.getEnd_time())));
|
||
rl_mx.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
|
||
if (myRoomActivity != null){
|
||
myRoomActivity.isShowLoading(true);
|
||
}
|
||
|
||
// TODO: 跳转到房间详情页面
|
||
RoomManager.getInstance().fetchRoomDataAndEnter(itemView.getContext(), item.getRoom_id() + "", "",null);
|
||
|
||
// startActivity(new Intent(getContext(), RoomDetailsActivity.class));
|
||
// ARouter.getInstance().build(ARouteConstants.MY_ROOM_DETAILS).withString("roomId", item.getRoom_id() + "").navigation();
|
||
}
|
||
});
|
||
cl_my_room_list.setOnClickListener(new View.OnClickListener() {//跳转房间
|
||
@Override
|
||
public void onClick(View v) {
|
||
if (myRoomActivity != null){
|
||
myRoomActivity.isShowLoading(true);
|
||
}
|
||
|
||
RoomManager.getInstance().fetchRoomDataAndEnter(itemView.getContext(), item.getRoom_id() + "", "",null);
|
||
|
||
// TODO: 跳转到房间
|
||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", item.getRoom_id() + "").navigation();
|
||
}
|
||
});
|
||
|
||
ThemeableDrawableUtils.setThemeableRoundedBackground(rl_mx, itemView.getContext().getColor(com.xscm.moduleutil.R.color.color6c49e25), 53);
|
||
rl_mx.setTextColor(ColorManager.getInstance().getPrimaryColorInt());
|
||
}
|
||
}
|
||
|
||
public static String formatTimestampToDaysHours(long timestamp) {
|
||
// 获取当前时间戳(秒)
|
||
long currentTimestamp = System.currentTimeMillis() / 1000;
|
||
|
||
// 计算时间差(秒)
|
||
long timeDifferenceSeconds = Math.abs(currentTimestamp - timestamp);
|
||
|
||
// 转换为天数和小时数
|
||
long days = timeDifferenceSeconds / (24 * 60 * 60);
|
||
long remainingSecondsAfterDays = timeDifferenceSeconds % (24 * 60 * 60);
|
||
long hours = remainingSecondsAfterDays / (60 * 60);
|
||
|
||
return days + "天 " + hours + "小时";
|
||
}
|
||
|
||
static class GiftViewHolder extends RecyclerView.ViewHolder {
|
||
RoundedImageView iv_follow_bg;
|
||
ImageView iv_type, iv_play;
|
||
TextView tv_name, tv_num;
|
||
ConstraintLayout rl_root;
|
||
|
||
private MyRoomActivity roomActivity;
|
||
GiftViewHolder(MyRoomActivity roomActivity, View itemView) {
|
||
super(itemView);
|
||
this.roomActivity = roomActivity;
|
||
iv_follow_bg = itemView.findViewById(R.id.iv_follow_bg);
|
||
iv_type = itemView.findViewById(R.id.iv_type);
|
||
tv_name = itemView.findViewById(R.id.tv_name);
|
||
iv_play = itemView.findViewById(R.id.iv_play);
|
||
tv_num = itemView.findViewById(R.id.tv_num);
|
||
rl_root = itemView.findViewById(R.id.rl_root);
|
||
}
|
||
|
||
void bind(MyFootResp item) {
|
||
ImageUtils.loadHeadCC(item.getRoom_cover(), iv_follow_bg);
|
||
ImageUtils.loadHeadCC(item.getLabel_icon(), iv_type);
|
||
|
||
tv_name.setText(item.getRoom_name());
|
||
tv_num.setText(item.getHot_value());
|
||
|
||
rl_root.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
if (roomActivity != null){
|
||
roomActivity.isShowLoading(true);
|
||
}
|
||
RoomManager.getInstance().fetchRoomDataAndEnter(itemView.getContext(), item.getRoom_id() + "", "",null);
|
||
|
||
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", item.getRoom_id() + "").navigation();
|
||
|
||
}
|
||
});
|
||
}
|
||
}
|
||
} |