package com.cooleshow.student.ui.main;

import static com.cooleshow.student.constants.CourseConstants.LIVE_COURSE;
import static com.cooleshow.student.constants.CourseConstants.OTHER_COURSE;
import static com.cooleshow.student.constants.CourseConstants.PIANO_ROOM_COURSE;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.cooleshow.base.common.BaseApplication;
import com.cooleshow.base.common.WebConstants;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.base.utils.SPUtils;
import com.cooleshow.base.utils.TimeUtils;
import com.cooleshow.base.utils.UiUtils;
import com.cooleshow.base.utils.helper.QMUIDisplayHelper;
import com.cooleshow.student.R;
import com.cooleshow.student.adapter.HomeHotAlbumAdapter;
import com.cooleshow.student.adapter.HomeLiveCourseAdapter;
import com.cooleshow.student.adapter.HomeMenuPagerAdapter;
import com.cooleshow.student.adapter.HomeTeacherStyleAdapter;
import com.cooleshow.student.adapter.HomeVideoCourseAdapter;
import com.cooleshow.student.adapter.HomeWonderfulInfoAdapter;
import com.cooleshow.student.bean.AppHomeBean;
import com.cooleshow.student.bean.CountOfUnreadBean;
import com.cooleshow.student.bean.HelpCenterContentBean;
import com.cooleshow.student.bean.HomeLiveAndVideoBean;
import com.cooleshow.student.bean.HomeStyleBean;
import com.cooleshow.student.bean.HotAlbumBean;
import com.cooleshow.student.bean.StudentUserInfo;
import com.cooleshow.student.constants.CourseConstants;
import com.cooleshow.student.contract.HomeContract;
import com.cooleshow.student.databinding.FragmentHomeLayoutBinding;
import com.cooleshow.student.presenter.main.HomePresenter;
import com.cooleshow.student.ui.course.SparringCourseDetailActivity;
import com.cooleshow.student.widgets.DialogUtils;
import com.cooleshow.usercenter.helper.UserHelper;
import com.daya.live_teaching.utils.DisplayUtils;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TreeMap;

/**
 * 创建日期：2022/5/26 10:03
 *
 * @author Ryan
 * 类说明：
 */
