From ecaff4ffd05c630ac32e49daf3b9b8904052b0fe Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期五, 29 十二月 2023 15:16:07 +0800 Subject: [PATCH] 备份一下 --- app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java | 150 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 149 insertions(+), 1 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java index 9753060..1568045 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java @@ -1,21 +1,169 @@ package com.hdl.photovoltaic.ui.message; +import android.content.Intent; import android.os.Bundle; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import com.hdl.linkpm.sdk.core.exception.HDLException; +import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.base.CustomBaseFragment; +import com.hdl.photovoltaic.config.ConstantManage; +import com.hdl.photovoltaic.databinding.FragmentNascentMessageBinding; +import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch; +import com.hdl.photovoltaic.enums.MessageStateType; +import com.hdl.photovoltaic.listener.CloudCallBeak; +import com.hdl.photovoltaic.other.HdlMessageLogic; +import com.hdl.photovoltaic.other.HdlThreadLogic; +import com.hdl.photovoltaic.ui.adapter.MessageAdapter; +import com.hdl.photovoltaic.ui.bean.MessageBean; +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; /** * 娑堟伅-鍙戠敓涓� */ public class NascentMessageFragment extends CustomBaseFragment { + private FragmentNascentMessageBinding viewBinding; + + private MessageAdapter messageNascentAdapter; + + private final List<MessageBean> mList = new ArrayList<>(); + @Override public Object getContentView() { - return null; + viewBinding = FragmentNascentMessageBinding.inflate(getLayoutInflater()); + return viewBinding.getRoot(); } @Override public void onBindView(Bundle savedInstanceState) { + //鍒濆鍖栨暟鎹� +// initData(); + //鍒濆鍖栫晫闈� + initView(); + //鍒濆鍖栫洃鍚櫒 + initEvent(); + } + private void initData() { + mList.clear(); + mList.addAll(HdlMessageLogic.getInstance().getNascentMessageMemoryList()); + } + + private void initEvent() { + //璁剧疆涓嬫媺绠ご棰滆壊 + viewBinding.messageNascentSrl.setColorSchemeResources(R.color.text_FF245EC3); + viewBinding.messageNascentSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 + updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; + getNascentMessageList(false); + } + }); + messageNascentAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { + @Override + public void onClick(int position, MessageBean item) { + if (position < 0 || position > mList.size()) { + return; + } + Intent intent = new Intent(); + intent.putExtra("msgId", item.getMsgId().toString()); + intent.setClass(_mActivity, MessageInfoActivity.class); + startActivity(intent); + + } + }); + } + + private void initView() { + viewBinding.messageNascentRecyclerview.setLayoutManager(new LinearLayoutManager(_mActivity)); + messageNascentAdapter = new MessageAdapter(this.mList, _mActivity); + viewBinding.messageNascentRecyclerview.setAdapter(messageNascentAdapter); + } + + /** + * 鍒锋柊鍒楄〃鏁版嵁 + */ + private void updateListData() { + if (this.messageNascentAdapter != null) { + this.messageNascentAdapter.setList(mList); + this.messageNascentAdapter.notifyDataSetChanged(); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) + public void onEventMessage(BaseEventBus eventBus) { + super.onEventMessage(eventBus); + //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢 + if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) { + if (eventBus.getType().equals(MessageFunctionTabSwitch.nascent.toString())) { + initData(); + getNascentMessageList(true); + // 鍙栨秷绮樻�т簨浠� + EventBus.getDefault().removeStickyEvent(eventBus); + } + + } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { + if (eventBus.getType().equals(MessageStateType.untreated)) { + //娑堟伅璇︽儏鍥炶皟 + initData(); + updateListData(); + } + } + } + + /** + * 鑾峰彇鍙戠敓涓殑娑堟伅鍒楄〃 + * + * @param isShowLoading 鏄惁鍚姩 true鍚姩 + */ + private void getNascentMessageList(boolean isShowLoading) { + if (mList.size() == 0) { + if (isShowLoading) { + showLoading(); + } + HdlMessageLogic.getInstance().getNascentMessageList(new CloudCallBeak<List<MessageBean>>() { + @Override + public void onSuccess(List<MessageBean> list) { + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + if (isShowLoading) { + hideLoading(); + } + if (!isShowLoading) { + viewBinding.messageNascentSrl.setRefreshing(false); + } + + if (list != null && list.size() != 0) { + mList.addAll(list); + updateListData(); + } + } + }); + + } + + @Override + public void onFailure(HDLException e) { + if (isShowLoading) { + hideLoading(); + } + if (!isShowLoading) { + viewBinding.messageNascentSrl.setRefreshing(false); + } + } + }); + } } } -- Gitblit v1.8.0