From a034e242fe844a1ca45d2a28710cb7face1f8fe6 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期日, 28 四月 2024 19:07:56 +0800 Subject: [PATCH] 2024年04月28日19:07:49 --- app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java | 85 ++++++++++++++++++++++++++---------------- 1 files changed, 53 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java index 9585d2a..ea34e28 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java @@ -12,10 +12,14 @@ import com.hdl.photovoltaic.base.CustomBaseFragment; import com.hdl.photovoltaic.config.ConstantManage; import com.hdl.photovoltaic.databinding.FragmentMessageBinding; -import com.hdl.photovoltaic.other.HdlCommonLogic; +import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; +import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch; +import com.hdl.photovoltaic.other.HdlLogLogic; import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.List; @@ -60,8 +64,9 @@ @Override public void onClick(View v) { currentIndex = 0; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.nascent); } }); @@ -70,8 +75,9 @@ @Override public void onClick(View v) { currentIndex = 1; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.recover); } }); @@ -81,8 +87,9 @@ @Override public void onClick(View v) { currentIndex = 2; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.all); } }); } @@ -90,30 +97,28 @@ private void initView() { if (this.currentIndex == 0) { - viewBinding.messageTabAllTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); viewBinding.messageTabNascentTitleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null)); viewBinding.messageTabRecoverTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); - viewBinding.line1V.setVisibility(View.GONE); - viewBinding.line2V.setVisibility(View.VISIBLE); - viewBinding.line3V.setVisibility(View.GONE); - postEventBus(HdlCommonLogic.MessageFunctionTabSwitch.nascent); - } else if (this.currentIndex == 1) { viewBinding.messageTabAllTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); - viewBinding.messageTabNascentTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); - viewBinding.messageTabRecoverTitleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null)); - viewBinding.line1V.setVisibility(View.GONE); - viewBinding.line2V.setVisibility(View.GONE); - viewBinding.line3V.setVisibility(View.VISIBLE); - postEventBus(HdlCommonLogic.MessageFunctionTabSwitch.recover); - } else if (this.currentIndex == 2) { - viewBinding.messageTabAllTitleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null)); - viewBinding.messageTabNascentTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); - viewBinding.messageTabRecoverTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); viewBinding.line1V.setVisibility(View.VISIBLE); viewBinding.line2V.setVisibility(View.GONE); viewBinding.line3V.setVisibility(View.GONE); - postEventBus(HdlCommonLogic.MessageFunctionTabSwitch.all); + } else if (this.currentIndex == 1) { + viewBinding.messageTabNascentTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); + viewBinding.messageTabRecoverTitleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null)); + viewBinding.messageTabAllTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); + viewBinding.line1V.setVisibility(View.GONE); + viewBinding.line2V.setVisibility(View.VISIBLE); + viewBinding.line3V.setVisibility(View.GONE); + } else if (this.currentIndex == 2) { + viewBinding.messageTabNascentTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); + viewBinding.messageTabRecoverTitleTv.setTextColor(getResources().getColor(R.color.text80_FFFFFF, null)); + viewBinding.messageTabAllTitleTv.setTextColor(getResources().getColor(R.color.text_FFFFFFFF, null)); + viewBinding.line1V.setVisibility(View.GONE); + viewBinding.line2V.setVisibility(View.GONE); + viewBinding.line3V.setVisibility(View.VISIBLE); } + } private void initData() { @@ -124,11 +129,12 @@ * * @param tabSwitch - */ - private void postEventBus(HdlCommonLogic.MessageFunctionTabSwitch tabSwitch) { + private void postEventBus(MessageFunctionTabSwitch tabSwitch) { BaseEventBus baseEventBus = new BaseEventBus(); baseEventBus.setTopic(ConstantManage.message_function_tab_switch); - baseEventBus.setType(tabSwitch + ""); - EventBus.getDefault().post(baseEventBus); + baseEventBus.setType(tabSwitch.toString()); + //鍙戦�佺矘鎬т簨浠�(濡傛灉涓嶅彂绮樻�т簨浠朵細閬囧埌涓�涓病鏈夊姞杞藉嚭鏉ョ殑纰庣墖鎺ユ敹涓嶅埌淇℃伅) + EventBus.getDefault().postSticky(baseEventBus); } @@ -159,8 +165,6 @@ fragmentList.add(mRecoverMessageFragment); fragmentList.add(mAllMessageFragment); showFragment(); - - } } @@ -174,14 +178,16 @@ //濡傛灉涔嬪墠娌℃湁娣诲姞杩� if (!fragmentList.get(currentIndex).isAdded()) { //绗笁涓弬鏁颁负娣诲姞褰撳墠鐨刦ragment鏃剁粦瀹氫竴涓猼ag - ft.hide(currentFragment) - .add(R.id.message_fcv, fragmentList.get(currentIndex), currentIndex + ""); + ft.hide(currentFragment).add(R.id.message_fcv, fragmentList.get(currentIndex), currentIndex + ""); } else { - ft.hide(currentFragment) - .show(fragmentList.get(currentIndex)); + ft.hide(currentFragment).show(fragmentList.get(currentIndex)); } currentFragment = fragmentList.get(currentIndex); ft.commit(); + //鎶婂綋鍓嶆樉绀虹殑fragment璁板綍涓嬫潵 + currentFragment = fragmentList.get(currentIndex); + + } /** @@ -197,9 +203,24 @@ } } ft.commit(); - //鎶婂綋鍓嶆樉绀虹殑fragment璁板綍涓嬫潵 - currentFragment = fragmentList.get(currentIndex); + } + @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) + public void onEventMessage(BaseEventBus eventBus) { + super.onEventMessage(eventBus); + if (eventBus == null) { + return; + } + //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢 + if (eventBus.getTopic().equals(ConstantManage.homepage_title_tab_switch)) { + if (eventBus.getType().equals(HomepageTitleTabSwitch.message.toString())) { + // 鍙栨秷绮樻�т簨浠� + EventBus.getDefault().removeStickyEvent(eventBus); + postEventBus(MessageFunctionTabSwitch.nascent); + HdlLogLogic.print("姝e湪鐐瑰嚮銆愭秷鎭��"); + } + } + } } -- Gitblit v1.8.0