2025-10-28 16:56:13 +08:00
|
|
|
|
package com.xscm.modulemain.dialog;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
import android.view.Gravity;
|
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
import android.view.Window;
|
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
import com.blankj.utilcode.util.LogUtils;
|
2025-10-28 16:56:13 +08:00
|
|
|
|
import com.xscm.modulemain.R;
|
|
|
|
|
|
import com.xscm.modulemain.adapter.CardRelationAdapter;
|
|
|
|
|
|
import com.xscm.modulemain.activity.room.contacts.CardRelationshipContacts;
|
|
|
|
|
|
import com.xscm.modulemain.databinding.DialogCardRelationBinding;
|
|
|
|
|
|
import com.xscm.modulemain.activity.room.presenter.CardRelationshipPresenter;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
import com.hjq.toast.ToastUtils;
|
|
|
|
|
|
import com.xscm.moduleutil.RoomAutionTimeBean;
|
|
|
|
|
|
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.RoomAuctionABean;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.RoomRelationBean;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.RoomTime;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.RoonGiftModel;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.ViewItem;
|
|
|
|
|
|
import com.xscm.moduleutil.bean.room.AuctionBean;
|
|
|
|
|
|
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
|
|
|
|
|
import com.xscm.moduleutil.utils.ColorManager;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-04 22:51:36 +08:00
|
|
|
|
* @author qx
|
|
|
|
|
|
* @data 2025/6/28
|
|
|
|
|
|
* @description: 卡关系弹框
|
2025-10-20 10:16:44 +08:00
|
|
|
|
*/
|
2025-12-04 22:51:36 +08:00
|
|
|
|
public class CardRelationshipFragment extends BaseMvpDialogFragment<CardRelationshipPresenter, DialogCardRelationBinding> implements CardRelationshipContacts.View {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
private String type;
|
|
|
|
|
|
private String roomId;
|
|
|
|
|
|
private String userId;
|
|
|
|
|
|
private CardRelationAdapter adapter;
|
|
|
|
|
|
private List<ViewItem> viewItems = new ArrayList<>();
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
private RoomAuctionABean roomAuctionABean;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
RoomRelationBean roomRelationBean;
|
|
|
|
|
|
RoomAutionTimeBean roomAutionTimeBean;
|
|
|
|
|
|
RoonGiftModel roonGiftModel;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected CardRelationshipPresenter bindPresenter() {
|
|
|
|
|
|
return new CardRelationshipPresenter(this, getActivity());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
public interface OnCardRelationListener{
|
|
|
|
|
|
void OnCardRelationListener(CardRelationshipFragment dialogFragment);
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
|
|
|
|
|
|
public static int show(String roomId, String userId, String type, FragmentManager fragmentManager,OnCardRelationListener onCardRelationListener) {
|
|
|
|
|
|
//activity 退到后台调用闪退
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 检查 FragmentManager 状态
|
|
|
|
|
|
if (fragmentManager.isDestroyed() || fragmentManager.isStateSaved()) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
CardRelationshipFragment dialogFragment = new CardRelationshipFragment();
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
|
args.putString("roomId", roomId);
|
|
|
|
|
|
args.putString("userId", userId);
|
|
|
|
|
|
args.putString("type", type);
|
|
|
|
|
|
dialogFragment.setArguments(args);
|
|
|
|
|
|
dialogFragment.show(fragmentManager, "CardRelationshipFragment");
|
|
|
|
|
|
onCardRelationListener.OnCardRelationListener(dialogFragment);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
LogUtils.e("CardRelationshipFragment", "show: " + e.getMessage());
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2025-10-20 10:16:44 +08:00
|
|
|
|
}
|
2025-12-04 22:51:36 +08:00
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onAttach(@NonNull Context context) {
|
|
|
|
|
|
super.onAttach(context);
|
|
|
|
|
|
type = getArguments().getString("type");
|
|
|
|
|
|
roomId = getArguments().getString("roomId");
|
|
|
|
|
|
userId = getArguments().getString("userId");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void initData() {
|
|
|
|
|
|
MvpPre.roomRelationList(type);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-04 22:51:36 +08:00
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onStart() {
|
|
|
|
|
|
super.onStart();
|
|
|
|
|
|
Window window = getDialog().getWindow();
|
|
|
|
|
|
if (window != null) {
|
|
|
|
|
|
// 设置固定高度为 500dp
|
|
|
|
|
|
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
2025-12-04 22:51:36 +08:00
|
|
|
|
int heightInDp = (int) (screenHeight * 0.6f);
|
|
|
|
|
|
;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
int heightInPx = (int) heightInDp;
|
|
|
|
|
|
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, heightInPx);
|
|
|
|
|
|
|
|
|
|
|
|
// 可选:设置动画样式(从底部弹出)
|
|
|
|
|
|
window.setWindowAnimations(com.xscm.moduleutil.R.style.CommonShowDialogBottom);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 设置不可通过点击外部关闭
|
|
|
|
|
|
getDialog().setCancelable(false);
|
|
|
|
|
|
getDialog().setCanceledOnTouchOutside(false);
|
|
|
|
|
|
}
|
2025-12-04 22:51:36 +08:00
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void initDialogStyle(Window window) {
|
|
|
|
|
|
super.initDialogStyle(window);
|
|
|
|
|
|
window.setGravity(Gravity.BOTTOM);
|
|
|
|
|
|
setStyle(DialogFragment.STYLE_NORMAL, com.xscm.moduleutil.R.style.CustomDialogFragmentTheme);
|
|
|
|
|
|
}
|
2025-12-04 22:51:36 +08:00
|
|
|
|
|
2025-10-20 10:16:44 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void initView() {
|
|
|
|
|
|
RecyclerView recyclerView = mBinding.recycleView;
|
|
|
|
|
|
GridLayoutManager layoutManager = new GridLayoutManager(requireContext(), 4); // 最大支持 4 列
|
|
|
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
|
|
|
|
|
// 设置 SpanSizeLookup 控制不同 item 占据的列数
|
|
|
|
|
|
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int getSpanSize(int position) {
|
|
|
|
|
|
int viewType = adapter.getItemViewType(position);
|
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
|
case ViewItem.TYPE_TEXT: // 文本占满整行
|
|
|
|
|
|
return 4;
|
|
|
|
|
|
case ViewItem.TYPE_RELATION: // 每行 2 个
|
2025-12-04 22:51:36 +08:00
|
|
|
|
return 1;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
case ViewItem.TYPE_GIFT: // 每行 3 个
|
|
|
|
|
|
return 1; // 3 个时,总列数 3,则每项占 1 列;若总列数为 4,则需调整
|
|
|
|
|
|
case ViewItem.TYPE_IMAGE_SELECTION: // 每行 4 个
|
2025-12-04 22:51:36 +08:00
|
|
|
|
return 1;
|
2025-10-20 10:16:44 +08:00
|
|
|
|
default:
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
adapter = new CardRelationAdapter();
|
|
|
|
|
|
recyclerView.setAdapter(adapter);
|
2025-12-04 22:51:36 +08:00
|
|
|
|
roomAuctionABean = new RoomAuctionABean();
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
// 模拟从网络获取 RoomAuctionABean 数据
|
|
|
|
|
|
|
|
|
|
|
|
// 构建 ViewItem 列表
|
|
|
|
|
|
|
|
|
|
|
|
mBinding.tvWheatQd.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View v) {
|
2025-12-04 22:51:36 +08:00
|
|
|
|
roomRelationBean = adapter.getSelectedRelation();
|
|
|
|
|
|
roomAutionTimeBean = adapter.getSelectedTime();
|
|
|
|
|
|
roonGiftModel = adapter.getSelectedGift();
|
|
|
|
|
|
if (type.equals("2")) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (roomRelationBean != null && roomAutionTimeBean != null && roonGiftModel != null) {
|
|
|
|
|
|
// 创建一个 RoomAuctionABean 对象
|
2025-12-04 22:51:36 +08:00
|
|
|
|
MvpPre.roomAuction(roomId, userId, roonGiftModel.getGift_id(), roomRelationBean.getRelation_id(), "2", roomAutionTimeBean.getHours() + "");
|
|
|
|
|
|
} else {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
ToastUtils.show("请选择竞拍信息");
|
|
|
|
|
|
}
|
2025-12-04 22:51:36 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (roomRelationBean != null && roonGiftModel != null) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
// MvpPre.roomAuctionTime(roonGiftModel.getGift_id());
|
|
|
|
|
|
MvpPre.roomAuction(roomId, userId, roonGiftModel.getGift_id(), roomRelationBean.getRelation_id(), "1", "");
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
} else {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
ToastUtils.show("请选择竞拍信息");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvWheatQd, ColorManager.getInstance().getPrimaryColorInt(), 53);
|
|
|
|
|
|
mBinding.tvWheatQd.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected int getLayoutId() {
|
|
|
|
|
|
return R.layout.dialog_card_relation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void roomRelationList(List<RoomRelationBean> roomRelationBeans) {
|
2025-12-04 22:51:36 +08:00
|
|
|
|
if (roomRelationBeans != null) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
roomAuctionABean.setRoomRelationBeanList(roomRelationBeans);
|
|
|
|
|
|
MvpPre.getGiftList("99");
|
2025-12-04 22:51:36 +08:00
|
|
|
|
} else {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
ToastUtils.show("数据接口错误");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void setGiftList(List<RoonGiftModel> roonGiftModels) {
|
2025-12-04 22:51:36 +08:00
|
|
|
|
if (roonGiftModels != null) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
roomAuctionABean.setRoomGiftBeanList(roonGiftModels);
|
|
|
|
|
|
upList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void roomAuction(AuctionBean auctionBean) {
|
|
|
|
|
|
dismiss();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void roomAuctionTime(RoomTime roomTime) {
|
|
|
|
|
|
MvpPre.roomAuction(roomId, userId, roonGiftModel.getGift_id(), roomRelationBean.getRelation_id(), "1", roomTime.getTime_day());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
private void upList() {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
if (roomAuctionABean != null) {
|
|
|
|
|
|
// 添加文本项
|
|
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_TEXT, "选择关系"));
|
|
|
|
|
|
|
|
|
|
|
|
// 添加关系列表
|
|
|
|
|
|
for (RoomRelationBean bean : roomAuctionABean.getRoomRelationBeanList()) {
|
|
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_RELATION, bean));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-04 22:51:36 +08:00
|
|
|
|
if (type.equals("2")) {
|
2025-10-20 10:16:44 +08:00
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_TEXT, "选择时长"));
|
|
|
|
|
|
for (RoomAutionTimeBean bean : getDefaultTimeOptions()) {
|
|
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_IMAGE_SELECTION, bean));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_TEXT, "选择礼物"));
|
|
|
|
|
|
// 添加礼物列表
|
|
|
|
|
|
for (RoonGiftModel bean : roomAuctionABean.getRoomGiftBeanList()) {
|
|
|
|
|
|
viewItems.add(new ViewItem(ViewItem.TYPE_GIFT, bean));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
adapter.submitList(viewItems);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<RoomAutionTimeBean> getDefaultTimeOptions() {
|
|
|
|
|
|
List<RoomAutionTimeBean> list = new ArrayList<>();
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(1));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(3));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(5));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(10));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(15));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(20));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(25));
|
|
|
|
|
|
list.add(new RoomAutionTimeBean(30));
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void dismissDialog() {
|
|
|
|
|
|
dismiss();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDestroyView() {
|
|
|
|
|
|
super.onDestroyView();
|
|
|
|
|
|
dismiss();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|