From 592ad3b6524ff524c999674b272a653ef062780e Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 30 一月 2024 13:47:17 +0800 Subject: [PATCH] 2024年01月30日13:47:09 --- app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java | 284 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 142 insertions(+), 142 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 e672fd4..016b4c4 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 @@ -5,6 +5,7 @@ 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; @@ -39,6 +40,7 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -50,10 +52,9 @@ private MessageAdapter messageNascentAdapter; private final List<MessageBean> mList = new ArrayList<>(); + private int currentPage = 0; // 褰撳墠椤电爜 + private int total = 0; // 鏈�鍚庨〉鐮� - // 娣诲姞涓婃媺鍔犺浇鏇村鐨勯�昏緫 - private int visibleThreshold = 5; // 褰撳墠鏄剧ず鐨勬渶鍚庝竴椤逛笌鎬诲叡鏈夊灏戞潯鏁版嵁涔嬮棿鐨勫樊鍊� - private int currentPage = 1; // 褰撳墠椤电爜 private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁 LinearLayoutManager layoutManager; @@ -85,9 +86,10 @@ viewBinding.messageNascentSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 - updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; - getNascentMessageList(false); + viewBinding.messageNascentSrl.setRefreshing(false); +// mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 +// updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; +// getNascentMessageList(false); } }); messageNascentAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { @@ -107,25 +109,22 @@ viewBinding.messageNascentRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); +// super.onScrolled(recyclerView, dx, dy); -// if (dy <= 0) { -// //绛変簬0鏄《閮� -// return; -// } -// LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); -// assert layoutManager != null; -// // 鍙湁鍨傜洿甯冨眬鎵嶄細瑙﹀彂涓婃媺浜嬩欢 -// if (!layoutManager.canScrollVertically()) { -// return; -// } -// -// int totalItemCount = layoutManager.getItemCount(); -// int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); -// -// if (!isLoadingMore && totalItemCount <= (lastVisibleItemPosition + visibleThreshold)) { -//// loadNextPage(); -// } + LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); + if (layoutManager == null) { + return; + } + int visibleItemCount = layoutManager.getChildCount(); + int totalItemCount = layoutManager.getItemCount(); + int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); + if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { + if (!isLoadingMore) { + // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔 + HdlLogLogic.print("--->婊戝姩鍒颁簡搴曢儴"); + loadNextPageNascentMessageList(++currentPage, false); + } + } } }); } @@ -141,15 +140,24 @@ * 鍒锋柊鍒楄〃鏁版嵁 */ private void updateListData() { - if (this.messageNascentAdapter != null) { - this.messageNascentAdapter.setList(mList); - this.messageNascentAdapter.notifyDataSetChanged(); - } - //鍒锋柊銆愬彂鐢熶腑銆戜俊鎭暟閲忔�绘暟 - this.refreshNascentCount(); - this.nullDataUpdateUi(); - - + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + //鏇存柊缂撳瓨鏁版嵁 + initData(); + //鍒锋柊鍒楄〃 + if (messageNascentAdapter != null) { + messageNascentAdapter.setList(mList); + messageNascentAdapter.notifyDataSetChanged(); + } + //鏄剧ず鍙戠敓涓秷鎭�绘暟閲� + refreshNascentCount(); + //鏄剧ず娌℃暟鎹甎i鏍峰紡 + nullDataUpdateUi(); + //鏄剧ず鏈淇℃伅鎬绘暟閲� + getUnreadCount(); + } + }); } /** @@ -181,8 +189,8 @@ if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) { if (eventBus.getType().equals(MessageFunctionTabSwitch.nascent.toString())) { initData(); - getNascentMessageList(true); - getUnreadCount(); + loadNextPageNascentMessageList(1, true); +// getUnreadCount(); // 鍙栨秷绮樻�т簨浠� EventBus.getDefault().removeStickyEvent(eventBus); @@ -193,126 +201,121 @@ //娑堟伅璇︽儏鍥炶皟 initData(); updateListData(); - getUnreadCount(); +// getUnreadCount(); } } } /** - * 鑾峰彇鍙戠敓涓殑娑堟伅鍒楄〃 + * 鍔犺浇涓�椤垫暟鎹� * + * @param pageNo 椤垫暟 * @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(); - } else { - nullDataUpdateUi(); - } - } - }); - - } - - @Override - public void onFailure(HDLException e) { - if (isShowLoading) { - hideLoading(); - } - if (!isShowLoading) { - viewBinding.messageNascentSrl.setRefreshing(false); - } - } - }); + private void loadNextPageNascentMessageList(int pageNo, boolean isShowLoading) { + if (pageNo == 1 && mList.size() > 0) { + //缂撳瓨鏁版嵁娌℃湁鎵嶅彲浠ヨ鍙栫涓�椤� + return; } - } + if (currentPage > total) { + //褰撳墠椤典笉鑳藉ぇ浜庢�婚〉鏁� + return; + } + isLoadingMore = true;//鏍囪璇诲彇鐘舵�� + if (isShowLoading) { + showLoading(); + } + HdlMessageLogic.getInstance().getPageNoMessageList(pageNo, MessageStateType.untreated, new CloudCallBeak<HdlMessageLogic.MessageListClass>() { + @Override + public void onSuccess(HdlMessageLogic.MessageListClass messageListClass) { + if (messageListClass != null) { + total = (int) messageListClass.getTotalPage(); + currentPage = (int) messageListClass.getPageNo(); + updateListData(); + } + isLoadingMore = false; + if (isShowLoading) { + hideLoading(); + } + } -// private void loadNextPage() { -// isLoadingMore = true; -// -// // 妯℃嫙缃戠粶璇锋眰鑾峰彇鏂扮殑鏁版嵁 -// Handler handler = new Handler(); -// handler.postDelayed(() -> { -// List<MessageBean> newData = fetchNewDataFromServer(currentPage++); -// messageNascentAdapter.setList(newData); -// isLoadingMore = false; -// }, 2000); -// } -// -// private List<MessageBean> fetchNewDataFromServer(int pageNumber) { -// // TODO: 浠庢湇鍔″櫒鑾峰彇鏂扮殑鏁版嵁骞惰繑鍥� -// pageNumber++; -// List<MessageBean> newData = HdlMessageLogic.getInstance().getAllMessageList(); -// return newData; -// } + @Override + public void onFailure(HDLException e) { + if (currentPage > 1) { + --currentPage; + } + isLoadingMore = false; + if (isShowLoading) { + hideLoading(); + } + } + }); + } /** * 璇诲彇娑堟伅銆愭湭璇绘暟閲忋�� */ private void getUnreadCount() { - 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); + 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")) { +//// //鏈鐞嗘暟閲� +//// 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); +// } +// } +// }); } @@ -320,9 +323,6 @@ * 娌℃湁鐢电珯鍒楄〃鐨勬牱寮� */ private void nullDataUpdateUi() { - HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, - viewBinding.nullDataIc.getRoot(), - viewBinding.nullDataIc.nullDataGifAnimationIv, - viewBinding.nullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0); + HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.nullDataIc.getRoot(), viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0); } } -- Gitblit v1.8.0