1:修改bug

2:给所有视图添加手动调用销毁的方法
This commit is contained in:
2025-09-03 01:02:15 +08:00
parent b9c126ba73
commit c90b44ebf6
16 changed files with 394 additions and 126 deletions

View File

@@ -47,13 +47,14 @@ public class RechargeDialogFragment extends BaseMvpDialogFragment<RechargeDialog
private PayMethodAdapter bindTypeAdapter; private PayMethodAdapter bindTypeAdapter;
private String roomId; private String roomId;
public static void show(String id, String type,FragmentManager fragmentManager) { public static RechargeDialogFragment show(String id, String type, FragmentManager fragmentManager) {
RechargeDialogFragment dialogFragment = new RechargeDialogFragment(); RechargeDialogFragment dialogFragment = new RechargeDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("roomId", id); //// 可选:传递参数 args.putString("roomId", id); //// 可选:传递参数
args.putString("type", type); args.putString("type", type);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment"); dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment");
return dialogFragment;
} }
@Override @Override
protected void initDialogStyle(Window window) { protected void initDialogStyle(Window window) {

View File

@@ -49,7 +49,9 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.facade.annotation.Autowired; import com.alibaba.android.arouter.facade.annotation.Autowired;
@@ -207,7 +209,18 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
private boolean isLayoutAdjusted = false; private boolean isLayoutAdjusted = false;
private ViewStub stub; private ViewStub stub;
private static WeakReference<RoomActivity> sActivityRef; private static WeakReference<RoomActivity> sActivityRef;
// 存储当前显示的弹框引用
private List<DialogInterface> activeDialogs = new ArrayList<>();
private List<Fragment> activeDialogFragments = new ArrayList<>();
// 添加弹框到管理列表
public void addActiveDialog(DialogInterface dialog) {
activeDialogs.add(dialog);
}
public void addActiveDialogFragment(Fragment dialogFragment) {
activeDialogFragments.add(dialogFragment);
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
password = intent.getStringExtra("password"); password = intent.getStringExtra("password");
@@ -303,6 +316,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
// EMqttService.cleanSubscribeRoom(roomId); // EMqttService.cleanSubscribeRoom(roomId);
CommonAppContext.getInstance().isPlaying = false; CommonAppContext.getInstance().isPlaying = false;
CommonAppContext.getInstance().isShow = false; CommonAppContext.getInstance().isShow = false;
cleanupResources();
} }
@Override @Override
@@ -477,8 +491,10 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
if (!TextUtils.isEmpty(msg) && msg.contains("当前余额不足")) { if (!TextUtils.isEmpty(msg) && msg.contains("当前余额不足")) {
com.hjq.toast.ToastUtils.show("当前余额不足,请充值"); com.hjq.toast.ToastUtils.show("当前余额不足,请充值");
ThreadUtils.runOnUiThreadDelayed(() -> { ThreadUtils.runOnUiThreadDelayed(() -> {
RechargeDialogFragment.show(roomId, null, getSupportFragmentManager()); RechargeDialogFragment fragment = RechargeDialogFragment.show(roomId, null, getSupportFragmentManager());
// DialogUtils.showDialogFragment(ARouter.getInstance().build(ARouteConstants.RECHARGE_DIALOG).navigation()); if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
}, 1400); }, 1400);
} }
hideGiftGiveProgress(); hideGiftGiveProgress();
@@ -626,7 +642,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
likeUserAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { likeUserAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override @Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) { public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager()); // RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
RoomOnlineDialogFragment fragment = RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} }
}); });
@@ -1551,7 +1571,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
private void querenPk(String text, String pk_id) { private void querenPk(String text, String pk_id) {
// 创建并显示确认对话框 // 创建并显示确认对话框
new ConfirmDialog(this, ConfirmDialog dialog = new ConfirmDialog(this,
"温馨提示", "温馨提示",
text, text,
"确认", "确认",
@@ -1563,7 +1583,9 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
v -> { v -> {
MvpPre.acceptPk(pk_id, "2"); MvpPre.acceptPk(pk_id, "2");
// 点击“取消”按钮时什么都不做 // 点击“取消”按钮时什么都不做
}, true, 10).show(); }, true, 10);
dialog.show();
addActiveDialog(dialog);
} }
/** /**
@@ -1641,8 +1663,12 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
roomNoticeDialogFragment.setTitle("公告"); roomNoticeDialogFragment.setTitle("公告");
roomNoticeDialogFragment.setContent(mRoomBean.getRoom_intro()); roomNoticeDialogFragment.setContent(mRoomBean.getRoom_intro());
roomNoticeDialogFragment.show(); roomNoticeDialogFragment.show();
addActiveDialog(roomNoticeDialogFragment);
} else if (id == R.id.btn_ranking) {//排行榜 } else if (id == R.id.btn_ranking) {//排行榜
RoomChartsFragment.newInstance(roomId).show(getSupportFragmentManager(), "RoomChartsFragment"); // RoomChartsFragment.newInstance(roomId).show(getSupportFragmentManager(), "RoomChartsFragment");
RoomChartsFragment fragment = RoomChartsFragment.newInstance(roomId);
fragment.show(getSupportFragmentManager(), "RoomChartsFragment");
addActiveDialogFragment(fragment);
} else if (id == R.id.btn_close_live) { } else if (id == R.id.btn_close_live) {
//最小化 //最小化
ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance(); ExitRoomBottomSheet bottomSheet = ExitRoomBottomSheet.newInstance();
@@ -1667,8 +1693,13 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
} }
}); });
bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet"); bottomSheet.show(getSupportFragmentManager(), "ExitRoomBottomSheet");
addActiveDialogFragment(bottomSheet);
} else if (id == R.id.tv_num) { } else if (id == R.id.tv_num) {
RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager()); // RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
RoomOnlineDialogFragment fragment = RoomOnlineDialogFragment.show(roomId, "", mRoomUserBean, mRoomInfoResp, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} else if (id == R.id.rl) { } else if (id == R.id.rl) {
MvpPre.clearUserCharm(roomId, ""); MvpPre.clearUserCharm(roomId, "");
} else if (id == R.id.ll_input) { } else if (id == R.id.ll_input) {
@@ -1696,7 +1727,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
} }
} }
} else if (id == R.id.rl_sett) {//房间设置 } else if (id == R.id.rl_sett) {//房间设置
RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager()); // RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager());
RoomSettingFragment fragment = RoomSettingFragment.show(mRoomInfoResp, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} else if (id == R.id.rl_voive) { } else if (id == R.id.rl_voive) {
if (voive) { if (voive) {
mBinding.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_g); mBinding.imVoive.setImageResource(com.xscm.moduleutil.R.mipmap.room_voice_g);
@@ -1707,20 +1742,38 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
} }
AgoraManager.getInstance(this).muteSpeaker(!voive); AgoraManager.getInstance(this).muteSpeaker(!voive);
} else if (id == R.id.rl_more) {//点击PK } else if (id == R.id.rl_more) {//点击PK
RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk()).show(getSupportFragmentManager(), "RoomPkDialogFragment"); // RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk()).show(getSupportFragmentManager(), "RoomPkDialogFragment");
RoomPkDialogFragment fragment = RoomPkDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk());
fragment.show(getSupportFragmentManager(), "RoomPkDialogFragment");
addActiveDialogFragment(fragment); // 添加到管理列表
} else if (id == R.id.rl_message) { } else if (id == R.id.rl_message) {
RoomMessageDialogFragment.show(getSupportFragmentManager()); // RoomMessageDialogFragment.show(getSupportFragmentManager());
// RoomMessageDialogFragment.newInstance(roomId, SpUtil.getUserId() + "", mRoomInfoResp.getRoom_info().getIs_pk()).show(getChildFragmentManager(), "RoomMessageDialogFragment"); RoomMessageDialogFragment fragment = RoomMessageDialogFragment.show(getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} else if (id == R.id.rl_misc) {//设置点歌 } else if (id == R.id.rl_misc) {//设置点歌
if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) { if (mRoomInfoResp.getRoom_info().getLabel_id().equals("1")) {
queren(); queren();
} else { } else {
RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager()); // RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager());
RequestDialogFragment fragment = RequestDialogFragment.show(roomId, mRoomInfoResp, 1, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} }
} else if (id == R.id.rl_gift) {//礼物 } else if (id == R.id.rl_gift) {//礼物
RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager()); // RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager());
RoomGiftDialogFragment fragment = RoomGiftDialogFragment.show(mRoomInfoResp, null, roomId, 0, "", getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} else if (id == R.id.iv_sound_effects) { } else if (id == R.id.iv_sound_effects) {
SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager()); // SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager());
SoundEffectsDialogFragment fragment = SoundEffectsDialogFragment.show(roomId, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} else if (id == R.id.cl_first_charge) { } else if (id == R.id.cl_first_charge) {
// showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2); // showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2);
roomFragment.showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2); roomFragment.showWheatFeedingDialog(roomId, (mRoomInfoResp.getUser_info().getIs_room_owner() == 1 || mRoomInfoResp.getUser_info().getIs_host() == 1 || mRoomInfoResp.getUser_info().getIs_management() == 1) ? 1 : 2);
@@ -1751,7 +1804,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
private void queren() { private void queren() {
// 创建并显示确认对话框 // 创建并显示确认对话框
new ConfirmDialog(this, ConfirmDialog dialog= new ConfirmDialog(this,
"提示", "提示",
"您将要发起点歌申请?", "您将要发起点歌申请?",
"确认", "确认",
@@ -1762,7 +1815,9 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
}, },
v -> { v -> {
// 点击“取消”按钮时什么都不做 // 点击“取消”按钮时什么都不做
}, false, 0).show(); }, false, 0);
dialog.show();
addActiveDialog(dialog);
} }
/** /**
@@ -2005,7 +2060,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
} }
}); });
dialog.show(); dialog.show();
addActiveDialog(dialog); // 添加到管理列表
} }
private void countDownTimer() { private void countDownTimer() {
@@ -2234,7 +2289,12 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
mBinding.headName.setText(mRoomInfoResp.getRoom_info().getHead_line().getNickname()); mBinding.headName.setText(mRoomInfoResp.getRoom_info().getHead_line().getNickname());
mBinding.headCone.setText(mRoomInfoResp.getRoom_info().getHead_line().getContent()); mBinding.headCone.setText(mRoomInfoResp.getRoom_info().getHead_line().getContent());
mBinding.ivQuanQiang.setOnClickListener(v -> PublishCommentDialogFragment.show(roomId, getSupportFragmentManager())); mBinding.ivQuanQiang.setOnClickListener(v -> {
PublishCommentDialogFragment fragment = PublishCommentDialogFragment.show(roomId, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
});
mBinding.ivQuanC.setOnClickListener(v -> ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS) mBinding.ivQuanC.setOnClickListener(v -> ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS)
.withString("from", "我的界面") .withString("from", "我的界面")
.withString("roomId", mRoomInfoResp.getRoom_info().getHead_line().getRoom_id()) .withString("roomId", mRoomInfoResp.getRoom_info().getHead_line().getRoom_id())
@@ -2333,6 +2393,7 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
public void showPasswordDialog() { public void showPasswordDialog() {
RoomPasswordSetDialogFragment roomPasswordSetDialogFragment = RoomPasswordSetDialogFragment.newInstance(true, roomId); RoomPasswordSetDialogFragment roomPasswordSetDialogFragment = RoomPasswordSetDialogFragment.newInstance(true, roomId);
roomPasswordSetDialogFragment.show(getSupportFragmentManager()); roomPasswordSetDialogFragment.show(getSupportFragmentManager());
addActiveDialogFragment(roomPasswordSetDialogFragment);
} }
@Override @Override
@@ -2349,8 +2410,11 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
xunf(); xunf();
isMusic = true; isMusic = true;
} }
RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager()); // RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager());
RequestDialogFragment fragment = RequestDialogFragment.show(roomId, mRoomInfoResp, 2, getSupportFragmentManager());
if (fragment != null) {
addActiveDialogFragment(fragment); // 添加到管理列表
}
} }
/** /**
@@ -2734,11 +2798,12 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
super.onDestroy(); super.onDestroy();
// 标记 Activity 已经销毁 // 标记 Activity 已经销毁
sDestroied = true;
overridePendingTransition(0, 0);
} }
private void cleanupResources() { private void cleanupResources() {
sDestroied = true;
overridePendingTransition(0, 0);
try { try {
// 1. 清理 EventBus 注册 // 1. 清理 EventBus 注册
if (EventBus.getDefault().isRegistered(this)) { if (EventBus.getDefault().isRegistered(this)) {
@@ -2770,7 +2835,8 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
if (AgoraManager.getInstance(this) != null) { if (AgoraManager.getInstance(this) != null) {
AgoraManager.getInstance(this).cleanup(); AgoraManager.getInstance(this).cleanup();
} }
// 清理所有弹框
dismissAllDialogs();
// 7. 清理 Fragment // 7. 清理 Fragment
cleanupFragments(); cleanupFragments();
@@ -2784,6 +2850,34 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
LogUtils.e("cleanupResources error: " + e.getMessage()); LogUtils.e("cleanupResources error: " + e.getMessage());
} }
} }
// 清理所有弹框
private void dismissAllDialogs() {
// 关闭 AlertDialog 实例
for (DialogInterface dialog : activeDialogs) {
if (dialog != null) {
try {
dialog.dismiss();
} catch (Exception e) {
LogUtils.e("dismiss dialog error: " + e.getMessage());
}
}
}
activeDialogs.clear();
// 移除 DialogFragment
for (Fragment fragment : activeDialogFragments) {
if (fragment != null && fragment.isAdded()) {
try {
if (fragment instanceof DialogFragment) {
((DialogFragment) fragment).dismissAllowingStateLoss();
}
} catch (Exception e) {
LogUtils.e("dismiss dialog fragment error: " + e.getMessage());
}
}
}
activeDialogFragments.clear();
}
private void clearSVGAResources() { private void clearSVGAResources() {
try { try {
@@ -2802,19 +2896,21 @@ public class RoomActivity extends BaseMvpActivity<RoomPresenter, ActivityRoomBin
private void cleanupFragments() { private void cleanupFragments() {
try { try {
// 清理Fragment
if (publicScreenFragment != null || roomFragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (publicScreenFragment != null) { if (publicScreenFragment != null) {
getSupportFragmentManager().beginTransaction() publicScreenFragment.onFragmentShowDestroy();
.remove(publicScreenFragment) transaction.remove(publicScreenFragment);
.commitAllowingStateLoss();
publicScreenFragment = null; publicScreenFragment = null;
} }
if (roomFragment != null) { if (roomFragment != null) {
getSupportFragmentManager().beginTransaction() roomFragment.onFragmentShowDestroy();
.remove(roomFragment) transaction.remove(roomFragment);
.commitAllowingStateLoss();
roomFragment = null; roomFragment = null;
} }
transaction.commitAllowingStateLoss();
}
} catch (Exception e) { } catch (Exception e) {
LogUtils.e("cleanupFragments error: " + e.getMessage()); LogUtils.e("cleanupFragments error: " + e.getMessage());
} }

View File

@@ -35,12 +35,13 @@ public class PublishCommentDialogFragment extends BaseMvpDialogFragment<PublishC
return new PublishCommentPresenter(this, getActivity()); return new PublishCommentPresenter(this, getActivity());
} }
public static void show(String roomId, FragmentManager fragmentManager) { public static PublishCommentDialogFragment show(String roomId, FragmentManager fragmentManager) {
PublishCommentDialogFragment dialogFragment = new PublishCommentDialogFragment(); PublishCommentDialogFragment dialogFragment = new PublishCommentDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("roomId", roomId); args.putString("roomId", roomId);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "PublishCommentDialogFragment"); dialogFragment.show(fragmentManager, "PublishCommentDialogFragment");
return dialogFragment;
} }
@Override @Override
public void onStart() { public void onStart() {

View File

@@ -47,7 +47,7 @@ public class RequestDialogFragment extends BaseMvpDialogFragment<RequestPresente
protected RequestPresenter bindPresenter() { protected RequestPresenter bindPresenter() {
return new RequestPresenter(this, getActivity()); return new RequestPresenter(this, getActivity());
} }
public static void show(String id,RoomInfoResp roomInfoResp, int type,FragmentManager fragmentManager) { public static RequestDialogFragment show(String id, RoomInfoResp roomInfoResp, int type, FragmentManager fragmentManager) {
RequestDialogFragment dialogFragment = new RequestDialogFragment(); RequestDialogFragment dialogFragment = new RequestDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("roomId", id); // 可选:传递参数 args.putString("roomId", id); // 可选:传递参数
@@ -55,6 +55,7 @@ public class RequestDialogFragment extends BaseMvpDialogFragment<RequestPresente
args.putInt("type", type); args.putInt("type", type);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RequestDialogFragment"); dialogFragment.show(fragmentManager, "RequestDialogFragment");
return dialogFragment;
} }
@Override @Override

View File

@@ -89,7 +89,7 @@ public class RoomGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPres
return new RewardGiftPresenter(this, getActivity()); return new RewardGiftPresenter(this, getActivity());
} }
public static void show(RoomInfoResp roomInfoResp, UserInfo userInfo, String roomId, int jingp, String heart_id, FragmentManager fragmentManager) { public static RoomGiftDialogFragment show(RoomInfoResp roomInfoResp, UserInfo userInfo, String roomId, int jingp, String heart_id, FragmentManager fragmentManager) {
RoomGiftDialogFragment dialogFragment = new RoomGiftDialogFragment(); RoomGiftDialogFragment dialogFragment = new RoomGiftDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putSerializable("roomInfoResp", roomInfoResp); args.putSerializable("roomInfoResp", roomInfoResp);
@@ -99,6 +99,7 @@ public class RoomGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPres
args.putString("heart_id", heart_id); args.putString("heart_id", heart_id);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RewardGiftDialogFragment"); dialogFragment.show(fragmentManager, "RewardGiftDialogFragment");
return dialogFragment;
} }
@Override @Override

View File

@@ -31,11 +31,12 @@ public class RoomMessageDialogFragment extends BaseMvpDialogFragment<NewsPresent
private static final String TAG = "BaseDialogFragment"; private static final String TAG = "BaseDialogFragment";
public static void show(FragmentManager fragmentManager) { public static RoomMessageDialogFragment show(FragmentManager fragmentManager) {
RoomMessageDialogFragment dialogFragment = new RoomMessageDialogFragment(); RoomMessageDialogFragment dialogFragment = new RoomMessageDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment"); dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment");
return dialogFragment;
} }
@Override @Override

View File

@@ -25,7 +25,6 @@ import com.xscm.moduleutil.bean.room.RoomInfoResp;
import com.xscm.moduleutil.bean.room.RoomOnline; import com.xscm.moduleutil.bean.room.RoomOnline;
import com.xscm.moduleutil.bean.room.RoomOnlineBean; import com.xscm.moduleutil.bean.room.RoomOnlineBean;
import com.xscm.moduleutil.bean.room.RoomUserBean; import com.xscm.moduleutil.bean.room.RoomUserBean;
import com.xscm.moduleutil.databinding.FragmentCommentDialogBinding;
import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener; import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
@@ -52,7 +51,7 @@ public class RoomOnlineDialogFragment extends BaseMvpDialogFragment<RoomPresente
return new RoomPresenter(this, getActivity()); return new RoomPresenter(this, getActivity());
} }
public static void show(String id, String pit_number, RoomUserBean hostUser, RoomInfoResp roomInfoResp, FragmentManager fragmentManager) { public static RoomOnlineDialogFragment show(String id, String pit_number, RoomUserBean hostUser, RoomInfoResp roomInfoResp, FragmentManager fragmentManager) {
RoomOnlineDialogFragment dialogFragment = new RoomOnlineDialogFragment(); RoomOnlineDialogFragment dialogFragment = new RoomOnlineDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("roomId", id); // 可选:传递参数 args.putString("roomId", id); // 可选:传递参数
@@ -61,6 +60,7 @@ public class RoomOnlineDialogFragment extends BaseMvpDialogFragment<RoomPresente
args.putSerializable("roomInfoResp", roomInfoResp); args.putSerializable("roomInfoResp", roomInfoResp);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment"); dialogFragment.show(fragmentManager, "RoomOnlineDialogFragment");
return dialogFragment;
} }
@Override @Override

View File

@@ -67,12 +67,13 @@ public class RoomSettingFragment extends BaseMvpDialogFragment<RoomSettingPresen
return new RoomSettingPresenter(this, getActivity()); return new RoomSettingPresenter(this, getActivity());
} }
public static void show(RoomInfoResp roomInfoResp, FragmentManager fragmentManager) { public static RoomSettingFragment show(RoomInfoResp roomInfoResp, FragmentManager fragmentManager) {
RoomSettingFragment dialogFragment = new RoomSettingFragment(); RoomSettingFragment dialogFragment = new RoomSettingFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putSerializable("roomInfoResp", roomInfoResp); args.putSerializable("roomInfoResp", roomInfoResp);
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "RoomSettingFragment"); dialogFragment.show(fragmentManager, "RoomSettingFragment");
return dialogFragment;
} }
@Override @Override

View File

@@ -42,12 +42,13 @@ public class SoundEffectsDialogFragment extends BaseMvpDialogFragment<WheatPrese
protected WheatPresenter bindPresenter() { protected WheatPresenter bindPresenter() {
return new WheatPresenter(this, getActivity()); return new WheatPresenter(this, getActivity());
} }
public static void show(String id, FragmentManager fragmentManager) { public static SoundEffectsDialogFragment show(String id, FragmentManager fragmentManager) {
SoundEffectsDialogFragment dialogFragment = new SoundEffectsDialogFragment(); SoundEffectsDialogFragment dialogFragment = new SoundEffectsDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("roomId", id); // 可选:传递参数 args.putString("roomId", id); // 可选:传递参数
dialogFragment.setArguments(args); dialogFragment.setArguments(args);
dialogFragment.show(fragmentManager, "SoundEffectsDialogFragment"); dialogFragment.show(fragmentManager, "SoundEffectsDialogFragment");
return dialogFragment;
} }
@Override @Override
protected void initData() { protected void initData() {

View File

@@ -21,6 +21,7 @@ import android.widget.PopupWindow;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import com.blankj.utilcode.util.LogUtils;
import com.example.moduleroom.R; import com.example.moduleroom.R;
import com.example.moduleroom.activity.RoomActivity; import com.example.moduleroom.activity.RoomActivity;
import com.example.moduleroom.contacts.FriendshipRoomContacts; import com.example.moduleroom.contacts.FriendshipRoomContacts;
@@ -532,10 +533,6 @@ public class FriendshipRoomFragment extends BaseRoomFragment<FriendshipRoomPrese
} }
/// 销毁视图
public void destroyViews() {
}
/** /**
* 心动数值变化 * 心动数值变化
@@ -1022,4 +1019,70 @@ public class FriendshipRoomFragment extends BaseRoomFragment<FriendshipRoomPrese
public void hideAllWheatMaozi() { public void hideAllWheatMaozi() {
} }
/**
* 销毁视图和资源
*/
public void releaseResources() {
// 停止并释放所有SVGA动画资源
stopAndReleaseSVGA(mBinding.iv22);
stopAndReleaseSVGA(mBinding.iv11);
stopAndReleaseSVGA(mBinding.iv33);
// 重置动画状态标志
topIsAnimate = false;
centerIsAnimate = false;
bottomIsAnimate = false;
// 停止倒计时器
releaseCountDownTimer();
// 清理PopupWindow
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
popupWindow = null;
}
// 清理对话框
if (dialogFragment != null && dialogFragment.isAdded()) {
dialogFragment.dismissAllowingStateLoss();
dialogFragment = null;
}
}
/**
* 安全地停止并释放SVGA资源
* @param svgaView SVGAImageView实例
*/
private void stopAndReleaseSVGA(com.opensource.svgaplayer.SVGAImageView svgaView) {
if (svgaView != null) {
try {
// 停止动画
svgaView.stopAnimation();
// 清除回调
svgaView.setCallback(null);
// 释放资源
svgaView.clear();
} catch (Exception e) {
LogUtils.e("Error releasing SVGA: " + e.getMessage());
}
}
}
@Override
public void onDestroyView() {
// 在视图销毁前释放资源
releaseResources();
super.onDestroyView();
}
@Override
public void onDestroy() {
// 确保资源被释放
releaseResources();
super.onDestroy();
}
} }

