2025-10-28 16:56:13 +08:00
|
|
|
package com.xscm.modulemain.adapter;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
2025-10-28 16:56:13 +08:00
|
|
|
import com.xscm.modulemain.R;
|
2025-10-20 10:16:44 +08:00
|
|
|
import com.xscm.moduleutil.bean.GiftBoxRecordBean;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class GiftBoxAdapter extends RecyclerView.Adapter<GiftBoxAdapter.GiftBoxViewHolder> {
|
|
|
|
|
|
|
|
|
|
private static final int TYPE_HEADER = 0;
|
|
|
|
|
private static final int TYPE_ITEM = 1;
|
|
|
|
|
|
|
|
|
|
private List<GiftBoxRecordBean> giftBoxList;
|
|
|
|
|
|
|
|
|
|
public GiftBoxAdapter(List<GiftBoxRecordBean> giftBoxList) {
|
|
|
|
|
this.giftBoxList = giftBoxList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public GiftBoxViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
|
View view;
|
|
|
|
|
if (viewType == TYPE_HEADER) {
|
|
|
|
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gift_box, parent, false);
|
|
|
|
|
// 设置标题可见
|
|
|
|
|
view.findViewById(R.id.tv_label_time).setVisibility(View.VISIBLE);
|
|
|
|
|
view.findViewById(R.id.tv_label_gift_name).setVisibility(View.VISIBLE);
|
|
|
|
|
view.findViewById(R.id.tv_label_obtain).setVisibility(View.VISIBLE);
|
|
|
|
|
// 隐藏数据项
|
|
|
|
|
view.findViewById(R.id.tv_time).setVisibility(View.GONE);
|
|
|
|
|
view.findViewById(R.id.tv_gift_name).setVisibility(View.GONE);
|
|
|
|
|
view.findViewById(R.id.tv_obtain).setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gift_box, parent, false);
|
|
|
|
|
// 设置数据项可见
|
|
|
|
|
view.findViewById(R.id.tv_time).setVisibility(View.VISIBLE);
|
|
|
|
|
view.findViewById(R.id.tv_gift_name).setVisibility(View.VISIBLE);
|
|
|
|
|
view.findViewById(R.id.tv_obtain).setVisibility(View.VISIBLE);
|
|
|
|
|
// 隐藏标题项
|
|
|
|
|
view.findViewById(R.id.tv_label_time).setVisibility(View.GONE);
|
|
|
|
|
view.findViewById(R.id.tv_label_gift_name).setVisibility(View.GONE);
|
|
|
|
|
view.findViewById(R.id.tv_label_obtain).setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
return new GiftBoxViewHolder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(@NonNull GiftBoxViewHolder holder, int position) {
|
|
|
|
|
if (position == 0) {
|
|
|
|
|
// 设置标题文本
|
|
|
|
|
holder.tvLabelTime.setText("时间");
|
|
|
|
|
holder.tvLabelGiftName.setText("礼盒名称");
|
|
|
|
|
holder.tvLabelObtain.setText("获取");
|
|
|
|
|
} else {
|
|
|
|
|
GiftBoxRecordBean giftBox = giftBoxList.get(position - 1);
|
|
|
|
|
holder.tvTime.setText(giftBox.getCreatetime());
|
|
|
|
|
holder.tvGiftName.setText(giftBox.getGift_bag_name());
|
|
|
|
|
holder.tvObtain.setText(giftBox.getGift_name());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return giftBoxList.size() + 1; // 加上标题项
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
|
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class GiftBoxViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
TextView tvLabelTime;
|
|
|
|
|
TextView tvLabelGiftName;
|
|
|
|
|
TextView tvLabelObtain;
|
|
|
|
|
TextView tvTime;
|
|
|
|
|
TextView tvGiftName;
|
|
|
|
|
TextView tvObtain;
|
|
|
|
|
|
|
|
|
|
GiftBoxViewHolder(View view) {
|
|
|
|
|
super(view);
|
|
|
|
|
tvLabelTime = view.findViewById(R.id.tv_label_time);
|
|
|
|
|
tvLabelGiftName = view.findViewById(R.id.tv_label_gift_name);
|
|
|
|
|
tvLabelObtain = view.findViewById(R.id.tv_label_obtain);
|
|
|
|
|
tvTime = view.findViewById(R.id.tv_time);
|
|
|
|
|
tvGiftName = view.findViewById(R.id.tv_gift_name);
|
|
|
|
|
tvObtain = view.findViewById(R.id.tv_obtain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|