mac
2024-03-15 a0e8f81afc4fe2a21a5c504d53e569ea50d463d6
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; // 标记正在加载更多数据
@@ -67,18 +63,14 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
        //初始化数据
//        initData();
        //初始化界面
        initView();
        //初始化监听器
        initEvent();
        //进来读取一次数据(为了更新currentPage,currentTotal这个值)
        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();
                //显示没数据Ui样式
                nullDataUpdateUi();
                //显示未读信息总数量
                getUnreadCount();
                //显示没数据Ui样式
                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);
                }
            }
        });
    }