951 lines
38 KiB
Java
951 lines
38 KiB
Java
package com.xscm.modulemain.dialog;
|
||
|
||
import android.app.Dialog;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.os.Bundle;
|
||
import android.text.TextUtils;
|
||
import android.util.DisplayMetrics;
|
||
import android.util.Log;
|
||
import android.view.Gravity;
|
||
import android.view.View;
|
||
import android.view.ViewGroup;
|
||
import android.view.Window;
|
||
import android.view.WindowManager;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.annotation.Nullable;
|
||
import androidx.fragment.app.Fragment;
|
||
import androidx.fragment.app.FragmentManager;
|
||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||
import androidx.viewpager.widget.ViewPager;
|
||
|
||
import com.blankj.utilcode.util.LogUtils;
|
||
import com.hjq.toast.ToastUtils;
|
||
import com.xscm.modulemain.R;
|
||
import com.xscm.modulemain.adapter.GiftUserAdapter;
|
||
import com.xscm.modulemain.databinding.RoomGiftDialogBinding;
|
||
import com.xscm.modulemain.activity.WebViewActivity;
|
||
import com.xscm.moduleutil.adapter.GiftTwoDetailsFragment;
|
||
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
||
import com.xscm.moduleutil.bean.GiftLabelBean;
|
||
import com.xscm.moduleutil.bean.GiftNumBean;
|
||
import com.xscm.moduleutil.bean.GiftPackBean;
|
||
import com.xscm.moduleutil.bean.GiftPackEvent;
|
||
import com.xscm.moduleutil.bean.GiftPackListCount;
|
||
import com.xscm.moduleutil.bean.RewardUserBean;
|
||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||
import com.xscm.moduleutil.bean.UserInfo;
|
||
import com.xscm.moduleutil.bean.WalletBean;
|
||
import com.xscm.moduleutil.bean.room.RoomAuction;
|
||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
||
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||
import com.xscm.moduleutil.dialog.ConfirmDialog;
|
||
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
|
||
import com.xscm.moduleutil.event.GiftDoubleClickEvent;
|
||
import com.xscm.moduleutil.event.GiftUserRefreshEvent;
|
||
import com.xscm.moduleutil.event.RoomGiftGiveEvent;
|
||
import com.xscm.moduleutil.presenter.RewardGiftContacts;
|
||
import com.xscm.moduleutil.presenter.RewardGiftPresenter;
|
||
import com.xscm.moduleutil.utils.ColorManager;
|
||
import com.xscm.moduleutil.utils.SpUtil;
|
||
import com.xscm.moduleutil.utils.SystemUtils;
|
||
import com.xscm.moduleutil.widget.dialog.KeyboardPopupWindow;
|
||
import com.xscm.moduleutil.widget.dialog.SelectGiftNumPopupWindow;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
import org.greenrobot.eventbus.Subscribe;
|
||
import org.greenrobot.eventbus.ThreadMode;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.HashSet;
|
||
import java.util.LinkedList;
|
||
import java.util.List;
|
||
import java.util.Set;
|
||
|
||
/**
|
||
* @author qx
|
||
* @data 2025/6/16
|
||
* @description: 送礼物的dialog
|
||
*/
|
||
public class RoomGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPresenter, RoomGiftDialogBinding> implements RewardGiftContacts.View {
|
||
|
||
private GiftUserAdapter gifyuseradapter;
|
||
private SelectGiftNumPopupWindow mSelectGiftNumPopupWindow;
|
||
private KeyboardPopupWindow mKeyboardPopupWindow;
|
||
private List<GiftNumBean> mGiftNumList;
|
||
private RoonGiftModel roonGiftModel = new RoonGiftModel();
|
||
private GiftPackBean giftModel = null;
|
||
private RoomInfoResp roomInfoResp;
|
||
private String label_id;
|
||
List<RewardUserBean> rewardUserBeanList;
|
||
private List<Fragment> fragmentList = new ArrayList<>();
|
||
private UserInfo userInfo;
|
||
|
||
private boolean all = false;
|
||
private String roomId;
|
||
private final List<String> oldSelectedIds = new LinkedList<>();
|
||
private int jingp;//1:是点击的竞拍,2:是点击的送礼物
|
||
private String heart_id = "";//交友房中,点击助力需要发送heart_id
|
||
private String auction_id;
|
||
|
||
@Override
|
||
protected RewardGiftPresenter bindPresenter() {
|
||
return new RewardGiftPresenter(this, getActivity());
|
||
}
|
||
|
||
public static RoomGiftDialogFragment show(RoomInfoResp roomInfoResp, UserInfo userInfo, String roomId, int jingp, String heart_id, FragmentManager fragmentManager) {
|
||
RoomGiftDialogFragment dialogFragment = new RoomGiftDialogFragment();
|
||
Bundle args = new Bundle();
|
||
args.putSerializable("roomInfoResp", roomInfoResp);
|
||
args.putSerializable("userInfo", userInfo);
|
||
args.putString("roomId", roomId);
|
||
args.putInt("jingp", jingp);//竞拍
|
||
args.putString("heart_id", heart_id);
|
||
dialogFragment.setArguments(args);
|
||
dialogFragment.show(fragmentManager, "RewardGiftDialogFragment");
|
||
return dialogFragment;
|
||
}
|
||
|
||
@Override
|
||
public void onAttach(@NonNull Context context) {
|
||
super.onAttach(context);
|
||
roomInfoResp = (RoomInfoResp) getArguments().getSerializable("roomInfoResp");
|
||
userInfo = (UserInfo) getArguments().getSerializable("userInfo");
|
||
roomId = getArguments().getString("roomId");
|
||
jingp = getArguments().getInt("jingp");
|
||
heart_id = getArguments().getString("heart_id");
|
||
LogUtils.e("RoomGiftDialogFragment_roomInfoResp",roomInfoResp.toString());
|
||
LogUtils.e("RoomGiftDialogFragment_userInfo",userInfo.toString());
|
||
|
||
}
|
||
|
||
@Override
|
||
protected void initDialogStyle(Window window) {
|
||
super.initDialogStyle(window);
|
||
window.setGravity(Gravity.BOTTOM);
|
||
}
|
||
|
||
@Override
|
||
public void onDestroyView() {
|
||
super.onDestroyView();
|
||
// 清理资源,防止内存泄漏
|
||
if (mSelectGiftNumPopupWindow != null) {
|
||
mSelectGiftNumPopupWindow.dismiss();
|
||
mSelectGiftNumPopupWindow = null;
|
||
}
|
||
|
||
if (mKeyboardPopupWindow != null) {
|
||
mKeyboardPopupWindow.dismiss();
|
||
mKeyboardPopupWindow = null;
|
||
}
|
||
|
||
if (currentDialog != null) {
|
||
currentDialog.dismiss();
|
||
currentDialog = null;
|
||
}
|
||
|
||
// 清理适配器引用
|
||
if (gifyuseradapter != null) {
|
||
gifyuseradapter.setOnItemClickListener(null);
|
||
gifyuseradapter = null;
|
||
}
|
||
|
||
// 清理Fragment列表
|
||
if (fragmentList != null) {
|
||
fragmentList.clear();
|
||
fragmentList = null;
|
||
}
|
||
|
||
// 清理其他引用
|
||
// roomInfoResp = null;
|
||
// userInfo = null;
|
||
rewardUserBeanList = null;
|
||
giftLabelBeanList = null;
|
||
roonGiftModel = null;
|
||
giftModel = null;
|
||
}
|
||
|
||
@Override
|
||
public void onStart() {
|
||
super.onStart();
|
||
Dialog dialog = getDialog();
|
||
if (dialog != null) {
|
||
// 获取屏幕高度
|
||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
||
int height = displayMetrics.heightPixels;
|
||
|
||
// 设置DialogFragment的高度为屏幕高度的70%
|
||
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) (height * 0.7));
|
||
}
|
||
}
|
||
|
||
@Override
|
||
protected void initData() {
|
||
// MvpPre.getRewardList("1", 1, 10);
|
||
MvpPre.getGiftLabel("1");
|
||
MvpPre.wallet();
|
||
|
||
mGiftNumList = new ArrayList<>();
|
||
mGiftNumList.add(new GiftNumBean("20", "x20"));
|
||
mGiftNumList.add(new GiftNumBean("15", "x15"));
|
||
mGiftNumList.add(new GiftNumBean("10", "x10"));
|
||
mGiftNumList.add(new GiftNumBean("5", "x5"));
|
||
mGiftNumList.add(new GiftNumBean("1", "x1"));
|
||
|
||
rewardUserBeanList = new ArrayList<>();
|
||
if (roomInfoResp == null) {
|
||
RewardUserBean rewardUserBean = new RewardUserBean();
|
||
rewardUserBean.setUser_id(userInfo.getUser_id() + "");
|
||
rewardUserBean.setNickname(userInfo.getNickname());
|
||
rewardUserBean.setAvatar(userInfo.getAvatar());
|
||
rewardUserBean.setPit_number(userInfo.getPit_number());
|
||
rewardUserBean.setSelect(true);
|
||
rewardUserBeanList.add(rewardUserBean);
|
||
} else {
|
||
rewardUserBeanList = getSortedRewardUserList(roomInfoResp.getRoom_info().getPit_list(), "9", "10");
|
||
}
|
||
mBinding.rvGiftUser.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
|
||
gifyuseradapter = new GiftUserAdapter();
|
||
mBinding.rvGiftUser.setAdapter(gifyuseradapter);
|
||
gifyuseradapter.setNewData(rewardUserBeanList);
|
||
|
||
gifyuseradapter.setOnItemClickListener((adapter, view, position) -> {
|
||
RewardUserBean item = (RewardUserBean) adapter.getItem(position);
|
||
if (item != null) {
|
||
item.setSelect(!item.isSelect());
|
||
}
|
||
// mBinding.tvOneKeyAllGive.setVisibility(currentPage == 1 && giftUserAdapter.getSelectCount() == 1 ?
|
||
// View.VISIBLE : View.INVISIBLE);//选中了两个以上麦位,一键送礼隐藏
|
||
all = gifyuseradapter.isAll();
|
||
if (all) {
|
||
mBinding.tvAllWheat.setVisibility(View.GONE);
|
||
} else {
|
||
mBinding.tvAllWheat.setVisibility(View.VISIBLE);
|
||
}
|
||
gifyuseradapter.notifyItemChanged(position, item);
|
||
oldSelectedIds.clear();
|
||
oldSelectedIds.addAll(gifyuseradapter.getAllSelectedIds());
|
||
});
|
||
|
||
}
|
||
|
||
private List<RewardUserBean> getSortedRewardUserList(List<RoomPitBean> pitList, String... priorityPits) {
|
||
List<RewardUserBean> result = new ArrayList<>();
|
||
List<RoomPitBean> pitList2 = new ArrayList<>();
|
||
List<RoomPitBean> pitList3 = new ArrayList<>();
|
||
List<String> added = new ArrayList<>();
|
||
if (roomInfoResp.getSong_pit_list() != null && roomInfoResp.getSong_pit_list().size() > 0) {
|
||
pitList2.addAll(roomInfoResp.getSong_pit_list());
|
||
// 使用 HashSet 进行去重
|
||
Set<RoomPitBean> uniquePitSet = new HashSet<>(pitList);
|
||
uniquePitSet.addAll(pitList2);
|
||
// 将去重后的集合转换回 List
|
||
pitList.clear();
|
||
pitList.addAll(uniquePitSet);
|
||
}
|
||
|
||
if (roomInfoResp.getRoom_auction() != null) {
|
||
if (roomInfoResp.getRoom_auction().getAuction_list() != null && roomInfoResp.getRoom_auction().getAuction_list().size() > 0) {
|
||
for (int i = 0; i < roomInfoResp.getRoom_auction().getAuction_list().size(); i++) {
|
||
RoomAuction.AuctionListBean auctionListBean = roomInfoResp.getRoom_auction().getAuction_list().get(i);
|
||
RoomPitBean pitBean = new RoomPitBean();
|
||
pitBean.setUser_id(auctionListBean.getUser_id());
|
||
pitBean.setNickname(auctionListBean.getNickname());
|
||
pitBean.setAvatar(auctionListBean.getAvatar());
|
||
pitBean.setCharm(auctionListBean.getCharm());
|
||
pitBean.setPit_number("1111");
|
||
pitList3.add(pitBean);
|
||
}
|
||
// 使用 HashSet 进行去重
|
||
Set<RoomPitBean> uniquePitSet = new HashSet<>(pitList);
|
||
uniquePitSet.addAll(pitList3);
|
||
// 将去重后的集合转换回 List
|
||
pitList.clear();
|
||
pitList.addAll(uniquePitSet);
|
||
}
|
||
|
||
if (roomInfoResp.getRoom_auction().getAuction_user() != null) {
|
||
if (roomInfoResp.getRoom_auction().getAuction_user().getUser_id() != null && !roomInfoResp.getRoom_auction().getAuction_user().getUser_id().equals(SpUtil.getUserId() + "")) {
|
||
RewardUserBean rewardUserBean = new RewardUserBean();
|
||
rewardUserBean.setUser_id(roomInfoResp.getRoom_auction().getAuction_user().getUser_id());
|
||
rewardUserBean.setNickname(roomInfoResp.getRoom_auction().getAuction_user().getNickname());
|
||
rewardUserBean.setAvatar(roomInfoResp.getRoom_auction().getAuction_user().getAvatar());
|
||
rewardUserBean.setPit_number("888");
|
||
result.add(rewardUserBean);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 优先添加指定麦位
|
||
for (String targetPit : priorityPits) {
|
||
for (RoomPitBean bean : pitList) {
|
||
if (bean.getPit_number().equals(targetPit) &&
|
||
!bean.getUser_id().equals("0") && !bean.getUser_id().equals("") &&
|
||
!bean.getUser_id().equals(SpUtil.getUserId() + "")) {
|
||
|
||
RewardUserBean rewardUserBean = new RewardUserBean();
|
||
rewardUserBean.setUser_id(bean.getUser_id());
|
||
rewardUserBean.setNickname(bean.getNickname());
|
||
rewardUserBean.setAvatar(bean.getAvatar());
|
||
rewardUserBean.setPit_number(bean.getPit_number());
|
||
|
||
result.add(rewardUserBean);
|
||
added.add(bean.getPit_number());
|
||
}
|
||
}
|
||
}
|
||
|
||
// 添加剩余的
|
||
for (RoomPitBean bean : pitList) {
|
||
String pitNumber = bean.getPit_number();
|
||
if (!added.contains(pitNumber) &&
|
||
!bean.getUser_id().equals("0") && !bean.getUser_id().equals("") &&
|
||
!bean.getUser_id().equals(SpUtil.getUserId() + "")) {
|
||
|
||
RewardUserBean rewardUserBean = new RewardUserBean();
|
||
rewardUserBean.setUser_id(bean.getUser_id());
|
||
rewardUserBean.setNickname(bean.getNickname());
|
||
rewardUserBean.setAvatar(bean.getAvatar());
|
||
rewardUserBean.setPit_number(bean.getPit_number());
|
||
|
||
result.add(rewardUserBean);
|
||
}
|
||
}
|
||
|
||
List<RewardUserBean> uniquePitSet = removeDuplicateByUserId(result);
|
||
result.clear();
|
||
result.addAll(uniquePitSet);
|
||
return result;
|
||
}
|
||
|
||
// TODO: 2025/9/15 去重
|
||
private List<RewardUserBean> removeDuplicateByUserId(List<RewardUserBean> list) {
|
||
Set<String> userIdSet = new HashSet<>();
|
||
List<RewardUserBean> uniqueList = new ArrayList<>();
|
||
|
||
for (RewardUserBean bean : list) {
|
||
if (bean != null && bean.getUser_id() != null && !userIdSet.contains(bean.getUser_id())) {
|
||
userIdSet.add(bean.getUser_id());
|
||
uniqueList.add(bean);
|
||
}
|
||
}
|
||
|
||
return uniqueList;
|
||
}
|
||
|
||
|
||
@Override
|
||
protected void initView() {
|
||
// mBinding.rvGiftUser.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
|
||
// adapter = new BaseQuickAdapter<RewardUserBean, BaseViewHolder>(com.qxcm.moduleutil.R.layout.item_reward, null) {
|
||
// @Override
|
||
// protected void convert(BaseViewHolder helper, RewardUserBean item) {
|
||
// ImageUtils.loadHeadCC(item.getAvatar(), helper.getView(com.qxcm.moduleutil.R.id.im_reward));
|
||
// }
|
||
// };
|
||
|
||
mBinding.tvGiveCoinNum.setOnClickListener(this::onClisk);
|
||
mBinding.tvGive.setOnClickListener(this::onClisk);
|
||
mBinding.cz.setOnClickListener(this::onClisk);
|
||
mBinding.tvAllWheat.setOnClickListener(this::onClisk);
|
||
|
||
float[] corners = {0f, 65f, 65f, 0f};
|
||
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvGive, ColorManager.getInstance().getPrimaryColorInt(), corners);
|
||
mBinding.tvGive.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
||
mBinding.cz.setTextColor(ColorManager.getInstance().getPrimaryColorInt());
|
||
|
||
|
||
ViewGroup.LayoutParams layoutParams = mBinding.llGiftRule.getLayoutParams();
|
||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; // 使用你定义的getWidth方法
|
||
layoutParams.height = SystemUtils.getWidth(64); // 示例高度
|
||
mBinding.llGiftRule.setLayoutParams(layoutParams);
|
||
|
||
|
||
float[] corners2 = {56f, 56f, 56f, 56f};
|
||
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvBbQs, ColorManager.getInstance().getPrimaryColorInt(), corners2);
|
||
mBinding.tvBbQs.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
||
|
||
mBinding.tvBbQs.setOnClickListener(this::onClisk);
|
||
|
||
mBinding.container.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dismiss();
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private void onClisk(View view1) {
|
||
if (view1.getId() == R.id.tv_give_coin_num) {
|
||
|
||
if (mSelectGiftNumPopupWindow == null) {
|
||
|
||
mSelectGiftNumPopupWindow = new SelectGiftNumPopupWindow(getSelfActivity(), (adapter, view, position) -> {
|
||
GiftNumBean giftNumBean = (GiftNumBean) adapter.getItem(position);
|
||
if ("0".equals(giftNumBean.getNumber())) {//自定义
|
||
mKeyboardPopupWindow = new KeyboardPopupWindow(getSelfActivity(), getView());
|
||
mKeyboardPopupWindow.refreshKeyboardOutSideTouchable(false);//false开启键盘 ,true关闭键盘
|
||
mKeyboardPopupWindow.addRoomPasswordListener(new KeyboardPopupWindow.KeyboardCompleteListener() {//监听自定键盘的完成
|
||
@Override
|
||
public void inputComplete(String inputContent) {
|
||
mBinding.tvGiveCoinNum.setText(inputContent);
|
||
mKeyboardPopupWindow.releaseResources();
|
||
}
|
||
});
|
||
} else {
|
||
mBinding.tvGiveCoinNum.setText(giftNumBean.getText());
|
||
}
|
||
mSelectGiftNumPopupWindow.dismiss();
|
||
});
|
||
}
|
||
mSelectGiftNumPopupWindow.setData(mGiftNumList);
|
||
mSelectGiftNumPopupWindow.showAtLocation(mBinding.tvGiveCoinNum, Gravity.BOTTOM | Gravity.RIGHT, 100, 190);
|
||
|
||
|
||
} else if (view1.getId() == R.id.tv_give) {
|
||
for (int i = 0; i < mGiftNumList.size(); i++) {
|
||
if (mBinding.tvGiveCoinNum.getText().toString().equals(mGiftNumList.get(i).getText())) {
|
||
giftNumber = mGiftNumList.get(i).getNumber();
|
||
}
|
||
}
|
||
if (packType == 1) {
|
||
giveGift(giftNumber);
|
||
} else {
|
||
giveGift(giftNumber);
|
||
}
|
||
} else if (view1.getId() == R.id.cz) {
|
||
RechargeDialogFragment.show(roomId, null, getActivity().getSupportFragmentManager(),"","");
|
||
dismiss();
|
||
} else if (view1.getId() == R.id.tv_all_wheat) {//全麦
|
||
if (all) {
|
||
gifyuseradapter.allElection(false);
|
||
// mBinding.tvAllWheat.setVisibility(View.VISIBLE);
|
||
} else {
|
||
gifyuseradapter.allElection(true);
|
||
// mBinding.tvAllWheat.setVisibility(View.GONE);
|
||
}
|
||
all = !all;
|
||
oldSelectedIds.clear();
|
||
oldSelectedIds.addAll(gifyuseradapter.getAllSelectedIds());
|
||
} else if (view1.getId() == R.id.tv_bb_qs) {
|
||
int count = gifyuseradapter.getSelectCount();
|
||
if (count <=0) {
|
||
ToastUtils.show("请选择打赏的用户");
|
||
return;
|
||
}
|
||
if (gifyuseradapter.getUserIdCount() > 1) {
|
||
ToastUtils.show("一键全送只能选择一个用户");
|
||
return;
|
||
}
|
||
if (userInfo != null) {
|
||
if (userInfo.getAuction_id() != null) {
|
||
auction_id =userInfo.getAuction_id();
|
||
} else {
|
||
auction_id = "";
|
||
}
|
||
}
|
||
queren();
|
||
}
|
||
}
|
||
private void queren() {
|
||
// 创建并显示确认对话框
|
||
new ConfirmDialog(getActivity(),
|
||
"提示",
|
||
"是否确认将背包礼物全部送出?",
|
||
"确认",
|
||
"取消",
|
||
v -> {
|
||
// 点击“确认”按钮时执行删除操作
|
||
MvpPre.getGiftPack(roomId, gifyuseradapter.getUserIdToString(), heart_id, auction_id);
|
||
},
|
||
v -> {
|
||
// 点击“取消”按钮时什么都不做
|
||
}, false, 0).show();
|
||
}
|
||
private String giftNumber = "";
|
||
private RoomGiftGiveEvent roomGiftGiveEvent;
|
||
|
||
int packType;
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onGiftDoubleClickEvent(GiftDoubleClickEvent event) {
|
||
getSelectedGift();
|
||
packType = 1;
|
||
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void userRefresh(GiftUserRefreshEvent event) {
|
||
if (event.gift == null || event.gift.getRule() == null) {
|
||
mBinding.llGiftRule.setVisibility(View.GONE);
|
||
} else {
|
||
if (event.gift.getActivities_id() == 5) {
|
||
|
||
showGiftLotteryDialog(event.gift, roomId);
|
||
return;
|
||
}
|
||
mBinding.llGiftRule.setVisibility(View.VISIBLE);
|
||
setGiftDetail(event.gift);
|
||
}
|
||
if (event.addSelf) {
|
||
roonGiftModel = event.gift;
|
||
}
|
||
}
|
||
|
||
private GiftLotteryDialog currentDialog;
|
||
|
||
private void showGiftLotteryDialog(RoonGiftModel gift, String roomId) {
|
||
String userId = gifyuseradapter.getUserIdToString();
|
||
if (userId == null || userId.isEmpty()) {
|
||
ToastUtils.show("请先选择人员");
|
||
gift.setChecked(false);
|
||
|
||
return;
|
||
}
|
||
// this.dismiss();
|
||
// FragmentManager fm = getParentFragmentManager();
|
||
// GiftLotteryDialog newDialog = GiftLotteryDialog.newInstance(gift.getGift_bag() + "", roomId, userId);
|
||
// newDialog.show(fm, "GiftLotteryDialog");
|
||
|
||
try {
|
||
// 直接显示对话框,移除有问题的 FragmentTransaction
|
||
this.dismissAllowingStateLoss(); // 使用 dismissAllowingStateLoss 更安全
|
||
|
||
FragmentManager fm = getParentFragmentManager();
|
||
if (fm != null && !fm.isDestroyed()) {
|
||
if (jingp==1){
|
||
auction_id= userInfo.getAuction_id() ;
|
||
}
|
||
if (auction_id==null || auction_id.isEmpty()){
|
||
auction_id="";
|
||
}
|
||
GiftLotteryDialog newDialog = GiftLotteryDialog.newInstance(
|
||
String.valueOf(gift.getGift_bag()), roomId, userId, heart_id,auction_id);
|
||
newDialog.show(fm, "GiftLotteryDialog");
|
||
}
|
||
} catch (Exception e) {
|
||
Log.e("RoomGiftDialogFragment", "Error in showGiftLotteryDialog", e);
|
||
ToastUtils.show("操作失败,请重试");
|
||
}
|
||
|
||
// 如果当前dialog存在且正在显示,先关闭
|
||
// if (currentDialog != null && currentDialog.isVisible()) {
|
||
// currentDialog.dismiss();
|
||
// }
|
||
// currentDialog = GiftLotteryDialog.newInstance(gift.getGift_bag()+"", roomId, userId);
|
||
// currentDialog.show(getChildFragmentManager(), "GiftLotteryDialog");
|
||
}
|
||
|
||
|
||
public void setGiftDetail(RoonGiftModel giftDetailResp) {
|
||
if (giftDetailResp == null) {
|
||
return;
|
||
}
|
||
mBinding.tvTitle.setText(giftDetailResp.getGift_bag_name());
|
||
mBinding.tvIntroduce.setText(giftDetailResp.getRule());
|
||
mBinding.ivWf.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
// ARouter.getInstance().build(ARouteConstants.H5).withString("url", giftDetailResp.getRule_url()).withString("title", "盲盒规则").navigation();
|
||
|
||
Intent intent = new Intent(getActivity(), WebViewActivity.class);
|
||
intent.putExtra("url", giftDetailResp.getRule_url());
|
||
intent.putExtra("title", "盲盒规则");
|
||
startActivity(intent);
|
||
|
||
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private int getSelectedGift() {
|
||
int currentItem = mBinding.viewPager.getCurrentItem();
|
||
|
||
// 增加边界检查
|
||
if (fragmentList == null || currentItem < 0 || currentItem >= fragmentList.size()) {
|
||
return currentItem;
|
||
}
|
||
|
||
if (currentItem < 1) { //比1小的是背包
|
||
GiftTwoDetailsFragment fragment = (GiftTwoDetailsFragment) fragmentList.get(currentItem);
|
||
if (fragment != null && giftModel == null) {
|
||
giftModel = fragment.mGiftList();
|
||
}
|
||
} else {
|
||
GiftTwoDetailsFragment fragment = (GiftTwoDetailsFragment) fragmentList.get(currentItem);
|
||
if (fragment != null && roonGiftModel == null) {
|
||
roonGiftModel = fragment.getGiftList();
|
||
}
|
||
}
|
||
return currentItem;
|
||
}
|
||
|
||
private void giveGift(String num) {
|
||
getSelectedGift();
|
||
int currentItem = mBinding.viewPager.getCurrentItem();
|
||
String userId = gifyuseradapter.getUserIdToString();
|
||
String pit = gifyuseradapter.getUserPitToString();
|
||
// if (currentItem < 1) {
|
||
// if (giftModel == null) {
|
||
// ToastUtils.show("请选择礼物");
|
||
// return;
|
||
// }
|
||
// int count = gifyuseradapter.getSelectCount();
|
||
// if (count <= 0) {
|
||
// ToastUtils.show("请选择打赏对象");
|
||
// return;
|
||
// }
|
||
//
|
||
// if (TextUtils.isEmpty(num)) {
|
||
// ToastUtils.show("请选择打赏礼物数量");
|
||
// return;
|
||
// }
|
||
// if (Integer.valueOf(num) <= 0) {
|
||
// ToastUtils.show("请选择打赏礼物数量");
|
||
// return;
|
||
// }
|
||
// } else {
|
||
if (roonGiftModel == null|| roonGiftModel.getGift_id() == null) {
|
||
ToastUtils.show("请选择礼物");
|
||
return;
|
||
}
|
||
int count = gifyuseradapter.getSelectCount();
|
||
if (count <= 0) {
|
||
ToastUtils.show("请选择打赏对象");
|
||
return;
|
||
}
|
||
|
||
if (TextUtils.isEmpty(num)) {
|
||
ToastUtils.show("请选择打赏礼物数量");
|
||
return;
|
||
}
|
||
if (Integer.valueOf(num) <= 0) {
|
||
ToastUtils.show("请选择打赏礼物数量");
|
||
return;
|
||
}
|
||
// }
|
||
if (roonGiftModel != null && roonGiftModel.getGift_id() != null) {
|
||
if (currentItem != 0) {
|
||
//礼物打赏
|
||
giftNumber = num;
|
||
|
||
if (userInfo != null) {
|
||
if (userInfo.getPit_number() != null) {
|
||
if (userInfo.getPit_number().equals("888") || userInfo.getPit_number().equals("")) {
|
||
if (userInfo.getPit_number().isEmpty() || jingp != 1) {
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, "");
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "1", pit, "");
|
||
} else {
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, userInfo.getAuction_id());
|
||
EventBus.getDefault().post(roomGiftGiveEvent);
|
||
roomGiftGiveEvent = null;
|
||
MvpPre.roomAuctionJoin(userInfo.getAuction_id(), userInfo.getUser_id() + "", roonGiftModel.getGift_id(), num, "1");
|
||
dismiss();
|
||
}
|
||
} else {
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, "");
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "1", pit, heart_id);
|
||
}
|
||
} else {
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, "");
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "1", pit, "");
|
||
}
|
||
} else {
|
||
if (all) {
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "1", null, "");
|
||
} else {
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "1", pit, "");
|
||
}
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, "");
|
||
}
|
||
} else if (currentItem == 0) {
|
||
if (userInfo==null){
|
||
giftNumber = num;
|
||
beibaoId = roonGiftModel.getGift_id();
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "2", pit, heart_id);
|
||
return;
|
||
}
|
||
if ( userInfo.getPit_number()!=null&& userInfo.getPit_number().equals("888") || userInfo.getPit_number().equals("")) {
|
||
if (userInfo.getPit_number().isEmpty() || jingp != 1) {
|
||
giftNumber = num;
|
||
beibaoId = roonGiftModel.getGift_id();
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "2", pit, heart_id);
|
||
}else {
|
||
beibaoId = roonGiftModel.getGift_id();
|
||
MvpPre.roomAuctionJoin(userInfo.getAuction_id(), userInfo.getUser_id() + "", roonGiftModel.getGift_id(), num, "2");
|
||
roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 0, null, roonGiftModel, heart_id, userInfo.getAuction_id());
|
||
EventBus.getDefault().post(roomGiftGiveEvent);
|
||
roomGiftGiveEvent = null;
|
||
// dismiss();
|
||
}
|
||
} else{
|
||
giftNumber = num;
|
||
beibaoId = roonGiftModel.getGift_id();
|
||
MvpPre.roomGift(roomId, roonGiftModel.getGift_id(), giftNumber, userId, "2", pit, heart_id);
|
||
}
|
||
|
||
} else {
|
||
//背包礼物打赏
|
||
// giftNumber = num;
|
||
// roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 1, giftModel, null);
|
||
//
|
||
// MvpPre.giveBackGift(userId, giftModel.getGift_id(), roomId, pit, num, giftModel, 1);
|
||
}
|
||
} else {
|
||
ToastUtils.show("数据错误");
|
||
dismiss();
|
||
}
|
||
}
|
||
|
||
private String beibaoId;
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.room_gift_dialog;
|
||
}
|
||
|
||
@Override
|
||
public void getRewardList(List<RewardUserBean> rewardUserBeanList) {
|
||
if (rewardUserBeanList != null && !rewardUserBeanList.isEmpty()) {
|
||
mBinding.rvGiftUser.setVisibility(View.VISIBLE);
|
||
int limit = Math.min(rewardUserBeanList.size(), 6);
|
||
List<RewardUserBean> limitedList = rewardUserBeanList.subList(0, limit);
|
||
gifyuseradapter.setNewData(limitedList);
|
||
} else {
|
||
gifyuseradapter.setNewData(null);
|
||
mBinding.rvGiftUser.setVisibility(View.INVISIBLE);
|
||
}
|
||
}
|
||
|
||
private List<GiftLabelBean> giftLabelBeanList;
|
||
|
||
@Override
|
||
public void getGiftLabel(List<GiftLabelBean> giftLabelBeans) {
|
||
if (giftLabelBeans == null) return;
|
||
giftLabelBeanList = new ArrayList<>();
|
||
giftLabelBeanList.addAll(giftLabelBeans);
|
||
GiftLabelBean giftLabelBean = new GiftLabelBean();
|
||
giftLabelBean.setId("0");
|
||
giftLabelBean.setName("背包");
|
||
giftLabelBeans.add(0, giftLabelBean);
|
||
|
||
if (SpUtil.getShelf()==1){
|
||
for (GiftLabelBean giftLabelBean1 : giftLabelBeans){
|
||
if (giftLabelBean1.getId().equals("2")){
|
||
giftLabelBeans.remove(giftLabelBean1);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
mBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), giftLabelBeans, fragmentList, roomId));
|
||
mBinding.viewPager.setOffscreenPageLimit(0);
|
||
mBinding.slidingTabLayout.setViewPager(mBinding.viewPager);
|
||
mBinding.slidingTabLayout.setCurrentTab(1);
|
||
refreshCurrentGiftFragment(giftLabelBeans.get(1).getId(),1,roomId);
|
||
mBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||
@Override
|
||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onPageSelected(int position) {
|
||
// 当页面切换时,控制 tv_bb_qs 按钮的显示
|
||
updateTvBbQsVisibility(position);
|
||
refreshCurrentGiftFragment(giftLabelBeans.get(position).getId(),1,roomId);
|
||
}
|
||
|
||
@Override
|
||
public void onPageScrollStateChanged(int state) {
|
||
|
||
}
|
||
});
|
||
// 初始化时设置按钮可见性
|
||
updateTvBbQsVisibility(1);
|
||
}
|
||
// 调用示例
|
||
private void refreshCurrentGiftFragment(String id,int type,String roomId) {
|
||
if (getCurrentGiftFragment()!=null){
|
||
getCurrentGiftFragment().loadDataIfNeeded(id,type,roomId);
|
||
}
|
||
}
|
||
|
||
private GiftTwoDetailsFragment getCurrentGiftFragment() {
|
||
int currentPosition = mBinding.viewPager.getCurrentItem();
|
||
// 使用 ViewPager 的 adapter 获取当前 fragment
|
||
MyFragmentPagerAdapter adapter = (MyFragmentPagerAdapter) mBinding.viewPager.getAdapter();
|
||
if (adapter != null) {
|
||
// 直接从 adapter 获取 fragment
|
||
Fragment fragment = adapter.getItem(currentPosition);
|
||
if (fragment instanceof GiftTwoDetailsFragment) {
|
||
return (GiftTwoDetailsFragment) fragment;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
// 控制 tv_bb_qs 按钮显示的方法
|
||
private void updateTvBbQsVisibility(int currentPosition) {
|
||
// 假设你希望在特定位置(例如位置1)显示按钮
|
||
if (currentPosition == 0) { // 根据你的需求调整位置
|
||
// 显示按钮
|
||
if (mBinding.tvBbQs != null) {
|
||
mBinding.tvBbQs.setVisibility(View.VISIBLE);
|
||
mBinding.cz.setVisibility(View.GONE);
|
||
MvpPre.getGiftPackListCount();
|
||
}
|
||
} else {
|
||
// 隐藏按钮
|
||
if (mBinding.tvBbQs != null) {
|
||
mBinding.tvBbQs.setVisibility(View.GONE);
|
||
mBinding.cz.setVisibility(View.VISIBLE);
|
||
MvpPre.wallet();
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void setGiftList(List<RoonGiftModel> roonGiftModels, int type) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void giveGift() {
|
||
// dismiss();
|
||
|
||
if (mBinding.viewPager.getCurrentItem() == 0) {
|
||
if (MvpPre!=null) {
|
||
MvpPre.getGiftPackListCount();
|
||
}
|
||
GiftPackEvent giftPackEvent = new GiftPackEvent();
|
||
giftPackEvent.setBdid(beibaoId);
|
||
EventBus.getDefault().post(giftPackEvent);
|
||
return;
|
||
}
|
||
|
||
if (roomGiftGiveEvent != null) {
|
||
EventBus.getDefault().post(roomGiftGiveEvent);
|
||
roomGiftGiveEvent = null;
|
||
dismiss();
|
||
return;
|
||
}
|
||
dismiss();
|
||
|
||
}
|
||
|
||
@Override
|
||
public void wallet(WalletBean walletBean) {
|
||
mBinding.tvRewardGift.setText(walletBean.getCoin());
|
||
|
||
}
|
||
|
||
@Override
|
||
public void reward_zone() {
|
||
com.blankj.utilcode.util.ToastUtils.showShort("打赏成功");
|
||
}
|
||
|
||
@Override
|
||
public void roomAuctionJoin(RoomAuction.AuctionListBean auctionListBean) {
|
||
// com.blankj.utilcode.util.ToastUtils.showShort("竞拍成功");
|
||
if (roomGiftGiveEvent != null) {
|
||
EventBus.getDefault().post(roomGiftGiveEvent);
|
||
roomGiftGiveEvent = null;
|
||
// dismiss();
|
||
}
|
||
if (mBinding.viewPager.getCurrentItem()==0) {
|
||
GiftPackEvent giftPackEvent = new GiftPackEvent();
|
||
giftPackEvent.setBdid(beibaoId);
|
||
EventBus.getDefault().post(giftPackEvent);
|
||
MvpPre.getGiftPackListCount();
|
||
}
|
||
// dismiss();
|
||
}
|
||
|
||
@Override
|
||
public void giftPack(List<GiftPackBean> giftPackBean) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getGiftPack(String s) {
|
||
if (s != null) {
|
||
ToastUtils.show(s);
|
||
dismiss();
|
||
} else {
|
||
ToastUtils.show("一键全清背包礼物失败");
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void getGiftPackListCount(GiftPackListCount giftPackListCount) {
|
||
if (giftPackListCount != null){
|
||
mBinding.tvRewardGift.setText(giftPackListCount.getCount());
|
||
}
|
||
}
|
||
|
||
private class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||
|
||
private List<GiftLabelBean> list;
|
||
private List<Fragment> fragmentList;
|
||
private String roomId;
|
||
|
||
public MyFragmentPagerAdapter(FragmentManager fm, List<GiftLabelBean> list, List<Fragment> fragmentList, String roomId) {
|
||
super(fm);
|
||
this.list = list != null ? list : new ArrayList<>();
|
||
// 不直接使用传入的 fragmentList,而是创建一个新的列表
|
||
this.fragmentList = new ArrayList<>();
|
||
// 初始化 fragmentList 的大小,用 null 填充
|
||
for (int i = 0; i < this.list.size(); i++) {
|
||
this.fragmentList.add(null);
|
||
}
|
||
this.roomId = roomId;
|
||
}
|
||
|
||
@Override
|
||
public Fragment getItem(int position) {
|
||
// 边界检查
|
||
if (position < 0 || list == null || position >= list.size()) {
|
||
return null;
|
||
}
|
||
|
||
// 检查该位置是否已经有 Fragment 实例
|
||
if (position < fragmentList.size() && fragmentList.get(position) != null) {
|
||
return fragmentList.get(position);
|
||
}
|
||
// 创建新的 Fragment
|
||
GiftLabelBean model = list.get(position);
|
||
Fragment fragment = GiftTwoDetailsFragment.newInstance(model.getId(), 1, roomId);
|
||
// 确保 fragmentList 有足够的空间
|
||
while (fragmentList.size() <= position) {
|
||
fragmentList.add(null);
|
||
}
|
||
|
||
// 在指定位置设置 Fragment 实例
|
||
fragmentList.set(position, fragment);
|
||
return fragment;
|
||
}
|
||
|
||
@Override
|
||
public int getCount() {
|
||
return list.size();
|
||
}
|
||
|
||
@Nullable
|
||
@Override
|
||
public CharSequence getPageTitle(int position) {
|
||
if (list == null || position < 0 || position >= list.size()) {
|
||
return null;
|
||
}
|
||
GiftLabelBean model = list.get(position);
|
||
return model.getName();
|
||
}
|
||
}
|
||
}
|