From a0e8f81afc4fe2a21a5c504d53e569ea50d463d6 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期五, 15 三月 2024 11:51:23 +0800 Subject: [PATCH] 2024年03月15日11:51:17 --- app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java | 179 ++++++++++++++++++++++++++++------------------------------- 1 files changed, 84 insertions(+), 95 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 7f8b76f..1417088 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,12 +1,10 @@ package com.hdl.photovoltaic.ui.message; +import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.text.TextUtils; -import android.util.Log; -import android.view.MotionEvent; import android.view.View; import android.widget.TextView; @@ -30,9 +28,7 @@ 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.HouseIdBean; import com.hdl.photovoltaic.ui.bean.MessageBean; -import com.hdl.photovoltaic.utils.GlideUtils; import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; import org.greenrobot.eventbus.EventBus; @@ -40,7 +36,6 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -53,7 +48,8 @@ private final List<MessageBean> mList = new ArrayList<>(); private int currentPage = 0; // 褰撳墠椤电爜 - private int total = 0; // 鏈�鍚庨〉鐮� + private int currentTotal = 0; // 鎬婚〉鐮� + private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁 @@ -67,18 +63,14 @@ @Override public void onBindView(Bundle savedInstanceState) { - //鍒濆鍖栨暟鎹� -// initData(); //鍒濆鍖栫晫闈� initView(); //鍒濆鍖栫洃鍚櫒 initEvent(); + //杩涙潵璇诲彇涓�娆℃暟鎹�(涓轰簡鏇存柊currentPage锛宑urrentTotal杩欎釜鍊�) + loadNextPageNascentMessageList(1, true); } - private void initData() { - mList.clear(); - mList.addAll(HdlMessageLogic.getInstance().getNascentMessageMemoryList()); - } private void initEvent() { //璁剧疆涓嬫媺绠ご棰滆壊 @@ -87,9 +79,9 @@ @Override public void onRefresh() { viewBinding.messageNascentSrl.setRefreshing(false); -// mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 -// updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; -// getNascentMessageList(false); + mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰绗竴椤垫秷鎭垪琛� + HdlMessageLogic.getInstance().clearListMessage();//琛ㄧず寮哄埗娓呯┖鎵�鏈夌紦瀛樹俊鎭� + loadNextPageNascentMessageList(1, true); } }); messageNascentAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { @@ -143,19 +135,18 @@ HdlThreadLogic.runMainThread(new Runnable() { @Override public void run() { - //鏇存柊缂撳瓨鏁版嵁 - initData(); + //鏇存柊鏈湴缂撳瓨鏁版嵁 + updatelocalityCacheData(); //鍒锋柊鍒楄〃 if (messageNascentAdapter != null) { messageNascentAdapter.setList(mList); messageNascentAdapter.notifyDataSetChanged(); } - //鏄剧ず鍙戠敓涓秷鎭�绘暟閲� - refreshNascentCount(); - //鏄剧ず娌℃暟鎹甎i鏍峰紡 - nullDataUpdateUi(); //鏄剧ず鏈淇℃伅鎬绘暟閲� getUnreadCount(); + //鏄剧ず娌℃暟鎹甎i鏍峰紡 + nullDataUpdateUi(); + } }); } @@ -163,16 +154,41 @@ /** * 鍒锋柊銆愬彂鐢熶腑銆戜俊鎭暟閲忔�绘暟 */ - private void refreshNascentCount() { + private void refreshNascentCount(String totalCount) { HdlThreadLogic.runMainThread(new Runnable() { @Override public void run() { TextView textView = _mActivity.findViewById(R.id.message_tab_nascent_title_tv); if (textView != null) { textView.setText(getText(R.string.message_nascent)); - if (mList.size() > 0) { - String s = getText(R.string.message_nascent) + "(" + mList.size() + ")"; + if (!TextUtils.isEmpty(totalCount) && !totalCount.equals("0")) { + String s = getText(R.string.message_nascent) + "(" + totalCount + ")"; textView.setText(s); + } + } + } + }); + } + + /** + * 鍒锋柊瑙掓爣銆愭湭璇汇�戜俊鎭暟閲忔�绘暟 + */ + private void refreshUnreadNascentCount(String 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 (TextUtils.isEmpty(unreadCount) || unreadCount.equals("0")) { + textView.setVisibility(View.GONE); + } else { + textView.setVisibility(View.VISIBLE); + if (unreadCount.length() > 2) { + textView.setText("99+"); + } else { + textView.setText(unreadCount); + } } } } @@ -188,9 +204,6 @@ //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢 if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) { if (eventBus.getType().equals(MessageFunctionTabSwitch.nascent.toString())) { - initData(); - loadNextPageNascentMessageList(1, true); -// getUnreadCount(); // 鍙栨秷绮樻�т簨浠� EventBus.getDefault().removeStickyEvent(eventBus); @@ -199,11 +212,18 @@ } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { if (eventBus.getType().equals(MessageStateType.untreated)) { //娑堟伅璇︽儏鍥炶皟 - initData(); + updatelocalityCacheData(); updateListData(); -// getUnreadCount(); } } + } + + /** + * 鏇存柊鏈湴缂撳瓨鏁版嵁 + */ + private void updatelocalityCacheData() { + mList.clear(); + mList.addAll(HdlMessageLogic.getInstance().getNascentMessageMemoryList()); } /** @@ -213,11 +233,9 @@ * @param isShowLoading 鏄惁鍚姩鍔犺浇妗� true鍚姩 */ private void loadNextPageNascentMessageList(int pageNo, boolean isShowLoading) { - if (pageNo == 1 && mList.size() > 0) { - //娌℃湁缂撳瓨鏁版嵁,鎵嶅彲浠ヨ鍙栫涓�椤� - return; - } - if (currentPage > total) { + //绗竴椤佃鍙栨暟鎹己鍒惰 + if (pageNo > 1 && currentPage > currentTotal) { + --currentPage; //褰撳墠椤典笉鑳藉ぇ浜庢�婚〉鏁� return; } @@ -229,7 +247,7 @@ @Override public void onSuccess(HdlMessageLogic.MessageListClass messageListClass) { if (messageListClass != null) { - total = (int) messageListClass.getTotalPage(); + currentTotal = (int) messageListClass.getTotalPage(); currentPage = (int) messageListClass.getPageNo(); updateListData(); } @@ -256,66 +274,37 @@ * 璇诲彇娑堟伅銆愭湭璇绘暟閲忋�� */ private void getUnreadCount() { - String untreatedMemoryCount = HdlMessageLogic.getInstance().getMessageUntreatedMemoryCount(); - TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv); - if (textView != null) { - if (TextUtils.isEmpty(untreatedMemoryCount) || untreatedMemoryCount.equals("0")) { - textView.setVisibility(View.GONE); - } else { - if (untreatedMemoryCount.length() > 2) { - //澶т簬3浣嶆暟,榛樿99+ - untreatedMemoryCount = "99+"; - } - textView.setVisibility(View.VISIBLE); - textView.setText(untreatedMemoryCount); + HdlMessageLogic.getInstance().getMessageUntreatedCount("",new CloudCallBeak<String>() { + @Override + public void onSuccess(String data) { + + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + JSONObject jsonObject = JSON.parseObject(data); + if (jsonObject.containsKey("untreatedCount")) { + //鏈鐞嗘暟閲� + String untreatedCount = jsonObject.getString("untreatedCount"); + refreshNascentCount(untreatedCount); + } + if (jsonObject.containsKey("unreadCount")) { + //鏈鏁伴噺 + String unreadCount = jsonObject.getString("unreadCount"); + refreshUnreadNascentCount(unreadCount); + } + } + }); + } - } -// -// HdlMessageLogic.getInstance().getMessageUntreatedCount(new CloudCallBeak<String>() { -// @Override -// public void onSuccess(String data) { -// -// HdlThreadLogic.runMainThread(new Runnable() { -// @Override -// public void run() { -// JSONObject jsonObject = JSON.parseObject(data); -//// if (jsonObject.containsKey("untreatedCount")) { -//// //鏈鐞嗘暟閲� -//// jsonObject.getString("untreatedCount"); -//// } -// String unreadCount = "0"; -// if (jsonObject.containsKey("unreadCount")) { -// //鏈鏁伴噺 -// unreadCount = jsonObject.getString("unreadCount"); -// } -// TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv); -// if (textView != null) { -// if (TextUtils.isEmpty(unreadCount) || unreadCount.equals("0")) { -// textView.setVisibility(View.GONE); -// } else { -// if (unreadCount.length() > 2) { -// //澶т簬3浣嶆暟,榛樿99+ -// unreadCount = "99+"; -// } -// textView.setVisibility(View.VISIBLE); -// textView.setText(unreadCount); -// } -// -// -// } -// } -// }); -// -// } -// -// @Override -// public void onFailure(HDLException e) { -// TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv); -// if (textView != null) { -// textView.setVisibility(View.GONE); -// } -// } -// }); + + @Override + public void onFailure(HDLException e) { + TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv); + if (textView != null) { + textView.setVisibility(View.GONE); + } + } + }); } -- Gitblit v1.8.0