View File

@@ -120,12 +120,27 @@ public class PublicScreenEaseChatFragment extends BaseMvpFragment<PublicScreenEa
@Override @Override
public void onDestroyView() { public void onDestroyView() {
// mBinding.recycleView.removeCallbacks(joinChatRoomTask); // mBinding.recycleView.removeCallbacks(joinChatRoomTask);
// EventBus.getDefault().unregister(this);
// RoomMessageManager.getInstance().unregister(this);
// if (countDownTimer != null) {
// countDownTimer.cancel();
// }
onFragmentShowDestroy();
super.onDestroyView();
}
public void onFragmentShowDestroy() {
if (EventBus.getDefault().isRegistered(this)){
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
}
RoomMessageManager.getInstance().unregister(this); RoomMessageManager.getInstance().unregister(this);
if (countDownTimer != null) { if (countDownTimer != null) {
countDownTimer.cancel(); countDownTimer.cancel();
} }
super.onDestroyView(); if (messageListener != null) {
LogUtils.e("移除监听器");
MessageListenerSingleton.getInstance().removePublicScreenMessageListener(messageListener);
}
} }
@Override @Override

View File

@@ -1017,9 +1017,10 @@ public class RoomAuctionFragment extends BaseMvpFragment<RoomAuctionPresenterTow
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
// stub.setVisibility(GONE); // stub.setVisibility(GONE);
isButtonsInflated = false; // isButtonsInflated = false;
releaseCountDownTimer(); // releaseCountDownTimer();
// EventBus.getDefault().unregister(this); // EventBus.getDefault().unregister(this);
releaseResources();
} }
private void yinc() { private void yinc() {
@@ -1290,6 +1291,13 @@ public class RoomAuctionFragment extends BaseMvpFragment<RoomAuctionPresenterTow
// EventBus.getDefault().unregister(this); // EventBus.getDefault().unregister(this);
// } // }
// stub.setVisibility(GONE); // stub.setVisibility(GONE);
releaseResources();
}
public void releaseResources() {
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
isButtonsInflated = false; isButtonsInflated = false;
releaseCountDownTimer(); releaseCountDownTimer();
} }

