279 lines
10 KiB
Java
279 lines
10 KiB
Java
package com.xscm.modulemain.dialog;
|
||
|
||
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;
|
||
|
||
import com.blankj.utilcode.util.LogUtils;
|
||
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;
|
||
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;
|
||
|
||
/**
|
||
* @author qx
|
||
* @data 2025/6/28
|
||
* @description: 卡关系弹框
|
||
*/
|
||
public class CardRelationshipFragment extends BaseMvpDialogFragment<CardRelationshipPresenter, DialogCardRelationBinding> implements CardRelationshipContacts.View {
|
||
|
||
private String type;
|
||
private String roomId;
|
||
private String userId;
|
||
private CardRelationAdapter adapter;
|
||
private List<ViewItem> viewItems = new ArrayList<>();
|
||
|
||
private RoomAuctionABean roomAuctionABean;
|
||
RoomRelationBean roomRelationBean;
|
||
RoomAutionTimeBean roomAutionTimeBean;
|
||
RoonGiftModel roonGiftModel;
|
||
|
||
@Override
|
||
protected CardRelationshipPresenter bindPresenter() {
|
||
return new CardRelationshipPresenter(this, getActivity());
|
||
}
|
||
|
||
public interface OnCardRelationListener{
|
||
void OnCardRelationListener(CardRelationshipFragment dialogFragment);
|
||
}
|
||
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
@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);
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onStart() {
|
||
super.onStart();
|
||
Window window = getDialog().getWindow();
|
||
if (window != null) {
|
||
// 设置固定高度为 500dp
|
||
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
||
int heightInDp = (int) (screenHeight * 0.6f);
|
||
;
|
||
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);
|
||
}
|
||
|
||
@Override
|
||
protected void initDialogStyle(Window window) {
|
||
super.initDialogStyle(window);
|
||
window.setGravity(Gravity.BOTTOM);
|
||
setStyle(DialogFragment.STYLE_NORMAL, com.xscm.moduleutil.R.style.CustomDialogFragmentTheme);
|
||
}
|
||
|
||
@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 个
|
||
return 1;
|
||
case ViewItem.TYPE_GIFT: // 每行 3 个
|
||
return 1; // 3 个时,总列数 3,则每项占 1 列;若总列数为 4,则需调整
|
||
case ViewItem.TYPE_IMAGE_SELECTION: // 每行 4 个
|
||
return 1;
|
||
default:
|
||
return 1;
|
||
}
|
||
}
|
||
});
|
||
adapter = new CardRelationAdapter();
|
||
recyclerView.setAdapter(adapter);
|
||
roomAuctionABean = new RoomAuctionABean();
|
||
|
||
// 模拟从网络获取 RoomAuctionABean 数据
|
||
|
||
// 构建 ViewItem 列表
|
||
|
||
mBinding.tvWheatQd.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
roomRelationBean = adapter.getSelectedRelation();
|
||
roomAutionTimeBean = adapter.getSelectedTime();
|
||
roonGiftModel = adapter.getSelectedGift();
|
||
if (type.equals("2")) {
|
||
if (roomRelationBean != null && roomAutionTimeBean != null && roonGiftModel != null) {
|
||
// 创建一个 RoomAuctionABean 对象
|
||
MvpPre.roomAuction(roomId, userId, roonGiftModel.getGift_id(), roomRelationBean.getRelation_id(), "2", roomAutionTimeBean.getHours() + "");
|
||
} else {
|
||
ToastUtils.show("请选择竞拍信息");
|
||
}
|
||
} else {
|
||
if (roomRelationBean != null && roonGiftModel != null) {
|
||
|
||
// MvpPre.roomAuctionTime(roonGiftModel.getGift_id());
|
||
MvpPre.roomAuction(roomId, userId, roonGiftModel.getGift_id(), roomRelationBean.getRelation_id(), "1", "");
|
||
|
||
} else {
|
||
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) {
|
||
if (roomRelationBeans != null) {
|
||
roomAuctionABean.setRoomRelationBeanList(roomRelationBeans);
|
||
MvpPre.getGiftList("99");
|
||
} else {
|
||
ToastUtils.show("数据接口错误");
|
||
}
|
||
|
||
}
|
||
|
||
@Override
|
||
public void setGiftList(List<RoonGiftModel> roonGiftModels) {
|
||
if (roonGiftModels != null) {
|
||
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());
|
||
|
||
}
|
||
|
||
|
||
private void upList() {
|
||
if (roomAuctionABean != null) {
|
||
// 添加文本项
|
||
viewItems.add(new ViewItem(ViewItem.TYPE_TEXT, "选择关系"));
|
||
|
||
// 添加关系列表
|
||
for (RoomRelationBean bean : roomAuctionABean.getRoomRelationBeanList()) {
|
||
viewItems.add(new ViewItem(ViewItem.TYPE_RELATION, bean));
|
||
}
|
||
|
||
if (type.equals("2")) {
|
||
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();
|
||
}
|
||
}
|