public class HomeFragment extends BaseMVPFragment<FragmentHomeLayoutBinding, HomePresenter> implements HomeContract.HomeView, View.OnClickListener {
    private boolean isShowFlashPage = false;
    private String mCurrentShowNoticeId;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_avatar:
            case R.id.tv_name:
                ARouter.getInstance().build(RouterPath.MineCenter.MINE_PERSONAL_SETTING)
                        .navigation();
                break;
            case R.id.im_message:
                if (UiUtils.isFastClick()) {
                    return;
                }
                ARouter.getInstance().build(RouterPath.MessageCenter.TEACHER_MESSAGE_MESSAGEBOX)
                        .navigation();
                break;
            case R.id.tv_wonderful_info_more:
                //精彩资讯
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_SPECIAL)
                        .navigation();
                break;
            case R.id.tv_hot_album_more:
                //热门专辑
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_MUSIC_ALBUM)
                        .navigation();
                break;
            case R.id.tv_live_course_more:
                if (UiUtils.isFastClick()) {
                    return;
                }
                //直播课
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_LIVE_CLASS)
                        .navigation();
                break;
            case R.id.tv_video_course_more:
                if (UiUtils.isFastClick()) {
                    return;
                }
                //视频课
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_VIDEO_CLASS)
                        .navigation();
                break;
            case R.id.tv_teacher_style_more:
                if (UiUtils.isFastClick()) {
                    return;
                }
                //老师风采
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_TEACHER_ELEGANT)
                        .navigation();
                break;
            case R.id.bg_announcement:
                if (TextUtils.isEmpty(mCurrentShowNoticeId)) {
                    return;
                }
                //点击单条公告
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.HELP_CENTER_DETAIL + mCurrentShowNoticeId)
                        .navigation();
                break;
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        presenter.queryCountOfUnread();
        presenter.queryUserInfo();
        presenter.helpCenterContentList();
        presenter.queryLiveAndVideo();
    }

    @Override
    protected FragmentHomeLayoutBinding getLayoutView() {
        return FragmentHomeLayoutBinding.inflate(getLayoutInflater());
    }

    @Override
    protected HomePresenter createPresenter() {
        return new HomePresenter();
    }

    private Banner banner;
    private LinearLayout llIndicator;

    @Override
    protected void initView(View rootView) {
        banner = mViewBinding.banner;
        llIndicator = mViewBinding.llIndicator;
        mViewBinding.imMessage.setOnClickListener(this);
        mViewBinding.tvWonderfulInfoMore.setOnClickListener(this);
        mViewBinding.tvHotAlbumMore.setOnClickListener(this);
        mViewBinding.tvLiveCourseMore.setOnClickListener(this);
        mViewBinding.tvVideoCourseMore.setOnClickListener(this);
        mViewBinding.tvTeacherStyleMore.setOnClickListener(this);
        mViewBinding.tvName.setOnClickListener(this);
        mViewBinding.ivAvatar.setOnClickListener(this);
        mViewBinding.bgAnnouncement.setOnClickListener(this);

        mViewBinding.scrollLayout.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            boolean localVisibleRect = getLocalVisibleRect(getActivity(), banner, 10);
            //banner可见的时候就自动循环，否则就停止，解决问题：在scrollview到最底部时候，由于banner自动到第一个时候就往上顶一段距离
            if (localVisibleRect) {
                if (null != banner) {
                    banner.isAutoLoop(true);
                }
            } else {
                if (null != banner) {
                    banner.isAutoLoop(false);
                }
            }


        });
    }

    private void initBanner(List<AppHomeBean.ItemBean> bannerList) {
        if (null == bannerList || bannerList.size() == 0) {
            banner.setVisibility(View.GONE);
            return;
        }
        banner.setVisibility(View.VISIBLE);
        //banner自带图片轮播的适配器
        banner.setAdapter(new BannerImageAdapter<AppHomeBean.ItemBean>(bannerList) {

            @Override
            public void onBindView(BannerImageHolder holder, AppHomeBean.ItemBean data, int position, int size) {
                Glide.with(holder.imageView)
                        .load(data.coverImage)
                        .thumbnail(Glide.with(holder.itemView).load(com.cooleshow.base.R.drawable.bg_video_placeholder))//加载成功前显示一个loading的加载
                        //.apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))  //设置图片圆角
                        .into(holder.imageView);

            }
        }, true).addBannerLifecycleObserver(this)//添加生命周期观察者
                .setIntercept(true) //是否要拦截事件
                .setBannerRound(12f) //圆角
                .isAutoLoop(true)
                .removeIndicator()
//                .setIndicator(new CircleIndicator(getContext())) //圆形指示器 还支持条形指示器等
                .setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(Object data, int position) {
                        AppHomeBean.ItemBean item = (AppHomeBean.ItemBean) data;
                        if (!TextUtils.isEmpty(item.linkUrl)) {
                            ARouter.getInstance()
                                    .build(RouterPath.WebCenter.ACTIVITY_HTML)
                                    .withString(WebConstants.WEB_URL, item.linkUrl)
                                    .navigation();
                        }
                    }
                });
    }


    @Override
    protected void initData() {
        presenter.appHome();
        presenter.userAccountPage();
        presenter.queryLiveAndVideo();
        presenter.getStylePage();

        mViewBinding.refreshLayout.setOnRefreshListener(refreshLayout -> {
            mViewBinding.refreshLayout.finishRefresh();
            presenter.appHome();
            presenter.userAccountPage();
            presenter.queryLiveAndVideo();
            presenter.getStylePage();
            presenter.queryUserInfo();
            presenter.helpCenterContentList();
        });

    }


    @Override
    public void appHomeSuccess(AppHomeBean appHomeBean) {
        initBanner(appHomeBean.banner);
        initMenu(appHomeBean.appMenu);
        initWonderfulInfo(appHomeBean.information);
        showDialog(appHomeBean.flashPage);
    }

    private void showDialog(List<AppHomeBean.ItemBean> flashPage) {
        if (null == flashPage || flashPage.size() == 0) {
            return;
        }
        if (isShowFlashPage) {
            return;
        }
        DialogUtils.showHomeDialog(getContext(), flashPage.get(0));
        isShowFlashPage = true;
    }

    @Override
    public void hotAlbumListSuccess(HotAlbumBean data) {
        if (null == data || null == data.rows || data.rows.size() == 0) {
            mViewBinding.clHotAlbum.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clHotAlbum.setVisibility(View.VISIBLE);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mViewBinding.rvHotAlbum.setLayoutManager(manager);
        HomeHotAlbumAdapter albumAdapter = new HomeHotAlbumAdapter(data.rows);
        mViewBinding.rvHotAlbum.setAdapter(albumAdapter);
        albumAdapter.setOnItemClickListener((adapter, view, position) -> {
            HotAlbumBean.RowsBean item = (HotAlbumBean.RowsBean) adapter.getItem(position);
            ARouter.getInstance()
                    .build(RouterPath.WebCenter.ACTIVITY_HTML)
                    .withString(WebConstants.WEB_URL, WebConstants.STUDENT_MUSIC_ALBUM_DETAIL + item.id)
                    .navigation();
        });

    }

    @Override
    public void queryLiveAndVideoSuccess(HomeLiveAndVideoBean data) {
        initLiveCourse(data.liveList);
        initVideoCourse(data.videoList);
        initRecentLive(data.recentCourses);
    }

    @Override
    public void getStylePageSuccess(HomeStyleBean data) {
        if (null == data.rows || data.rows.size() == 0) {
            mViewBinding.clTeacherStyle.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clTeacherStyle.setVisibility(View.VISIBLE);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
        mViewBinding.rvTeacherStyle.setLayoutManager(gridLayoutManager);
        HomeTeacherStyleAdapter homeTeacherStyleAdapter = new HomeTeacherStyleAdapter(data.rows);
        mViewBinding.rvTeacherStyle.setAdapter(homeTeacherStyleAdapter);
        homeTeacherStyleAdapter.setOnItemClickListener((adapter, view, position) -> {
            HomeStyleBean.RowsBean item = (HomeStyleBean.RowsBean) adapter.getItem(position);
            ARouter.getInstance()
                    .build(RouterPath.WebCenter.ACTIVITY_HTML)
                    .withString(WebConstants.WEB_URL, WebConstants.STUDENT_TEACHER_HOME + item.userId)
                    .navigation();

        });

    }

    @Override
    public void queryUserInfoSuccess(StudentUserInfo data) {
        GlideUtils.INSTANCE.loadImage(getContext(), data.heardUrl, mViewBinding.ivAvatar, R.drawable.icon_student_default_head);
        mViewBinding.tvName.setText(data.username);

        if (TextUtils.isEmpty(data.subjectName)) {
            ARouter.getInstance().build(RouterPath.MineCenter.MINE_TEACHABLE_INSTRUMENT)
                    .withBoolean("hintBar", true)
                    .navigation();
        }
    }

    @Override
    public void helpCenterContentListSuccess(HelpCenterContentBean bean) {
        if (isDetached()) {
            return;
        }
        if (bean != null && bean.rows != null && bean.rows.size() > 0) {
            mViewBinding.bgAnnouncement.setVisibility(View.VISIBLE);
            HelpCenterContentBean.RowsBean rowsBean = bean.rows.get(0);
            mViewBinding.tvNoticeContent.setText(rowsBean.title);
            mCurrentShowNoticeId = rowsBean.id;
        } else {
            mViewBinding.bgAnnouncement.setVisibility(View.GONE);
        }
    }


    @SuppressLint("SetTextI18n")
    private void initRecentLive(HomeLiveAndVideoBean.RecentCoursesBean recentCourses) {
        if (null == recentCourses) {
            mViewBinding.clLive.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clLive.setVisibility(View.VISIBLE);
        GlideUtils.INSTANCE.loadImage(getContext(), recentCourses.avatar, mViewBinding.imLiveHeader, R.drawable.icon_student_default_head);
        mViewBinding.tvLiveTitle.setText(recentCourses.courseGroupName+"即将开始");
        String currentTime = TimeUtils.date2String(new Date(System.currentTimeMillis()), "yyyy-MM-dd");
        String startTime = TimeUtils.date2String(TimeUtils.getDate(recentCourses.courseStartTime), "yyyy-MM-dd");
        if (!TextUtils.isEmpty(recentCourses.courseStartTime) && TextUtils.equals(currentTime, startTime)) {
            String timeText = TimeUtils.date2String(TimeUtils.getDate(recentCourses.courseStartTime), "HH:mm");
            mViewBinding.tvLiveTime.setText("今日 " + timeText);
        } else {
            mViewBinding.tvLiveTime.setText(TimeUtils.date2String(TimeUtils.getDate(recentCourses.courseStartTime), "yyyy-MM-dd HH:mm"));
        }
        mViewBinding.tvGoLive.setOnClickListener(v -> {
            gotoCourseDetail(recentCourses);
        });
    }

    /**
     * 跳转直播课详情页面
     *
     * @param bean
     */
    private void gotoCourseDetail(HomeLiveAndVideoBean.RecentCoursesBean bean) {
        switch (bean.courseType) {
            case LIVE_COURSE:
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, String.format(WebConstants.TEACHER_LIVE_DETAIL_NORMAL_COURSE, bean.courseGroupId, bean.courseId))
                        .navigation();
                break;
            case OTHER_COURSE:
                //陪练课
                ARouter.getInstance().build(RouterPath.CourseCenter.SPARRING_COURSE_DETAIL)
                        .withString(CourseConstants.COURSE_ID, String.valueOf(bean.courseId))
                        .withString(CourseConstants.COURSE_GROUP_ID, String.valueOf(bean.courseGroupId))
                        .navigation();
                break;
            case PIANO_ROOM_COURSE:
                //琴房课 跳转详情页
                ARouter.getInstance().build(RouterPath.CourseCenter.PIANO_ROOM_COURSE_DETAIL)
                        .withString(CourseConstants.COURSE_ID, String.valueOf(bean.courseId))
                        .navigation();
                break;
        }

    }

    private void initLiveCourse(List<HomeLiveAndVideoBean.CourseBean> liveList) {
        if (null == liveList || liveList.size() == 0) {
            mViewBinding.clLiveCourse.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clLiveCourse.setVisibility(View.VISIBLE);

        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mViewBinding.rvLiveCourse.setLayoutManager(manager);
        HomeLiveCourseAdapter homeLiveCourseAdapter = new HomeLiveCourseAdapter(liveList);
        mViewBinding.rvLiveCourse.setAdapter(homeLiveCourseAdapter);
        homeLiveCourseAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                HomeLiveAndVideoBean.CourseBean item = (HomeLiveAndVideoBean.CourseBean) adapter.getItem(position);
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.TEACHER_LIVE_DETAIL + "?groupId=" + item.courseGroupId)
                        .navigation();
            }
        });
    }

    private void initVideoCourse(List<HomeLiveAndVideoBean.VideoCourseBean> liveList) {
        if (null == liveList || liveList.size() == 0) {
            mViewBinding.clVideoCourse.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clVideoCourse.setVisibility(View.VISIBLE);

        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mViewBinding.rvVideoCourse.setLayoutManager(manager);
        HomeVideoCourseAdapter homeLiveCourseAdapter = new HomeVideoCourseAdapter(liveList);
        mViewBinding.rvVideoCourse.setAdapter(homeLiveCourseAdapter);
        homeLiveCourseAdapter.setOnItemClickListener((adapter, view, position) -> {
            HomeLiveAndVideoBean.VideoCourseBean item = (HomeLiveAndVideoBean.VideoCourseBean) adapter.getItem(position);
            ARouter.getInstance()
                    .build(RouterPath.WebCenter.ACTIVITY_HTML)
                    .withString(WebConstants.WEB_URL, WebConstants.TEACHER_VIDEO_DETAIL + "?groupId=" + item.videoGroupId)
                    .navigation();
        });
    }


    private List<Fragment> fragments = new ArrayList<>();

    private void initMenu(List<AppHomeBean.ItemBean> menuList) {
        fragments.clear();
        int count = menuList.size() / 5;
        if (menuList.size() % 5 > 0) {
            count++;
        }

        for (int i = 0; i < count; i++) {
            List<AppHomeBean.ItemBean> dataList = new ArrayList<>();
            for (int j = i * 5; j < menuList.size() && j < (i + 1) * 5; j++) {
                dataList.add(menuList.get(j));
            }
            fragments.add(HomeMenuFragment.newInstance(dataList));
        }
        mViewBinding.viewpagerMenu.removeAllViews();
        if (fragments.size() == 0) {
            mViewBinding.viewpagerMenu.setVisibility(View.GONE);
            return;
        }

        mViewBinding.viewpagerMenu.setVisibility(View.VISIBLE);
        HomeMenuPagerAdapter homeMenuPagerAdapter = new HomeMenuPagerAdapter(getParentFragmentManager(), fragments);
        mViewBinding.viewpagerMenu.setAdapter(homeMenuPagerAdapter);
        mViewBinding.viewpagerMenu.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                position = position % fragments.size();// 需要对position的值进行重新赋值，否则会造成数组越界
                // 更新小圆点的显示
                for (int i = 0; i < fragments.size(); i++) {
                    ImageView iv = (ImageView) llIndicator.getChildAt(i);
                    // 当前滑到的是那一页就让第几个小圆点处于选中状态
                    if (position == i) {
                        iv.setImageResource(R.drawable.bg_2dc7aa_indicator);
                    } else {
                        iv.setImageResource(R.drawable.bg_f2f2f2_indicator);
                    }
                }
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        initPoint();

    }

    /**
     * 初始化指示器
     */
    private void initPoint() {
        llIndicator.removeAllViews();
        for (int i = 0; i < fragments.size(); i++) {
            // 往llContainer添加一个小圆点
            ImageView iv = new ImageView(getContext());
            //设置背景
            iv.setImageResource(R.drawable.bg_f2f2f2_indicator);
            //设置大小
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(QMUIDisplayHelper.dp2px(getContext(), 17), QMUIDisplayHelper.dp2px(getContext(), 4));
            iv.setLayoutParams(params);
            // 默认第0个小圆点显示红色
            if (i == 0) {
                iv.setEnabled(true);
            } else {
                iv.setEnabled(false);
            }
            //添加到LinearLayout中
            llIndicator.addView(iv);
        }
    }

    private void initWonderfulInfo(List<AppHomeBean.ItemBean> information) {
        if (null == information || information.size() == 0) {
            mViewBinding.clWonderfulInfo.setVisibility(View.GONE);
            return;
        }
        mViewBinding.clWonderfulInfo.setVisibility(View.VISIBLE);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mViewBinding.rvWonderfulInfo.setLayoutManager(manager);
        HomeWonderfulInfoAdapter wonderfulInfoAdapter = new HomeWonderfulInfoAdapter(information);
        mViewBinding.rvWonderfulInfo.setAdapter(wonderfulInfoAdapter);
        wonderfulInfoAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                AppHomeBean.ItemBean item = (AppHomeBean.ItemBean) adapter.getItem(position);
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.STUDENT_SPECIAL_DETAIL + item.id)
                        .navigation();

            }
        });
    }

    public static boolean getLocalVisibleRect(Activity activity, View view, int offsetY) {

        Point p = new Point();

        activity.getWindowManager().getDefaultDisplay().getSize(p);

        int screenWidth = p.x;

        int screenHeight = p.y;

        Rect rect = new Rect(0, 0, screenWidth, screenHeight);//得到屏幕矩阵

        int[] location = new int[2];

        location[1] = location[1] + DisplayUtils.dip2px(BaseApplication.context, offsetY);

        view.getLocationInWindow(location);

        view.setTag(location[1]);//存储y方向的位置

        if (view.getLocalVisibleRect(rect)) {

            return true;

        } else {

            return false;

        }

    }


    @Override
    public void queryCountOfUnreadSuccess(List<CountOfUnreadBean> data) {
        if (null == data || data.size() == 0) {
            mViewBinding.viewUnreadMessage.setVisibility(View.GONE);
            return;
        }
        int totalCount = 0;
        for (CountOfUnreadBean datum : data) {
            totalCount += datum.value;
        }
        if (totalCount > 0) {
            mViewBinding.viewUnreadMessage.setVisibility(View.VISIBLE);
        } else {
            mViewBinding.viewUnreadMessage.setVisibility(View.GONE);
        }
    }
}