View File

@@ -1,10 +1,7 @@
package com.example.moduleroom.fragment; package com.example.moduleroom.fragment;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static com.blankj.utilcode.util.ServiceUtils.startService;
import static com.google.common.reflect.Reflection.getPackageName;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
@@ -71,6 +68,7 @@ import io.agora.rtc2.video.VideoCanvas;
* @description: 电影房 * @description: 电影房
*/ */
public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, RoomCabinFragmentBinding> implements RoomCabinContacts.View { public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, RoomCabinFragmentBinding> implements RoomCabinContacts.View {
private static final String LABEL_ID_MOVIE = "5";
protected String roomId; protected String roomId;
protected String pitNumber;//当前点击的麦序 protected String pitNumber;//当前点击的麦序
protected CommonDialog commonDialog; protected CommonDialog commonDialog;
@@ -99,12 +97,11 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
public void initArgs(Bundle arguments) { public void initArgs(Bundle arguments) {
super.initArgs(arguments); super.initArgs(arguments);
roomInfoResp = (RoomInfoResp) arguments.getSerializable("roomInfoResp"); roomInfoResp = (RoomInfoResp) arguments.getSerializable("roomInfoResp");
if (roomInfoResp != null) {
roomId = roomInfoResp.getRoom_info().getRoom_id(); roomId = roomInfoResp.getRoom_info().getRoom_id();
if (roomInfoResp.getCp_user() != null) {
cpUserBean = roomInfoResp.getCp_user(); cpUserBean = roomInfoResp.getCp_user();
label_id = roomInfoResp.getRoom_info().getLabel_id();
} }
label_id=roomInfoResp.getRoom_info().getLabel_id();
} }
private boolean isLandscape; private boolean isLandscape;
@@ -148,6 +145,7 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
@Override @Override
protected void initData() { protected void initData() {
if (roomInfoResp == null) return;
mBinding.ivExit.setOnClickListener(this::onHeartLineClicked); mBinding.ivExit.setOnClickListener(this::onHeartLineClicked);
// 获取当前用户 ID // 获取当前用户 ID
@@ -160,6 +158,7 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
boolean isSelfFirst = false; boolean isSelfFirst = false;
// 判断当前用户是 user_id 还是 user_id1 // 判断当前用户是 user_id 还是 user_id1
if (cpUserBean != null) {
if (currentUserId.equals(cpUserBean.getUser_id())) { if (currentUserId.equals(cpUserBean.getUser_id())) {
// 当前用户是 user_id // 当前用户是 user_id
selfBean.setUser_id(cpUserBean.getUser_id()); selfBean.setUser_id(cpUserBean.getUser_id());
@@ -193,13 +192,16 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
otherBean.setDress(cpUserBean.getDress()); otherBean.setDress(cpUserBean.getDress());
otherBean.setPit_number("000"); otherBean.setPit_number("000");
} }
}
// 不论谁是自己,始终将自己放在 roomMakeWheat1 // 不论谁是自己,始终将自己放在 roomMakeWheat1
mBinding.roomMakeWheat1.setData(selfBean); mBinding.roomMakeWheat1.setData(selfBean);
// 将另一个用户的数据放在 roomMakeWheat2 // 将另一个用户的数据放在 roomMakeWheat2
mBinding.roomMakeWheat2.setData(otherBean); mBinding.roomMakeWheat2.setData(otherBean);
mBinding.tvMainTitle.setText(roomInfoResp.getRoom_info().getRoom_name()); mBinding.tvMainTitle.setText(roomInfoResp.getRoom_info().getRoom_name());
mBinding.tvHeartValue2.setText(roomInfoResp.getRoom_info().getHot_value()); mBinding.tvHeartValue2.setText(roomInfoResp.getRoom_info().getHot_value());
if (cpUserBean != null) {
countDownTime(Long.parseLong(cpUserBean.getTime_day())); countDownTime(Long.parseLong(cpUserBean.getTime_day()));
}
mediaProjectionManager = (MediaProjectionManager) getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE); mediaProjectionManager = (MediaProjectionManager) getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
} }
@@ -254,14 +256,14 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
} }
}); });
if (roomInfoResp.getRoom_owner().getUser_id().equals(SpUtil.getUserId()+"")){ if (roomInfoResp != null && roomInfoResp.getRoom_owner().getUser_id().equals(SpUtil.getUserId()+"")){
mBinding.im3.setVisibility(VISIBLE); mBinding.im3.setVisibility(VISIBLE);
setvkk(false); setvkk(false);
}else { }else {
mBinding.im3.setVisibility(GONE); mBinding.im3.setVisibility(GONE);
} }
// if (label_id!=null&& label_id.equals("5")){ // if (label_id!=null&& label_id.equals(LABEL_ID_MOVIE)){
// mBinding.im3.setVisibility(GONE); // mBinding.im3.setVisibility(GONE);
// } // }
} }
@@ -339,13 +341,15 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
@Override @Override
public void onExitRoom() { public void onExitRoom() {
// 调用退出房间方法 // 调用退出房间方法
if (roomInfoResp.getRoom_info().getLabel_id().equals("5")){ if (label_id!=null && label_id.equals(LABEL_ID_MOVIE)){
MvpPre.quitRoom(roomId, SpUtil.getUserId() + ""); MvpPre.quitRoom(roomId, SpUtil.getUserId() + "");
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation(); // ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation();
return; return;
} }
if (roomInfoResp != null) {
MvpPre.quitRoom(roomInfoResp.getRoom_info().getRoom_id(), SpUtil.getUserId() + ""); MvpPre.quitRoom(roomInfoResp.getRoom_info().getRoom_id(), SpUtil.getUserId() + "");
} }
}
@Override @Override
public void onCancel() { public void onCancel() {
@@ -432,7 +436,7 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
mBinding.datingTime.setText("00:00:00"); mBinding.datingTime.setText("00:00:00");
} }
String formattedTime = formatTime(time); String formattedTime = formatTime(time);
if (label_id!=null && label_id.equals("5")){ if (label_id!=null && label_id.equals(LABEL_ID_MOVIE)){
mBinding.datingTime.setText("倒计时:" + formattedTime); mBinding.datingTime.setText("倒计时:" + formattedTime);
}else { }else {
mBinding.datingTime.setText("到期时间:" + formattedTime); mBinding.datingTime.setText("到期时间:" + formattedTime);
@@ -448,14 +452,16 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
} }
protected void updateWheatData() { protected void updateWheatData() {
if (!ObjectUtils.isEmpty(roomInfoResp.getRoom_info().getPit_list())) { if (roomInfoResp != null && !ObjectUtils.isEmpty(roomInfoResp.getRoom_info().getPit_list())) {
for (RoomPitBean bean : roomInfoResp.getRoom_info().getPit_list()) { for (RoomPitBean bean : roomInfoResp.getRoom_info().getPit_list()) {
EventBus.getDefault().post(bean); EventBus.getDefault().post(bean);
} }
} }
if (roomInfoResp != null) {
RoomBeckoningEvent event = new RoomBeckoningEvent(roomId, roomInfoResp.getRoom_info().getCardiac() == 1); RoomBeckoningEvent event = new RoomBeckoningEvent(roomId, roomInfoResp.getRoom_info().getCardiac() == 1);
EventBus.getDefault().post(event); EventBus.getDefault().post(event);
} }
}
@Override @Override
@@ -509,7 +515,7 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
if (getActivity() instanceof RoomActivity) { if (getActivity() instanceof RoomActivity) {
LogUtils.e("lxj", "退出房间时间:" + TimeUtils.date2String(new Date())+":退出的roomId"+roomId); LogUtils.e("lxj", "退出房间时间:" + TimeUtils.date2String(new Date())+":退出的roomId"+roomId);
((RoomActivity) getActivity()).quitRoom2(roomId); ((RoomActivity) getActivity()).quitRoom2(roomId);
if (roomInfoResp.getRoom_info().getLabel_id().equals("5")){ if (label_id!=null && label_id.equals(LABEL_ID_MOVIE)){
((RoomActivity) getActivity()).jiaR(); ((RoomActivity) getActivity()).jiaR();
// ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation(); // ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", AgoraManager.getInstance(getActivity()).getLastRoomId()).navigation();
return; return;
@@ -666,4 +672,18 @@ public class RoomCabinFragment extends BaseRoomFragment<RoomCabinPresenter, Room
isMicPlace=true; isMicPlace=true;
} }
} }
@Override
public void onDestroy() {
super.onDestroy();
releaseResources();
}
public void releaseResources(){
releaseCountDownTimer();
if (mediaProjection[0] != null) {
mediaProjection[0].stop();
mediaProjection[0] = null;
}
}
} }

