mac
2024-01-08 53cfbb7c949edc8e3d0b624e251afbad1a1c74ca
app/src/main/java/com/hdl/photovoltaic/ui/message/MessageFragment.java
@@ -15,12 +15,16 @@
import com.hdl.photovoltaic.databinding.FragmentMessageBinding;
import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch;
import com.hdl.photovoltaic.enums.MessageStateType;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlMessageLogic;
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;
@@ -67,6 +71,7 @@
                currentIndex = 0;
                initView();
                showFragment();
                postEventBus(MessageFunctionTabSwitch.nascent);
            }
        });
@@ -77,6 +82,7 @@
                currentIndex = 1;
                initView();
                showFragment();
                postEventBus(MessageFunctionTabSwitch.recover);
            }
        });
@@ -88,6 +94,7 @@
                currentIndex = 2;
                initView();
                showFragment();
                postEventBus(MessageFunctionTabSwitch.all);
            }
        });
    }
@@ -116,6 +123,7 @@
            viewBinding.line2V.setVisibility(View.GONE);
            viewBinding.line3V.setVisibility(View.VISIBLE);
        }
    }
    private void initData() {
@@ -130,7 +138,8 @@
        BaseEventBus baseEventBus = new BaseEventBus();
        baseEventBus.setTopic(ConstantManage.message_function_tab_switch);
        baseEventBus.setType(tabSwitch.toString());
        EventBus.getDefault().post(baseEventBus);
        //发送粘性事件(如果不发粘性事件会遇到一个没有加载出来的碎片接收不到信息)
        EventBus.getDefault().postSticky(baseEventBus);
    }
@@ -183,13 +192,6 @@
        //把当前显示的fragment记录下来
        currentFragment = fragmentList.get(currentIndex);
        if (this.currentIndex == 0) {
            postEventBus(MessageFunctionTabSwitch.nascent);
        } else if (this.currentIndex == 1) {
            postEventBus(MessageFunctionTabSwitch.recover);
        } else if (this.currentIndex == 2) {
            postEventBus(MessageFunctionTabSwitch.all);
        }
    }
@@ -209,16 +211,28 @@
    }
    @Override
    @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("正在点击【消息】");
            }
        } else if (eventBus.getTopic().equals(ConstantManage.message_count)) {
            if (eventBus.getType().equals(MessageStateType.untreated)) {
                String s = getText(R.string.message_nascent) + "(" + HdlMessageLogic.getInstance().getNascentMessageMemoryList().size() + ")";
                viewBinding.messageTabNascentTitleTv.setText(s);
            } else if (eventBus.getType().equals(MessageStateType.processed)) {
                String s = getText(R.string.message_recover) + "(" + HdlMessageLogic.getInstance().getRecoverMessageMemoryList().size() + ")";
                viewBinding.messageTabRecoverTitleTv.setText(s);
            }
        }
    }