From f151e203da870dbe281defcb1daf84a1a38ecac1 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期一, 29 十二月 2025 09:59:57 +0800
Subject: [PATCH] Merge branch 'master' into google
---
app/src/main/java/com/hdl/photovoltaic/ui/message/MessageHouseFragment.java | 361 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 361 insertions(+), 0 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageHouseFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageHouseFragment.java
new file mode 100644
index 0000000..2b1671f
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/MessageHouseFragment.java
@@ -0,0 +1,361 @@
+package com.hdl.photovoltaic.ui.message;
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+
+import com.google.gson.Gson;
+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.FragementMessageHouseBinding;
+import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
+import com.hdl.photovoltaic.enums.MessageStateType;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.other.HdlCommonLogic;
+import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.other.HdlMessageLogic;
+import com.hdl.photovoltaic.other.HdlThreadLogic;
+import com.hdl.photovoltaic.ui.adapter.MessageAdapter;
+import com.hdl.photovoltaic.ui.adapter.MessageHouseAdapter;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
+import com.hdl.photovoltaic.ui.bean.UnCountBean;
+import com.hdl.photovoltaic.ui.powerstation.HouseSearchActivity;
+import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils;
+import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout;
+import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder;
+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 MessageHouseFragment extends CustomBaseFragment {
+ private FragementMessageHouseBinding viewBinding;
+ private MessageHouseAdapter mMessageHouseAdapter;
+
+ private boolean isRead = true;
+
+ private final List<MessageBean> mList = new ArrayList<>();
+
+ @Override
+ public Object getContentView() {
+ viewBinding = FragementMessageHouseBinding.inflate(getLayoutInflater());
+ return viewBinding.getRoot();
+ }
+
+ @Override
+ public void onBindView(Bundle savedInstanceState) {
+ //鍒濆鍖栫晫闈�
+ initView();
+ //鍒濆鍖栫洃鍚櫒
+ initEvent();
+ //鍒濆鍖栨暟鎹�
+ initData(true);
+
+ }
+
+ /**
+ * 鑾峰彇璐﹀彿涓嬪叏閮ㄧ數绔欐秷鎭�
+ *
+ * @param homeName 鐢电珯鍚嶇О锛堟悳绱㈢敤鐨勶級,濡傛灉鏄┖瀛楃涓查粯璁よ鍙栧叏閮�
+ * @param isShowLoading 鏄惁闇�瑕佸姞杞界獥锛坱rue=闇�瑕侊紝false=涓嶉渶瑕侊級
+ */
+ private void getMessageHouseList(String homeName, boolean isShowLoading) {
+ if (isShowLoading) {
+ showLoading();
+ }
+ HdlMessageLogic.getInstance().getMessageHouseList(homeName, new CloudCallBeak<List<MessageBean>>() {
+ @Override
+ public void onSuccess(List<MessageBean> list) {
+ isRead = false;
+ if (isShowLoading) {
+ hideLoading();
+ }
+ mList.clear();
+ if (list != null && !list.isEmpty()) {
+ mList.addAll(list);
+ }
+ updateRecyclerViewList();
+
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+
+ if (isShowLoading) {
+ hideLoading();
+ }
+ }
+ });
+ }
+
+ /**
+ * 鑾峰彇璐﹀彿涓嬪叏閮ㄧ數绔欐秷鎭�
+ *
+ * @param homeId 娑堟伅id(涓嶄紶宸茶鎵�鏈夌數绔欑殑锛屼紶鍊煎凡璇绘寚瀹氱數绔欑殑)
+ * @param isShowLoading 鏄惁闇�瑕佸姞杞界獥锛坱rue=闇�瑕侊紝false=涓嶉渶瑕侊級
+ */
+ private void messageAllRead(String homeId, boolean isShowLoading) {
+ if (isShowLoading) {
+ showLoading();
+ }
+ HdlMessageLogic.getInstance().messageAllRead(homeId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ if (isShowLoading) {
+ hideLoading();
+ }
+ if (!mList.isEmpty()) {
+ for (int i = 0; i < mList.size(); i++) {
+ MessageBean messageBean = mList.get(i);
+ messageBean.setUnreadCount(0L);
+ }
+ updateRecyclerViewList();
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (isShowLoading) {
+ hideLoading();
+ }
+ }
+ });
+ }
+
+ /**
+ * 璇诲彇娑堟伅銆愭湭璇绘暟閲�,鏈鐞嗘�绘暟閲忥紝宸插鐞嗘�绘暟閲忋��
+ */
+ private void getUnreadCount() {
+ HdlMessageLogic.getInstance().getMessageUntreatedCount("", new CloudCallBeak<UnCountBean>() {
+ @Override
+ public void onSuccess(UnCountBean unCountBean) {
+
+ HdlThreadLogic.runMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (unCountBean == null) {
+ return;
+ }
+ refreshUnreadCount(unCountBean.getUnreadCount());
+ }
+
+ });
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ HdlThreadLogic.runMainThread(new Runnable() {
+ @Override
+ public void run() {
+ TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv);
+ if (textView != null) {
+ textView.setVisibility(View.GONE);
+ }
+ }
+ });
+ }
+ });
+ }
+
+ private void initData(boolean isShowLoading) {
+ this.getMessageHouseList("", isShowLoading);
+ this.getUnreadCount();
+ }
+
+ private void initEvent() {
+ //鎼滅储
+ viewBinding.powerStationSearchCl.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent();
+ intent.setClass(_mActivity, SearchMessageHouseActivity.class);
+ startActivity(intent);
+ }
+ });
+ //鍏ㄩ儴宸茶
+ viewBinding.powerStationReadIv.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ messageAllRead("", true);
+ refreshUnreadCount(0);
+ }
+ });
+
+ if (mMessageHouseAdapter != null) {
+ mMessageHouseAdapter.setOnclickListener(new MessageHouseAdapter.OnClickListener() {
+ @Override
+ public void onClick(int position, MessageBean messageBean) {
+ Intent intent = new Intent();
+ intent.putExtra("messageBean", new Gson().toJson(messageBean));
+ intent.setClass(_mActivity, MessageActivity.class);
+ startActivity(intent);
+ }
+ });
+
+ }
+ }
+
+ /**
+ * 閲嶆柊鏇存柊鍒楄〃鏁版嵁
+ */
+ private void updateRecyclerViewList() {
+ if (mMessageHouseAdapter == null) {
+ return;
+ }
+ mMessageHouseAdapter.setList(mList);
+ nullDataUpdateUi();
+ }
+
+ /**
+ * 鍒锋柊銆愭秷鎭ā鍧椼�戜笅瑙掓爣鏁板��
+ *
+ * @param unreadCount 鏈淇℃伅鏁伴噺鎬绘暟
+ */
+ private void refreshUnreadCount(int unreadCount) {
+ HdlThreadLogic.runMainThread(new Runnable() {
+ @SuppressLint("SetTextI18n")
+ @Override
+ public void run() {
+ TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv);
+ if (textView != null) {
+ if (unreadCount == 0) {
+ textView.setVisibility(View.GONE);
+ } else {
+ textView.setVisibility(View.VISIBLE);
+ if (unreadCount > 99) {
+ textView.setText("99+");
+ } else {
+ textView.setText(unreadCount + "");
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * 娌℃湁娑堟伅鍒楄〃鐨勬牱寮�
+ */
+ private void nullDataUpdateUi() {
+ HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.deviceNullDataIc.getRoot(), viewBinding.deviceNullDataIc.nullDataGifAnimationIv, viewBinding.deviceNullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0);
+ }
+
+ private void initView() {
+ mMessageHouseAdapter = new MessageHouseAdapter(_mActivity);
+ viewBinding.houseListRcv.setLayoutManager(new LinearLayoutManager(_mActivity));
+ viewBinding.houseListRcv.setAdapter(mMessageHouseAdapter);
+ this.pullToRefresh();
+
+ }
+
+ /**
+ * 涓嬫媺鍒锋柊鐨勯�昏緫
+ */
+ protected void pullToRefresh() {
+ viewBinding.houseListRbl.setDelegate(new BGARefreshLayout.BGARefreshLayoutDelegate() {
+ @SuppressLint("StaticFieldLeak")
+ @Override
+ public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
+ new AsyncTask<Void, Void, Void>() {
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ // 鎵ц浠诲姟锛堝鏇存柊UI銆佽烦杞瓑锛�
+ viewBinding.houseListRbl.endRefreshing();
+ initData(false);
+
+ }
+ }.execute();
+
+
+ }
+
+
+ @SuppressLint("StaticFieldLeak")
+ @Override
+ public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ viewBinding.houseListRbl.endLoadingMore();
+ //鍔犺浇鏈�鏂版暟鎹畬鎴�
+ }
+ }.execute();
+ return true;
+ }
+ });
+ HDLRefreshViewHolder hdlRefreshViewHolder = new HDLRefreshViewHolder(_mActivity, true);
+ hdlRefreshViewHolder.setPullDownImageResource(R.mipmap.loading_44);
+ hdlRefreshViewHolder.setChangeToReleaseRefreshAnimResId(R.drawable.loading_refresh);
+ hdlRefreshViewHolder.setRefreshingAnimResId(R.drawable.loading_refresh_end);
+ viewBinding.houseListRbl.setRefreshViewHolder(hdlRefreshViewHolder);
+ }
+
+ @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);
+ HdlLogLogic.print("姝e湪鐐瑰嚮銆愭秷鎭��");
+ if (!isRead) {
+ //绗簩娆¤繘鏉ヤ笉鏄剧ず鍔犺浇妗�
+ initData(false);
+ }
+
+ }
+ } else if (eventBus.getTopic().equals(ConstantManage.refresh_message_house)) {
+ // 鍙栨秷绮樻�т簨浠�
+ EventBus.getDefault().removeStickyEvent(eventBus);
+ //绗簩娆¤繘鏉ヤ笉鏄剧ず鍔犺浇妗�
+ initData(false);
+
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+}
--
Gitblit v1.8.0