View File

@@ -69,6 +69,7 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -122,6 +123,20 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
// if (EventBus.getDefault().isRegistered(this)) {
// EventBus.getDefault().unregister(this);
// }
//
// // 释放SVGA动画资源
// if (mBinding != null && mBinding.svgaNobility != null) {
// mBinding.svgaNobility.release();
// }
//
// releaseAllResources();
onFragmentShowDestroy();
}
public void onFragmentShowDestroy() {
if (EventBus.getDefault().isRegistered(this)) { if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
} }
@@ -133,7 +148,6 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
releaseAllResources(); releaseAllResources();
} }
/** /**
* 释放Fragment中的所有资源 * 释放Fragment中的所有资源
*/ */
@@ -157,16 +171,19 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
// } // }
// 取消所有可能的网络请求 // 取消所有可能的网络请求
if (MvpPre != null) { // if (MvpPre != null) {
// 取消与Fragment相关的网络请求如果有提供相应方法 // // 取消与Fragment相关的网络请求如果有提供相应方法
MvpPre.cancelRequest(); // MvpPre.cancelRequest();
} // }
} catch (Exception e) { } catch (Exception e) {
LogUtils.e("releaseAllResources error: " + e.getMessage()); LogUtils.e("releaseAllResources error: " + e.getMessage());
} }
} }
/**
* 释放所有子Fragment
*/
/** /**
* 释放所有子Fragment * 释放所有子Fragment
*/ */
@@ -175,6 +192,25 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
// 获取所有子Fragment // 获取所有子Fragment
List<Fragment> fragments = getChildFragmentManager().getFragments(); List<Fragment> fragments = getChildFragmentManager().getFragments();
if (!fragments.isEmpty()) { if (!fragments.isEmpty()) {
for (Fragment fragment : fragments) {
if (fragment != null) {
// 检查Fragment是否实现了特定的销毁接口
if (fragment instanceof SingSongFragment) {
((SingSongFragment) fragment).releaseResources();
}else if (fragment instanceof RoomKtvFragment){
((RoomKtvFragment) fragment).releaseResources();
}else if (fragment instanceof FriendshipRoomFragment){
((FriendshipRoomFragment) fragment).releaseResources();
}else if (fragment instanceof RoomCabinFragment){
((RoomCabinFragment) fragment).releaseResources();
}else if (fragment instanceof RoomAuctionFragment) {
((RoomAuctionFragment) fragment).releaseResources();
}
}
}
// 最后移除所有Fragment
FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
for (Fragment fragment : fragments) { for (Fragment fragment : fragments) {
if (fragment != null) { if (fragment != null) {
@@ -188,6 +224,9 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
} }
} }
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
@@ -421,10 +460,34 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
// if (existing != null) { // if (existing != null) {
// transaction.remove(existing); // transaction.remove(existing);
// } // }
callSpecificDestroyMethod(newFragment);
transaction.replace(containerId, newFragment, tag); transaction.replace(containerId, newFragment, tag);
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
} }
/**
* 调用特定Fragment的销毁方法
* @param fragment 需要销毁的Fragment
*/
private void callSpecificDestroyMethod(Fragment fragment) {
try {
// 尝试调用Fragment的特定销毁方法
if (fragment instanceof SingSongFragment) {
((SingSongFragment) fragment).releaseResources();
} else if (fragment instanceof RoomKtvFragment) {
((RoomKtvFragment) fragment).releaseResources();
} else if (fragment instanceof FriendshipRoomFragment) {
((FriendshipRoomFragment) fragment).releaseResources();
} else if (fragment instanceof RoomCabinFragment) {
((RoomCabinFragment) fragment).releaseResources();
} else if (fragment instanceof RoomAuctionFragment) {
((RoomAuctionFragment) fragment).releaseResources();
}
} catch (Exception e) {
LogUtils.e("callSpecificDestroyMethod error: " + e.getMessage());
}
}
public void updateWheatStatus(RoomPitBean roomPitBean, int pit, boolean isOccupied, boolean isMine) { public void updateWheatStatus(RoomPitBean roomPitBean, int pit, boolean isOccupied, boolean isMine) {
mRoomInfoResp.getRoom_info().getPit_list().set(pit - 1, roomPitBean); mRoomInfoResp.getRoom_info().getPit_list().set(pit - 1, roomPitBean);

View File

@@ -81,7 +81,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
// roomInfoResp = (RoomInfoResp) getArguments().getSerializable("roomInfo"); // roomInfoResp = (RoomInfoResp) getArguments().getSerializable("roomInfo");
} }
public void roomInfoUpdate(RoomInfoResp resp){ public void roomInfoUpdate(RoomInfoResp resp) {
roomInfoResp = resp; roomInfoResp = resp;
upData(); upData();
} }
@@ -196,7 +196,6 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
} }
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
@@ -464,6 +463,10 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
releaseResources();
}
public void releaseResources() {
endRotateAnimation(); endRotateAnimation();
// AgoraManager.getInstance(getActivity()).destroy(); // AgoraManager.getInstance(getActivity()).destroy();
if (EventBus.getDefault().isRegistered(this)) { if (EventBus.getDefault().isRegistered(this)) {
@@ -534,9 +537,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
if (EventBus.getDefault().isRegistered(this)) { releaseResources();
EventBus.getDefault().unregister(this);
}
} }
public void event1013(RoomMessageEvent messageEvent) { public void event1013(RoomMessageEvent messageEvent) {
@@ -603,7 +604,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
sv(); sv();
} }
public void event1003(RoomMessageEvent messageEvent){ public void event1003(RoomMessageEvent messageEvent) {
boolean b = false; boolean b = false;
if (messageEvent.getText().getPit_number().equals("9") || messageEvent.getText().getPit_number().equals("10")) { if (messageEvent.getText().getPit_number().equals("9") || messageEvent.getText().getPit_number().equals("10")) {
@@ -648,7 +649,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
sv(); sv();
} }
public void event1004(RoomMessageEvent messageEvent){ public void event1004(RoomMessageEvent messageEvent) {
boolean b = false; boolean b = false;
if (messageEvent.getText().getPit_number().equals("9") || messageEvent.getText().getPit_number().equals("10")) { if (messageEvent.getText().getPit_number().equals("9") || messageEvent.getText().getPit_number().equals("10")) {
RoomPitBean pitBean = new RoomPitBean(); RoomPitBean pitBean = new RoomPitBean();
@@ -688,7 +689,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
sv(); sv();
} }
public void event1021(RoomMessageEvent messageEvent){ public void event1021(RoomMessageEvent messageEvent) {
RoomPitBean pitBean = mBinding.muYc.pitBean; RoomPitBean pitBean = mBinding.muYc.pitBean;
pitBean.setCharm("0"); pitBean.setCharm("0");
mBinding.muYc.setData(pitBean); mBinding.muYc.setData(pitBean);
@@ -705,7 +706,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
adapter.setNewData(roomInfoResp.getSong_pit_list()); adapter.setNewData(roomInfoResp.getSong_pit_list());
} }
public void event1005(RoomMessageEvent messageEvent){ public void event1005(RoomMessageEvent messageEvent) {
RoomPitBean pitBean = mBinding.muYc.pitBean; RoomPitBean pitBean = mBinding.muYc.pitBean;
if ((messageEvent.getText().getToUserInfo().getUser_id() + "").equals(pitBean.getUser_id())) { if ((messageEvent.getText().getToUserInfo().getUser_id() + "").equals(pitBean.getUser_id())) {
pitBean.setCharm(messageEvent.getText().getToUserInfo().getCharm()); pitBean.setCharm(messageEvent.getText().getToUserInfo().getCharm());
@@ -730,7 +731,7 @@ public class RoomKtvFragment extends BaseMvpFragment<RoomPresenter, FragmentRoom
adapter.setNewData(roomInfoResp.getSong_pit_list()); adapter.setNewData(roomInfoResp.getSong_pit_list());
} }
public void event1035(RoomMessageEvent messageEvent){ public void event1035(RoomMessageEvent messageEvent) {
RoomPitBean pitBean = mBinding.muZc.pitBean; RoomPitBean pitBean = mBinding.muZc.pitBean;
if (pitBean.getUser_id().equals(messageEvent.getText().getFromUserInfo().getUser_id() + "")) { if (pitBean.getUser_id().equals(messageEvent.getText().getFromUserInfo().getUser_id() + "")) {
pitBean.setCharm(messageEvent.getText().getFromUserInfo().getCharm()); pitBean.setCharm(messageEvent.getText().getFromUserInfo().getCharm());

View File

@@ -1497,24 +1497,19 @@ public class SingSongFragment extends BaseRoomFragment<SingSongPresenter, Fragme
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
releaseCountDownTimer(); releaseResources();
if (wheatLayoutSingManager != null) {
wheatLayoutSingManager.release();
}
if (wheatLayoutManager1 != null) {
wheatLayoutManager1.clear();
}
if (wheatLayoutManager2 != null) {
wheatLayoutManager2.clear();
}
mBinding.flexboxLayout.removeAllViews();
mBinding.flexboxLayout2.removeAllViews();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
releaseResources();
}
public void releaseResources(){
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
releaseCountDownTimer(); releaseCountDownTimer();
if (wheatLayoutSingManager != null) { if (wheatLayoutSingManager != null) {
wheatLayoutSingManager.release(); wheatLayoutSingManager.release();