fix bugs.9
This commit is contained in:
@@ -274,37 +274,37 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
mRoomActivity.isInAuctionTopBtVisible(false);
|
||||
|
||||
if (roomType == RoomType.MUTUAL_ENTERTAINMENT) {
|
||||
if (friendshipRoomFragment != null && friendshipRoomFragment.isAdded()) {
|
||||
if (friendshipRoomFragment == currentFragment && friendshipRoomFragment.isAdded()) {
|
||||
friendshipRoomFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
} else if (roomType == RoomType.AUCTION) {
|
||||
mRoomActivity.isInAuctionTopBtVisible(true);
|
||||
if (roomAuctionFragment != null && roomAuctionFragment.isAdded()) {
|
||||
if (roomAuctionFragment == currentFragment && roomAuctionFragment.isAdded()) {
|
||||
roomAuctionFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
} else if (roomType == RoomType.DATING && labelId.equals("2")) {
|
||||
switch (labelId) {
|
||||
case "2":
|
||||
if (ktvFragment != null && ktvFragment.isAdded()) {
|
||||
if (ktvFragment == currentFragment && ktvFragment.isAdded()) {
|
||||
ktvFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
break;
|
||||
case "1":
|
||||
if (singSongFragment != null && singSongFragment.isAdded()) {
|
||||
if (singSongFragment == currentFragment && singSongFragment.isAdded()) {
|
||||
singSongFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (roomType == RoomType.BLACK_ROOM) {
|
||||
if (roomCabinFragment != null && roomCabinFragment.isAdded()) {
|
||||
if (roomCabinFragment == currentFragment && roomCabinFragment.isAdded()) {
|
||||
roomCabinFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
} else if (roomType == RoomType.JUKEBOX) {
|
||||
if (roomJukeboxFragment != null && roomJukeboxFragment.isAdded()) {
|
||||
if (roomJukeboxFragment == currentFragment && roomJukeboxFragment.isAdded()) {
|
||||
roomJukeboxFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
} else if (roomType == RoomType.SIGN_CONTRACT) {
|
||||
if (mentorShipFragment != null && mentorShipFragment.isAdded()) {
|
||||
if (mentorShipFragment == currentFragment && mentorShipFragment.isAdded()) {
|
||||
mentorShipFragment.roomInfoUpdate(mRoomInfoResp);
|
||||
}
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
|
||||
/// 给子fragment传递参数
|
||||
public void updateFriendshipState(int status, int friend_id, long end_time, FriendUserBean friendshipUserBean) {
|
||||
if (friendshipRoomFragment != null && friendshipRoomFragment.isAdded()) {
|
||||
if (friendshipRoomFragment == currentFragment && friendshipRoomFragment.isAdded()) {
|
||||
if (status == FriendshipRoomFragment.FriendshipPartType.WAIT.getValue())
|
||||
friendshipRoomFragment.upDataFriendship(FriendshipRoomFragment.FriendshipPartType.WAIT, friend_id, end_time, friendshipUserBean);
|
||||
else if (status == FriendshipRoomFragment.FriendshipPartType.HEART.getValue())
|
||||
@@ -330,34 +330,34 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
|
||||
/// 交友房时间发生延时
|
||||
public void friendTimeDelayWithTime(long end_time) {
|
||||
if (friendshipRoomFragment != null) {
|
||||
if (friendshipRoomFragment == currentFragment) {
|
||||
friendshipRoomFragment.friendTimeDelayWithTime(end_time);
|
||||
}
|
||||
}
|
||||
|
||||
/// 心动值发生变化
|
||||
public void friendHeartNumberDidChanged(List<FriendInfo.HeartList> heartLists) {
|
||||
if (friendshipRoomFragment != null) {
|
||||
if (friendshipRoomFragment == currentFragment) {
|
||||
friendshipRoomFragment.friendHeartNumberDidChanged(heartLists);
|
||||
}
|
||||
}
|
||||
|
||||
/// 交友房麦位发生变化
|
||||
public void friendSeatDidChanged(List<RoomPitBean> pitArr) {
|
||||
if (friendshipRoomFragment != null) {
|
||||
if (friendshipRoomFragment == currentFragment) {
|
||||
friendshipRoomFragment.friendSeatDidChanged(pitArr);
|
||||
}
|
||||
}
|
||||
|
||||
public void upFriendList(List<RoomPitBean> pitArr) {
|
||||
if (friendshipRoomFragment != null) {
|
||||
if (friendshipRoomFragment == currentFragment) {
|
||||
friendshipRoomFragment.upFriendList();
|
||||
}
|
||||
}
|
||||
|
||||
/// 小黑屋修改倒计时
|
||||
public void upCabinFragment(long time) {
|
||||
if (roomCabinFragment != null)
|
||||
if (roomCabinFragment == currentFragment)
|
||||
roomCabinFragment.upCabinFragment(time);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
if (mRoomInfoResp == null || mRoomInfoResp.getRoom_info() == null) return;
|
||||
|
||||
// 先释放旧 Fragment
|
||||
releaseChildFragments();
|
||||
// releaseChildFragments();
|
||||
|
||||
String typeId = mRoomInfoResp.getRoom_info().getType_id();
|
||||
String labelId = mRoomInfoResp.getRoom_info().getLabel_id();
|
||||
@@ -435,7 +435,11 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
}
|
||||
|
||||
if (newFragment != null) {
|
||||
switchFragmentSafely(newFragment, R.id.container);
|
||||
if (currentFragment == null){
|
||||
performFragmentReplacement(newFragment, R.id.container);
|
||||
}else {
|
||||
switchFragmentSafely(newFragment, R.id.container);
|
||||
}
|
||||
} else {
|
||||
LogUtils.e("newFragment==null");
|
||||
}
|
||||
@@ -458,32 +462,43 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
if (isReplacing) return;
|
||||
isReplacing = true;
|
||||
|
||||
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||
|
||||
// 1️⃣ 如果 newFragment 没有添加过,先 add
|
||||
if (!newFragment.isAdded()) {
|
||||
ft.add(containerId, newFragment, newFragment.getClass().getSimpleName());
|
||||
View container = getView().findViewById(containerId);
|
||||
if (container == null) {
|
||||
isReplacing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2️⃣ 显示 newFragment
|
||||
ft.show(newFragment);
|
||||
container.post(() -> {
|
||||
if (!isAdded()) {
|
||||
isReplacing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3️⃣ 提交事务立即执行,确保 UI 已渲染
|
||||
ft.commitNowAllowingStateLoss();
|
||||
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||
|
||||
// 4️⃣ 移除或隐藏旧 Fragment(currentFragment)
|
||||
if (currentFragment != null && currentFragment != newFragment) {
|
||||
FragmentTransaction removeFt = getChildFragmentManager().beginTransaction();
|
||||
removeFt.remove(currentFragment); // 或 remove + releaseResources()
|
||||
removeFt.commitNowAllowingStateLoss();
|
||||
}
|
||||
// 1️⃣ 如果新 Fragment 没添加过,先 add
|
||||
if (!newFragment.isAdded()) {
|
||||
ft.add(containerId, newFragment, newFragment.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
// 5️⃣ 更新 currentFragment
|
||||
currentFragment = newFragment;
|
||||
isReplacing = false;
|
||||
// 2️⃣ 显示新 Fragment
|
||||
ft.show(newFragment);
|
||||
|
||||
// 3️⃣ 隐藏旧 Fragment
|
||||
if (currentFragment != null && currentFragment != newFragment) {
|
||||
ft.hide(currentFragment);
|
||||
}
|
||||
|
||||
ft.commitAllowingStateLoss(); // 使用异步提交,避免阻塞 UI
|
||||
|
||||
// 4️⃣ 更新引用
|
||||
currentFragment = newFragment;
|
||||
isReplacing = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// RoomFragment.java
|
||||
|
||||
|
||||
@@ -491,31 +506,39 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
* 安全替换子 Fragment
|
||||
*/
|
||||
private void performFragmentReplacement(@NonNull Fragment newFragment, int containerId) {
|
||||
if (isReplacing) return; // 防重复提交
|
||||
if (isReplacing) return;
|
||||
isReplacing = true;
|
||||
|
||||
// 在 UI 线程下一帧执行,保证上一帧 remove 完成
|
||||
if (getView() != null) {
|
||||
getView().post(() -> {
|
||||
if (!isAdded()) {
|
||||
isReplacing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||
ft.replace(containerId, newFragment, "TAG_" + containerId);
|
||||
ft.commitNowAllowingStateLoss();
|
||||
|
||||
isReplacing = false; // 释放标记
|
||||
});
|
||||
} else {
|
||||
// Fragment view 尚未创建,延迟执行
|
||||
getViewLifecycleOwnerLiveData().observe(getViewLifecycleOwner(), owner -> {
|
||||
if (owner != null) {
|
||||
performFragmentReplacement(newFragment, containerId);
|
||||
}
|
||||
});
|
||||
View container = getView().findViewById(containerId);
|
||||
if (container == null) {
|
||||
isReplacing = false;
|
||||
return;
|
||||
}
|
||||
if (!isAdded()) {
|
||||
isReplacing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||
|
||||
// 1️⃣ 如果新 Fragment 没添加过,先 add
|
||||
if (!newFragment.isAdded()) {
|
||||
ft.add(containerId, newFragment, newFragment.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
// 2️⃣ 显示新 Fragment
|
||||
ft.show(newFragment);
|
||||
|
||||
// 3️⃣ 隐藏旧 Fragment
|
||||
if (currentFragment != null && currentFragment != newFragment) {
|
||||
ft.hide(currentFragment);
|
||||
}
|
||||
|
||||
ft.commitAllowingStateLoss(); // 使用异步提交,避免阻塞 UI
|
||||
|
||||
// 4️⃣ 更新引用
|
||||
currentFragment = newFragment;
|
||||
isReplacing = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -750,7 +773,7 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
|
||||
// TODO: 2025/9/3 小黑屋火热值更新
|
||||
public void handleMsgType1028(RoomMessageEvent messageEvent) {
|
||||
if (roomCabinFragment != null) {
|
||||
if (roomCabinFragment == currentFragment) {
|
||||
roomCabinFragment.handleMsgType1028(messageEvent);
|
||||
}
|
||||
}
|
||||
@@ -766,35 +789,35 @@ public class RoomFragment extends BaseMvpFragment<RoomPresenter, FragmentRoomBin
|
||||
|
||||
switch (qxRoomSeatViewType) {
|
||||
case KTV:
|
||||
if (ktvFragment != null) {
|
||||
if (ktvFragment == currentFragment) {
|
||||
handleKtvEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
|
||||
case NORMAL:
|
||||
if (singSongFragment != null) {
|
||||
if (singSongFragment == currentFragment) {
|
||||
handleSingSongEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
|
||||
case AUCTION:
|
||||
if (roomAuctionFragment != null) {
|
||||
if (roomAuctionFragment == currentFragment) {
|
||||
handleAuctionEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
|
||||
case FRIEND:
|
||||
if (friendshipRoomFragment != null) {
|
||||
if (friendshipRoomFragment == currentFragment) {
|
||||
handleFriendshipEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
case JUKEBOX:
|
||||
if (roomJukeboxFragment != null) {
|
||||
if (roomJukeboxFragment == currentFragment) {
|
||||
handleJukeboxEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
case SIGNCONTRACT:
|
||||
if (mentorShipFragment != null) {
|
||||
if (mentorShipFragment == currentFragment) {
|
||||
handleMentorshipEvent(messageEvent);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user