From 0c7ae4e4f71a42b590d205cbe333f8d8b07f78cf Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 4 Dec 2023 18:19:22 +0800 Subject: [PATCH] update --- .../com/yunbao/live/dialog/LiveGiftPopup.java | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java index b3e9a331a..644d2ef71 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveGiftPopup.java @@ -27,6 +27,8 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -128,6 +130,8 @@ public class LiveGiftPopup extends AbsDialogFragment { private boolean isPk; private FragmentTransaction transaction=null; + private FragmentManager fragmentManager; + private Fragment contentFragment; @Override @@ -239,11 +243,10 @@ public class LiveGiftPopup extends AbsDialogFragment { giftTitleAdapter.uncheck(); liveWrap.setAlpha(1.0f); liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); - if(transaction==null){ - transaction=getTransaction(); - } - transaction.replace(R.id.context_layout_gift, LiveParcelFragment.newInstance(mStream, mLiveUid)); - transaction.commit(); + transaction=getTransaction(); + contentFragment=LiveParcelFragment.newInstance(mStream, mLiveUid); + transaction.replace(R.id.context_layout_gift, contentFragment); + transaction.commitAllowingStateLoss(); isWrap = true; findViewById(R.id.red_point).setVisibility(View.GONE); } @@ -477,12 +480,11 @@ public class LiveGiftPopup extends AbsDialogFragment { List liveGiftBeans = JSONArray.parseArray(giftJson, LiveGiftBean.class); for (LiveGiftBean model : liveGiftBeans) { if (TextUtils.equals(model.getId() + "", mWishGiftId)) { - if(transaction==null){ - transaction=getTransaction(); - } - transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, + transaction=getTransaction(); + contentFragment=LiveGiftFragment.newInstance(giftJson, liveGiftList.getJSONObject(i).getString("name"), - mStream, mLiveUid, mWishGiftId)); + mStream, mLiveUid, mWishGiftId); + transaction.replace(R.id.context_layout_gift, contentFragment); transaction.commitAllowingStateLoss(); giftTitleAdapter.setTitleIndex(i); break; @@ -493,12 +495,11 @@ public class LiveGiftPopup extends AbsDialogFragment { JSONObject obj2 = liveGiftList.getJSONObject(0); String giftJson = obj2.getString("giftlist"); - if(transaction==null){ - transaction=getTransaction(); - } - transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, + transaction=getTransaction(); + contentFragment= LiveGiftFragment.newInstance(giftJson, liveGiftList.getJSONObject(0).getString("name"), - mStream, mLiveUid, mWishGiftId)); + mStream, mLiveUid, mWishGiftId); + transaction.replace(R.id.context_layout_gift,contentFragment); transaction.commitAllowingStateLoss(); } @@ -880,17 +881,17 @@ public class LiveGiftPopup extends AbsDialogFragment { */ @Subscribe(threadMode = ThreadMode.MAIN) public void onGiftTitleEvent(GiftTitleEvent event) { + liveWrap.setAlpha(0.5f); liveWrap.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL); liveGiftSend.setEnabled(false); giftNumberLayout.setVisibility(View.INVISIBLE); JSONObject obj2 = liveGiftList.getJSONObject(event.getmPosition()); String giftJson = obj2.getString("giftlist"); - if(transaction==null){ - transaction=getTransaction(); - } - transaction.replace(R.id.context_layout_gift, LiveGiftFragment.newInstance(giftJson, event.getGiftTitle(), mStream, mLiveUid, mWishGiftId)); - transaction.commit(); + transaction=getTransaction(); + contentFragment=LiveGiftFragment.newInstance(giftJson, event.getGiftTitle(), mStream, mLiveUid, mWishGiftId); + transaction.replace(R.id.context_layout_gift, contentFragment); + transaction.commitAllowingStateLoss(); isWrap = false; if (giftSendLayout.getVisibility() == View.INVISIBLE) { hideLianBtn(); @@ -1446,9 +1447,14 @@ public class LiveGiftPopup extends AbsDialogFragment { } } private FragmentTransaction getTransaction(){ - if(transaction==null){ - transaction=getChildFragmentManager().beginTransaction(); + if(contentFragment!=null && transaction!=null){ + transaction.remove(contentFragment); + contentFragment=null; } + if(fragmentManager==null){ + fragmentManager=getChildFragmentManager(); + } + transaction=fragmentManager.beginTransaction(); return transaction; }