1、修改包的图片
2、修改房间的所有进出方式
This commit is contained in:
@@ -143,6 +143,8 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置麦位数据
|
||||
*
|
||||
|
||||
@@ -83,10 +83,12 @@ public class GiftAnimView extends FrameLayout implements GiftSvgaView.OnAnimatio
|
||||
public void onVideoComplete() {
|
||||
LogUtils.e("onVideoComplete");
|
||||
post(() -> {
|
||||
playerMp4View.setVisibility(View.GONE);
|
||||
// 通知播放完成
|
||||
notifyPlaybackComplete();
|
||||
loadStartSVGAPlayer();
|
||||
if (playerMp4View!=null) {
|
||||
playerMp4View.setVisibility(View.GONE);
|
||||
// 通知播放完成
|
||||
notifyPlaybackComplete();
|
||||
loadStartSVGAPlayer();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@@ -415,7 +417,9 @@ public class GiftAnimView extends FrameLayout implements GiftSvgaView.OnAnimatio
|
||||
@Override
|
||||
public void onFinishedDisplay(GiftSvgaView view) {
|
||||
post(() -> {
|
||||
svgaView.setVisibility(View.GONE);
|
||||
if (svgaView!=null) {
|
||||
svgaView.setVisibility(View.GONE);
|
||||
}
|
||||
// 通知播放完成
|
||||
notifyPlaybackComplete();
|
||||
loadStartSVGAPlayer();
|
||||
|
||||
@@ -1,322 +0,0 @@
|
||||
package com.xscm.moduleutil.widget;
|
||||
|
||||
|
||||
import static android.app.PendingIntent.getActivity;
|
||||
import static android.content.Context.WINDOW_SERVICE;
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivityForResult;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.petterp.floatingx.FloatingX;
|
||||
import com.petterp.floatingx.assist.FxGravity;
|
||||
import com.petterp.floatingx.assist.FxScopeType;
|
||||
import com.petterp.floatingx.assist.helper.FxAppHelper;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.BaseAppCompatActivity;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
* @Author
|
||||
* @Time 2025/7/18 21:52
|
||||
* @Description 飘屏管理器
|
||||
*/
|
||||
public class PiaoPingManager {
|
||||
private static PiaoPingManager instance;
|
||||
private WindowManager windowManager;
|
||||
private View piaoPingView;
|
||||
private boolean isPiaoPingShown = false;
|
||||
private Queue<MqttBean> messageQueue = new ConcurrentLinkedQueue<>(); // 消息队列
|
||||
private Queue<XLHBean> XLHmessageQueue = new ConcurrentLinkedQueue<>(); // 消息队列
|
||||
private boolean isAnimating = false; // 动画状态标记
|
||||
private boolean XLHisAnimating = false; // 动画状态标记
|
||||
|
||||
private Context mContext; // 添加成员变量
|
||||
View floatingView;
|
||||
|
||||
private PiaoPingManager(Context context) {
|
||||
this.mContext = context;
|
||||
windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
|
||||
if (windowManager == null) return;
|
||||
|
||||
// 创建飘屏消息的布局
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
piaoPingView = inflater.inflate(R.layout.item_piaoping, null);
|
||||
|
||||
}
|
||||
|
||||
public static synchronized PiaoPingManager getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new PiaoPingManager(context.getApplicationContext());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showPiaoPingMessage(MqttBean mqttBean) {
|
||||
// 创建 FloatingX 配置
|
||||
// 添加到队列
|
||||
messageQueue.offer(mqttBean);
|
||||
// 如果当前没有动画正在进行,则开始处理
|
||||
// if (!isAnimating) {
|
||||
processNextMessage();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void processNextMessage() {
|
||||
if (messageQueue.isEmpty()) {
|
||||
isAnimating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isAnimating = true;
|
||||
MqttBean mqttBean = messageQueue.poll();
|
||||
|
||||
displayMessage(mqttBean);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void displayMessage(MqttBean mqttBean) {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
// WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
// WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
// WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
|
||||
// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
||||
// PixelFormat.TRANSLUCENT
|
||||
// );
|
||||
|
||||
|
||||
ToastUtils.show("飘屏开始");
|
||||
// 获取悬浮窗视图并设置内容
|
||||
floatingView = LayoutInflater.from(mContext).inflate(R.layout.item_piaoping, new FrameLayout(mContext), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
|
||||
textView2.setText("送给" + mqttBean.getList().getToUserName());
|
||||
textView.setText(mqttBean.getList().getFromUserName());
|
||||
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
|
||||
TextView tv_time = floatingView.findViewById(R.id.tv_num);
|
||||
tv_time.setText("x" + mqttBean.getList().getNumber());
|
||||
ToastUtils.show("飘屏创建");
|
||||
|
||||
// WindowManager windowManager = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
|
||||
// windowManager.addView(floatingView, params);
|
||||
// }else {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
// 先将视图放置在屏幕右侧外部,避免闪现问题
|
||||
floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
// 在 FloatingX 配置中或者通过其他方式设置
|
||||
FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
.setContext(mContext)
|
||||
.setLayoutView(floatingView)
|
||||
.setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
.setX(0)
|
||||
.setY(100)
|
||||
.setScopeType(FxScopeType.SYSTEM_AUTO)
|
||||
.build();
|
||||
|
||||
FloatingX.install(fxAppHelper).show();
|
||||
ToastUtils.show("飘屏创建2");
|
||||
// 首先从右侧滑入到屏幕中央
|
||||
floatingView.post(() -> {
|
||||
// 确保初始位置在屏幕右侧外部
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator1.start();
|
||||
ToastUtils.show("飘屏创建2第一阶段");
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 动画结束后移除悬浮窗
|
||||
FloatingX.uninstallAll();
|
||||
windowManager.removeView(floatingView);
|
||||
// 处理下一个消息
|
||||
processNextMessage();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 3000); // 停留1秒
|
||||
ToastUtils.show("飘屏创建2第er阶段");
|
||||
});
|
||||
ToastUtils.show("飘屏结束");
|
||||
}
|
||||
|
||||
|
||||
public void subscribe() {
|
||||
try {
|
||||
if (!EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理重复注册或其他异常
|
||||
LogUtils.e("PiaoPingManager subscribe error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void unsubscribe() {
|
||||
try {
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理取消注册异常
|
||||
LogUtils.e("PiaoPingManager unsubscribe error: " + e.getMessage());
|
||||
}
|
||||
messageQueue.clear();
|
||||
isAnimating = false; // 重置动画状态
|
||||
XLHmessageQueue.clear();
|
||||
XLHisAnimating = false;
|
||||
}
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttBean mqttBean) {
|
||||
showPiaoPingMessage(mqttBean);
|
||||
ToastUtils.show("飘屏");
|
||||
// FxAppHelper fxAppHelper = FxAppHelper.builder().setContext( context).setLayout(R.layout.item_piaoping).build();
|
||||
// FloatingX.install(fxAppHelper).show();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(XLHBean event) {
|
||||
showPiaoPingMessageXlh(event);
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageXlh(XLHBean event) {
|
||||
// 创建 FloatingX 配置
|
||||
// 添加到队列
|
||||
XLHmessageQueue.offer(event);
|
||||
// 如果当前没有动画正在进行,则开始处理
|
||||
if (!XLHisAnimating) {
|
||||
processNextMessageXlh();
|
||||
}
|
||||
}
|
||||
|
||||
private void processNextMessageXlh() {
|
||||
if (XLHmessageQueue.isEmpty()) {
|
||||
XLHisAnimating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
XLHisAnimating = true;
|
||||
XLHBean xlhBean = XLHmessageQueue.poll();
|
||||
displayMessageXlh(xlhBean);
|
||||
}
|
||||
|
||||
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
|
||||
private void displayMessageXlh(XLHBean xlhBean) {
|
||||
// 获取悬浮窗视图并设置内容
|
||||
View floatingView = LayoutInflater.from(mContext).inflate(R.layout.item_piaoping_xlh, new FrameLayout(mContext), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = floatingView.findViewById(R.id.im_xlh);
|
||||
// if (xlhBean.getFrom_type() == 1){
|
||||
// xlh_image.setImageResource(R.mipmap.xlh_jjks);
|
||||
// }else {
|
||||
// xlh_image.setImageResource(R.mipmap.xlh_zsks);
|
||||
// }
|
||||
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? mContext.getResources().getDrawable(R.mipmap.xlh_jjks) : mContext.getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
|
||||
textView.setText(xlhBean.getText());
|
||||
|
||||
// 先将视图放置在屏幕右侧外部,避免闪现问题
|
||||
floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
|
||||
FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
.setContext(mContext)
|
||||
.setLayoutView(floatingView)
|
||||
.setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
.setX(0)
|
||||
.setY(100)
|
||||
.build();
|
||||
|
||||
FloatingX.install(fxAppHelper).show();
|
||||
// 添加点击事件监听器
|
||||
floatingView.setOnClickListener(v -> {
|
||||
// 点击时执行跳转操作
|
||||
handleItemClick(xlhBean);
|
||||
});
|
||||
// 首先从右侧滑入到屏幕中央
|
||||
floatingView.post(() -> {
|
||||
// 确保初始位置在屏幕右侧外部
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator1.start();
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 动画结束后移除悬浮窗
|
||||
FloatingX.uninstallAll();
|
||||
// 处理下一个消息
|
||||
processNextMessageXlh();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 4000); // 停留1秒
|
||||
});
|
||||
}
|
||||
|
||||
private void handleItemClick(XLHBean xlhBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
if (showBoss && WHEAT_BOSS.equals(pitNumber)) {
|
||||
mIvTagBoss.setVisibility(GONE);
|
||||
}
|
||||
mCharmView.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mTvName.setText((!"10".equals(pitBean.getPit_number()) && !"9".equals(pitBean.getPit_number())) ? pitBean.getPit_number() : "");
|
||||
//麦位上锁
|
||||
@@ -129,6 +130,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
//停止声浪
|
||||
mIvRipple.stopAnimation( true);
|
||||
mIvRipple.setVisibility(GONE);
|
||||
mCharmView.setVisibility(GONE);
|
||||
}
|
||||
if (showSexIcon) {
|
||||
checkSex();
|
||||
@@ -256,7 +258,11 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
final float scale = getContext().getResources().getDisplayMetrics().density;
|
||||
return (int) (dpValue * scale + 0.5f);
|
||||
}
|
||||
|
||||
// public void setmCharmView(String charm){
|
||||
// if (mCharmView!=null){
|
||||
// mCharmView.setSex(pitBean.getSex(),pitBean.getUser_id(), charm,false);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 开启计时
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomPitBean;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.utils.StringUtil;
|
||||
|
||||
|
||||
public class RoomMakeWheatView extends BaseWheatView {
|
||||
@@ -156,7 +157,7 @@ public class RoomMakeWheatView extends BaseWheatView {
|
||||
}else {
|
||||
mTvTime.setVisibility(VISIBLE);
|
||||
}
|
||||
mTvTime.setText(pitBean.getCharm());
|
||||
mTvTime.setText(StringUtil.toWan2(pitBean.getCharm(),1));
|
||||
}else if (pitBean.getPit_number().equals("000")){
|
||||
iv_tag_type.setVisibility(GONE);
|
||||
mCharmView.setVisibility(GONE);
|
||||
|
||||
@@ -8,6 +8,7 @@ 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 android.content.Context;
|
||||
import android.os.Bundle;
|
||||
@@ -34,13 +35,17 @@ import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
||||
import com.xscm.moduleutil.databinding.FragmentRewardGiftDialogBinding;
|
||||
import com.xscm.moduleutil.dialog.RechargeDialogFragment;
|
||||
import com.xscm.moduleutil.event.GiftRewardEvent;
|
||||
import com.xscm.moduleutil.event.GiftUserRefreshEvent;
|
||||
import com.xscm.moduleutil.presenter.RewardGiftContacts;
|
||||
import com.xscm.moduleutil.presenter.RewardGiftPresenter;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.widget.GifAvatarOvalView;
|
||||
import com.xscm.moduleutil.widget.floatingView.IFloatingView;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -101,6 +106,9 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
mGiftNumList.add(new GiftNumBean("10", "x10"));
|
||||
mGiftNumList.add(new GiftNumBean("5", "x5"));
|
||||
mGiftNumList.add(new GiftNumBean("1", "x1"));
|
||||
if (!EventBus.getDefault().isRegistered( this)){
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -189,46 +197,108 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
mBinding.tvRewardTitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
private List<GiftLabelBean> giftLabelBeanList;
|
||||
|
||||
@Override
|
||||
public void getGiftLabel(List<GiftLabelBean> giftLabelBeans) {
|
||||
// giftLabelBeanList = new ArrayList<>();
|
||||
// giftLabelBeanList.addAll(giftLabelBeans);
|
||||
// GiftLabelBean giftLabelBean = new GiftLabelBean();
|
||||
// giftLabelBean.setId("0");
|
||||
// giftLabelBean.setName("背包");
|
||||
// giftLabelBeans.add(0, giftLabelBean);
|
||||
mBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), giftLabelBeans,fragmentList,""));
|
||||
mBinding.slidingTabLayout.setViewPager(mBinding.viewPager);
|
||||
mBinding.slidingTabLayout.setCurrentTab(0);
|
||||
refreshCurrentGiftFragment(giftLabelBeans.get(0).getId(),2,"");
|
||||
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 按钮的显示
|
||||
refreshCurrentGiftFragment(giftLabelBeans.get(position).getId(),2,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
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;
|
||||
}
|
||||
private GiftPackBean giftModel = null;
|
||||
private int getSelectedGift() {
|
||||
int currentItem = mBinding.viewPager.getCurrentItem();
|
||||
// if (currentItem < 1) { //比2小是才是礼物
|
||||
GiftTwoDetailsFragment fragment = (GiftTwoDetailsFragment) fragmentList.get(currentItem);
|
||||
roonGiftModel = fragment.getGiftList();
|
||||
// GiftTwoDetailsFragment fragment = (GiftTwoDetailsFragment) fragmentList.get(currentItem);
|
||||
// roonGiftModel = fragment.getGiftList();
|
||||
// }
|
||||
// else {
|
||||
// GiftFragment fragment = (GiftFragment) fragmentList.get(currentItem);
|
||||
// giftModel = fragment.getmData();
|
||||
// }
|
||||
|
||||
// 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;
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void userRefresh(GiftUserRefreshEvent event) {
|
||||
if (event.addSelf) {
|
||||
roonGiftModel = event.gift;
|
||||
}
|
||||
}
|
||||
|
||||
private void giveGift(String num) {
|
||||
getSelectedGift();
|
||||
int currentItem = mBinding.viewPager.getCurrentItem();
|
||||
String userId = user_id;
|
||||
if (currentItem < 1) {
|
||||
if (roonGiftModel == null) {
|
||||
ToastUtils.show("请选择礼物");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (TextUtils.isEmpty(num)) {
|
||||
ToastUtils.show("请选择打赏礼物数量");
|
||||
return;
|
||||
}
|
||||
if (Integer.valueOf(num) <= 0) {
|
||||
ToastUtils.show("请选择打赏礼物数量");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// if (currentItem < 1) {
|
||||
// if (roonGiftModel == null) {
|
||||
// ToastUtils.show("请选择礼物");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (TextUtils.isEmpty(num)) {
|
||||
// ToastUtils.show("请选择打赏礼物数量");
|
||||
// return;
|
||||
// }
|
||||
// if (Integer.valueOf(num) <= 0) {
|
||||
// ToastUtils.show("请选择打赏礼物数量");
|
||||
// return;
|
||||
// }
|
||||
// } else {
|
||||
if (roonGiftModel == null) {
|
||||
ToastUtils.show("请选择礼物");
|
||||
return;
|
||||
@@ -242,7 +312,7 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
ToastUtils.show("请选择打赏礼物数量");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
// if (currentItem == 0) {
|
||||
//礼物打赏
|
||||
@@ -298,24 +368,61 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
|
||||
}
|
||||
|
||||
private static class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (!EventBus.getDefault().isRegistered( this)){
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (!EventBus.getDefault().isRegistered( this)){
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
private class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private List<GiftLabelBean> list;
|
||||
private List<Fragment> fragmentList ;
|
||||
private List<Fragment> fragmentList;
|
||||
private String roomId;
|
||||
|
||||
public MyFragmentPagerAdapter(FragmentManager fm, List<GiftLabelBean> list,List<Fragment> fragmentList,String roomId) {
|
||||
public MyFragmentPagerAdapter(FragmentManager fm, List<GiftLabelBean> list, List<Fragment> fragmentList, String roomId) {
|
||||
super(fm);
|
||||
this.list = list;
|
||||
this.fragmentList = fragmentList;
|
||||
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(), 2, roomId);
|
||||
fragmentList.add(fragment); // 保存 Fragment 实例
|
||||
Fragment fragment = GiftTwoDetailsFragment.newInstance(model.getId(), 1, roomId);
|
||||
// 确保 fragmentList 有足够的空间
|
||||
while (fragmentList.size() <= position) {
|
||||
fragmentList.add(null);
|
||||
}
|
||||
|
||||
// 在指定位置设置 Fragment 实例
|
||||
fragmentList.set(position, fragment);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@@ -327,6 +434,9 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
@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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user