From d1ebb94e1a17b7c25d4fcf73d85345d92cc86b5c Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 02 一月 2024 18:41:34 +0800 Subject: [PATCH] 2024年01月02日18:41:32 --- app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java | 85 +++++++++++++++++++++++++++--------------- 1 files changed, 55 insertions(+), 30 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 11770e3..026dfa0 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 @@ -1,6 +1,7 @@ package com.hdl.photovoltaic.ui.message; import android.os.Bundle; +import android.os.SystemClock; import android.view.View; @@ -12,11 +13,16 @@ import com.hdl.photovoltaic.base.CustomBaseFragment; import com.hdl.photovoltaic.config.ConstantManage; import com.hdl.photovoltaic.databinding.FragmentMessageBinding; +import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch; import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch; import com.hdl.photovoltaic.other.HdlCommonLogic; +import com.hdl.photovoltaic.other.HdlLogLogic; +import com.hdl.photovoltaic.ui.bean.BUserInfo; 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; @@ -61,8 +67,9 @@ @Override public void onClick(View v) { currentIndex = 0; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.nascent); } }); @@ -71,8 +78,9 @@ @Override public void onClick(View v) { currentIndex = 1; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.recover); } }); @@ -82,8 +90,9 @@ @Override public void onClick(View v) { currentIndex = 2; - showFragment(); initView(); + showFragment(); + postEventBus(MessageFunctionTabSwitch.all); } }); } @@ -91,30 +100,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(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(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(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() { @@ -128,8 +135,9 @@ 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); } @@ -160,8 +168,6 @@ fragmentList.add(mRecoverMessageFragment); fragmentList.add(mAllMessageFragment); showFragment(); - - } } @@ -175,14 +181,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); + + } /** @@ -198,8 +206,25 @@ } } 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())) { + postEventBus(MessageFunctionTabSwitch.nascent); + HdlLogLogic.print("姝e湪鐐瑰嚮銆愭秷鎭��"); + // 鍙栨秷绮樻�т簨浠� + EventBus.getDefault().removeStickyEvent(eventBus); + + } + } } -- Gitblit v1.8.0