| | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | |
| | | private MessageAdapter messageNascentAdapter; |
| | | |
| | | private final List<MessageBean> mList = new ArrayList<>(); |
| | | |
| | | // 添加上拉加载更多的逻辑 |
| | | private int visibleThreshold = 5; // 当前显示的最后一项与总共有多少条数据之间的差值 |
| | | private int currentPage = 1; // 当前页码 |
| | | private boolean isLoadingMore = false; // 标记正在加载更多数据 |
| | | |
| | | LinearLayoutManager layoutManager; |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | |
| | | } |
| | | }); |
| | | viewBinding.messageNascentRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| | | @Override |
| | | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| | | super.onScrolled(recyclerView, dx, dy); |
| | | |
| | | // int totalItemCount = layoutManager.getItemCount(); |
| | | // int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); |
| | | // |
| | | // if (!isLoadingMore && totalItemCount <= (lastVisibleItemPosition + visibleThreshold)) { |
| | | // loadNextPage(); |
| | | // } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.messageNascentRecyclerview.setLayoutManager(new LinearLayoutManager(_mActivity)); |
| | | layoutManager = new LinearLayoutManager(_mActivity); |
| | | viewBinding.messageNascentRecyclerview.setLayoutManager(layoutManager); |
| | | messageNascentAdapter = new MessageAdapter(this.mList, _mActivity); |
| | | viewBinding.messageNascentRecyclerview.setAdapter(messageNascentAdapter); |
| | | } |
| | |
| | | @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | super.onEventMessage(eventBus); |
| | | if (eventBus == null) { |
| | | return; |
| | | } |
| | | //接收外部点击事件 |
| | | if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) { |
| | | if (eventBus.getType().equals(MessageFunctionTabSwitch.nascent.toString())) { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 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; |
| | | // } |
| | | } |