TemplateFragment.java 38.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
package com.wd.display.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import org.jetbrains.annotations.NotNull;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.github.mminng.itemvisibility.listener.ItemStateChangeListener;
import com.orhanobut.logger.Logger;
import com.people.comment.bean.CommentClickShowType;
import com.people.comment.comment.listener.ICommentDataNewListener;
import com.people.comment.comment.vm.CommentViewModel;
import com.people.comment.dialog.CommentCommitDialog;
import com.people.comment.listener.CommitDialogListener;
import com.people.common.CommonNetUtils;
import com.people.common.ProcessUtils;
import com.people.common.analytics.CommonTrack;
import com.people.common.base.BaseLazyFragment;
import com.people.common.constant.DefaultViewConstant;
import com.people.common.constant.IntentConstants;
import com.people.common.decoration.Decoration;
import com.people.common.dialog.AlertDialog;
import com.people.common.util.PDUtils;
import com.people.common.widget.CommomLoadMoreFooter;
import com.people.common.widget.CommonRefreshHeader;
import com.people.common.widget.CustomSmartRefreshLayout;
import com.people.common.widget.DefaultView;
import com.people.common.widget.progress.PageLoadingView;
import com.people.component.R;
import com.people.component.comp.layoutdata.AbsGroup;
import com.people.component.comp.layoutdata.Group;
import com.people.component.comp.layoutdata.Page;
import com.people.component.comp.layoutmanager.BaseAdapter;
import com.people.component.comp.layoutmanager.ILayoutRender;
import com.people.component.comp.layoutmanager.ItemLayoutManager;
import com.people.component.comp.layoutmanager.LayoutAdapter;
import com.people.component.comp.parser.NewsSectionParserHelper;
import com.people.component.ui.commonpage.TemplatePageDataFetcher;
import com.people.component.ui.commonpage.TemplatePageDataListener;
import com.people.component.ui.commonpage.TemplatePageDataViewModel;
import com.people.component.ui.widget.nested.ColumnRecyclerView;
import com.people.component.ui.widget.nested.VerticalLoadScrollListener;
import com.people.component.utils.CompentLogicUtil;
import com.people.daily.lib_library.ToastNightUtil;
import com.people.entity.analytics.TrackContentBean;
import com.people.entity.comment.CommentListBean;
import com.people.entity.comment.CommentStatusBean;
import com.people.entity.comment.TransparentBean;
import com.people.entity.convenience.MoreItemBean;
import com.people.entity.custom.MenuBean;
import com.people.entity.custom.comp.CompBean;
import com.people.entity.custom.comp.CompDataSourceBean;
import com.people.entity.custom.comp.PageBean;
import com.people.entity.custom.content.CommentItem;
import com.people.entity.custom.content.ContentBean;
import com.people.entity.livedate.CommentOperationBean;
import com.people.entity.livedate.EventMessage;
import com.people.entity.response.MyAskMarkBean;
import com.people.entity.response.PersonalInfoBean;
import com.people.livedate.EventConstants;
import com.people.livedate.base.LiveDataBus;
import com.people.network.BaseObserver;
import com.people.network.NetworkUtils;
import com.people.network.bean.MetaBean;
import com.people.room.entity.ChannelBean;
import com.people.toolset.SpUtils;
import com.people.toolset.json.GsonUtils;
import com.people.toolset.string.StrUtils;
import com.people.toolset.system.DeviceUtil;
import com.people.umeng.enums.MoreEnum;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.wondertek.wheat.ability.tools.ResUtils;
import com.wondertek.wheat.ability.tools.SafeBundleUtil;
import com.wondertek.wheat.ability.tools.StringUtils;

/**
 * @Description: 信息流页面一个模板(自定义 页面信息 , 便于使用组件和稿件资源) 模板页fragment
 * @Author: Li Yubing
 * @Email: liyubing@wondert.com.cn
 * @CreateDate: 2023/8/14 18:46
 * @Version: 1.0
 * 数据请求:{@link TemplatePageDataFetcher}
 */
public class TemplateFragment extends BaseLazyFragment implements OnRefreshLoadMoreListener {
    private static final String TAG = "TemplateFragment";
    /**
     * 列表
     * mCommentData:处理列表数据供adapter使用
     */
    CommentCommitDialog commitDialog;

    CommentViewModel commentViewModel;
    private CommonRefreshHeader refreshHeader;

    private CommomLoadMoreFooter footView;

    // 页面是否展示了底线
    private boolean haveBottomLine = false;

    private ILayoutRender layoutRender;

    /**
     * 总页面容器
     */
    private FrameLayout mFrameLayout;

    /**
     * 下拉上推布局
     */
    private CustomSmartRefreshLayout refreshLayout;

    /**
     * 缺省页
     */
    private DefaultView defaultView;

    /**
     * 信息流页面容器
     */
    private FrameLayout contentFrameLayout;

    /**
     * 首次加载视图
     */
    private PageLoadingView loadingView;

    /**
     * recyclerview背景
     */
    protected View viewBg;

    /**
     * 当前页数据
     */
    private PageBean mPageBean;
    private Page mPage;
    /**
     * 页面是否已经有数据显示
     */
    private boolean isHashLoadDataInPage = false;

    /**
     * 内容存储器
     */
    private ColumnRecyclerView mRecyclerView;

    private VerticalLoadScrollListener aheadLoadScrollListener;

    private int pageNum = 1;

    private MenuBean menuBean;

    private ChannelBean mChannelBean;

    private String channelId;
    /**
     * 数据来源
     */
    private String dataSourceType;

    /**
     * 1 开启,2 关闭
     */
    private int bestNoticer = 2;

    TemplatePageDataViewModel templatePageDataViewModel;

    /**
     * 获取Fragment实例对象
     *
     * @param menuBean 数据id
     * @return Fragment实例
     */
    public static TemplateFragment newInstance(MenuBean menuBean) {
        TemplateFragment fragment = new TemplateFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(IntentConstants.PAGE_INFOR_DATA, menuBean);
        fragment.setArguments(bundle);
        return fragment;
    }

    /**
     * 获取Fragment实例对象
     *
     * @param menuBean 数据id
     * @return Fragment实例
     */
    public static TemplateFragment newInstance(MenuBean menuBean, int topMarginInt, ChannelBean channelBean) {
        TemplateFragment fragment = new TemplateFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(IntentConstants.PAGE_INFOR_DATA, menuBean);
        bundle.putInt(IntentConstants.PARAM_TOPMARGININT, topMarginInt);
        bundle.putSerializable(IntentConstants.PARAM_PAGE_OBJ, channelBean);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    protected void perCreate() {
        super.perCreate();
        //首页启动速度用户,使用java布局
        setIsjava(true);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        int topMarginInt = SafeBundleUtil.getInt(getArguments(), IntentConstants.PARAM_TOPMARGININT, 0);
        if (topMarginInt != 0) {
            mFrameLayout.setPadding(0, topMarginInt, 0, 0);
        }
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    protected int getLayout() {
        return 0;
    }

    @Override
    protected void initView(View rootView) {

        menuBean = (MenuBean) SafeBundleUtil.getSerializable(getArguments(), IntentConstants.PAGE_INFOR_DATA);
        mChannelBean = (ChannelBean) SafeBundleUtil.getSerializable(getArguments(), IntentConstants.PARAM_PAGE_OBJ);
        if (mChannelBean != null) {
            channelId = mChannelBean.getChannelId();
        }
        if(menuBean != null){
            dataSourceType = menuBean.dataSourceType;
        }
        if(CompDataSourceBean.LIVE_HORIZONTAL_CARD.equals(dataSourceType) || CompDataSourceBean.LIVE_RESERVATION.equals(dataSourceType)
                || CompDataSourceBean.LOCAL_MY_SUBSCRIBE.equals(dataSourceType)){
            mRecyclerView.setBackgroundColor(ResUtils.getColor(R.color.res_color_general_F9F9F9));
            mRecyclerView.setPadding(0, (int) ResUtils.getDimension(R.dimen.rmrb_dp4),0,0);
        }
        addHeadFootViewRF();
        initViewModel();
        registerBus();
    }

    /**
     * 注册LiveBus
     */
    private void registerBus() {

        // 接收删除稿件事件
//        LiveDataBus.getInstance().with(EventConstants.USER_COMP_MANUSCRIPT_DEL + mPageId, Integer.class).observe(getViewLifecycleOwner(), postion -> {
//
//            if (layoutRender != null) {
//                layoutRender.itemRemoved(postion);
//            }
//
//        });
        //接受关注事件
        LiveDataBus.getInstance().with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
            if (mEventMessage == null) {
                return;
            }
            if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
                // 同步关注信息
                List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
                CompentLogicUtil.updateUserFollowInforLayout(mEventMessage, layoutManagers);
            }
        });

        //接受点赞事件
        LiveDataBus.getInstance().with(EventConstants.FRESH_ZAN_CREATOR_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
            if (mEventMessage == null) {
                return;
            }
            if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
                // 同步关注信息
                List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
                CompentLogicUtil.updateUserZanInforLayout(mEventMessage, layoutManagers);
            }
        });

        //接受预约状态事件
        LiveDataBus.getInstance().with(EventConstants.FRESH_APPONINTMENT_STATUS_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
            if (mEventMessage == null) {
                return;
            }
            if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
                // 同步关注信息
                List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
                CompentLogicUtil.updateCompLiveAppointStatus(mEventMessage, layoutManagers);
            }
        });

        if(menuBean != null && CompDataSourceBean.LOCAL_HIGHQUALITYCOMMENTSPAGECARD.equals(menuBean.dataSourceType)){
            //评论操作
            LiveDataBus.getInstance()
                    .with(EventConstants.COMMENT_OPERATION_EVENT, CommentOperationBean.class)
                    .observe(getActivity(), new Observer<CommentOperationBean>() {
                        @Override
                        public void onChanged(CommentOperationBean commentOperationBean) {
                            if(commentOperationBean == null || mPageBean == null || mPageBean.getGroups() == null
                            || mPageBean.getGroups().size()< 1 || mPageBean.getGroups().get(0) == null
                            || mPageBean.getGroups().get(0).getComps() == null || mPageBean.getGroups().get(0).getComps().size()<1){
                                return;
                            }
                                String commentId = commentOperationBean.getCommentId();
                                int operationType = commentOperationBean.getOperationType();
                                List<CompBean> newsCompList = mPageBean.getGroups().get(0).getComps();
                            CompBean selectCompBean = null;
                            for(CompBean compBean: newsCompList){
                                    if (compBean == null || compBean.getOperDataList() == null
                                            || compBean.getOperDataList().size()<1 || compBean.getOperDataList().get(0) == null){
                                        continue;
                                    }
                                    ContentBean contentBean = compBean.getOperDataList().get(0);
                                    if(contentBean.getCommentInfo() == null){
                                        continue;
                                    }
                                    if(commentId.equals(contentBean.getCommentInfo().getCommentId())){
                                        selectCompBean = compBean;
                                    }
                            }
                                int curPosition = 0;// FIXME: 2023/11/8
                                int clickShowType = 0;
                                if (operationType == MoreEnum.REPLY){
                                    clickShowType = CommentClickShowType.reply;
                                }else if (operationType == MoreEnum.DELETE){
                                    clickShowType = CommentClickShowType.delete;
                                }else if (operationType == MoreEnum.COPY_LINK){
                                    clickShowType = CommentClickShowType.copy;
                                }else if (operationType == MoreEnum.REPORT){
                                    clickShowType = CommentClickShowType.report;
                                }
                                if (selectCompBean != null){
                                    judeClickType(selectCompBean,clickShowType);
                                }
                        }
                    });
        }

    }

    private void initViewModel() {

        templatePageDataViewModel = getViewModelThis(TemplatePageDataViewModel.class);
        templatePageDataViewModel.setChannelBean(mChannelBean);
        templatePageDataViewModel.setChannelId(channelId);
        templatePageDataViewModel.observeTemplatePageDataListener(this, new TemplatePageDataListener() {


            @Override
            public void onPageDataSuccess(Page page, PageBean data) {
                hideLoading();
                hidePageLoadingView();
                mPage = page;
                mPageBean = data;
                //   Log.e("DDDDSSS","data.needRefresh="+data.needRefresh);
                if (data.needRefresh) {
                    hideDefaultView();
                    isHashLoadDataInPage = true;
                    doPageDataSuccess();
                } else {
                    // 加载更多组件
                    List<ItemLayoutManager> layoutManagerList = layoutRender.getAllSectionLayoutManager();
                    // 页面缓存数据量
                    int startIndex = layoutManagerList.size();

                    // page.setDisplayItemCount(startIndex);
                    layoutRender.renderPage(page, false);
                    // 检测是否满足加载更多
                    boolean isLoadMore = checkHaveMoreLoad();
                    if (!isLoadMore) {
                        if (!haveBottomLine) {
                            layoutRender.addBaseLine(mPage);
                            haveBottomLine = true;
                        }
                    } else {
                        haveBottomLine = false;
                    }

                    List<ItemLayoutManager> newList = layoutRender.getAllSectionLayoutManager();
                    // 页面新数据量
                    int endIndex = newList.size();
                    BaseAdapter baseAdapter = (BaseAdapter) layoutRender;
                    baseAdapter.notifyItemRangeChanged(startIndex, endIndex);
                }

                if (pageNum == 1) {
                    AbsGroup absGroup = mPage.getGroups().get(0);
                    Group groupBean = (Group) absGroup;
                    int newCompSize = groupBean.getSections().size();
                    if (newCompSize == 0) {
                        isHashLoadDataInPage = false;
                        showDefaultView(DefaultViewConstant.TYPE_NO_CONTENT);
                    }
                }
                //检测是否需要开启预先加载
                boolean openLoadMore = checkHaveMoreLoad();
                refreshLayout.setEnableLoadMore(openLoadMore);
                // 检测到有分页数据,启用本地缓存无需要给pagenum加1
                if (openLoadMore) {
                    // 添加页码
                    pageNum = pageNum + 1;
                }

                if (aheadLoadScrollListener != null) {
                    aheadLoadScrollListener.setOneAheadLoadMore(openLoadMore);
                }

            }

            @Override
            public void onGetFailed(int code, String failedMsg) {
                hideLoading();
                hidePageLoadingView();
                if (!isHashLoadDataInPage) {
                    showDefaultView(DefaultViewConstant.TYPE_GET_CONTENT_ERROR);
                }
            }
        });

    }

    @Override
    protected View getJavaLayout() {
        mFrameLayout = new FrameLayout(activity);
        mFrameLayout.setBackgroundColor(0x00FFFFFF);
        //刷新框架
        refreshLayout = (CustomSmartRefreshLayout) LayoutInflater.from(activity).inflate(R.layout.page_layout_smartrefreshlayout, null);
        FrameLayout subLayout = getSubLayout();
        refreshLayout.addView(subLayout);
        mFrameLayout.addView(refreshLayout);
        //ViewStub
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//        ViewStub view_stub_special_view = new ViewStub(activity);
//        view_stub_special_view.setLayoutParams(params);
//        mFrameLayout.addView(view_stub_special_view);
//        view_stub_special_view.setLayoutResource(R.layout.custom_layout_special_view);

        //PageLoadingView
        params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER;
        loadingView = new PageLoadingView(activity);
        loadingView.setLayoutParams(params);
        loadingView.setVisibility(View.GONE);
        mFrameLayout.addView(loadingView);

        return mFrameLayout;
    }

    private FrameLayout getSubLayout() {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        contentFrameLayout = new FrameLayout(activity);
        contentFrameLayout.setLayoutParams(params);
        viewBg = new View(activity);
        viewBg.setAlpha(0);
        viewBg.setBackgroundColor(ContextCompat.getColor(activity, R.color.res_color_common_C8));
        contentFrameLayout.addView(viewBg);
        mRecyclerView = (ColumnRecyclerView) LayoutInflater.from(activity).inflate(R.layout.page_layout_columnrecyclerview, null);
        contentFrameLayout.addView(mRecyclerView);

        //DefaultView
        FrameLayout.LayoutParams defaultViewLp = new FrameLayout.LayoutParams(DeviceUtil.getDeviceWidth(), DeviceUtil.getDeviceHeight());
        defaultView = new DefaultView(activity);
        defaultView.setLayoutParams(defaultViewLp);

        FrameLayout pContent = new FrameLayout(activity);
        pContent.addView(contentFrameLayout);
        pContent.addView(defaultView);
        return pContent;
    }

    /**
     * 添加头部和底部view
     */
    private void addHeadFootViewRF() {
        if (refreshHeader == null) {
            refreshHeader = new CommonRefreshHeader(getActivity());
            refreshLayout.setRefreshHeader(refreshHeader);
        }

        refreshLayout.setEnableRefresh(true);
        refreshLayout.setOnRefreshLoadMoreListener(this);
        if (footView == null) {
            footView = new CommomLoadMoreFooter(getActivity());
            footView.setDescTextColor(ContextCompat.getColor(getActivity(), R.color.color_93959D));
            refreshLayout.setRefreshFooter(footView);
        }
        refreshLayout.setEnableLoadMore(false);
    }

    /**
     * 处理数据获取成功后续逻辑
     */
    private void doPageDataSuccess() {

        if (mPage == null) {
            return;
        }
        mPage.setFragment(TemplateFragment.this);

        initCommonRecyclerView();

        if (layoutRender != null) {
            layoutRender.renderPage(mPage, true);
            // 检测是否满足加载更多
            boolean isLoadMore = checkHaveMoreLoad();
            if (!isLoadMore) {
                haveBottomLine = true;
                layoutRender.addBaseLine(mPage);
            } else {
                haveBottomLine = false;
            }
            layoutRender.notifyDataSetChanged();
        }

    }

    private void initCommonRecyclerView() {

        mRecyclerView.setNestedScrollingEnabled(true);

        if (layoutRender != null) {
            layoutRender.releaseLayoutManagers();
        }
        layoutRender = new LayoutAdapter();
        // 组件内的滚动事件
        mRecyclerView.setItemViewCacheSize(NewsSectionParserHelper.getColumnCacheSize());
        mRecyclerView.setDrawingCacheEnabled(true);
        mRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 12, RecyclerView.VERTICAL, false);
        //  mRecyclerView.setOnAllowEnableLoadMoreListener(onAllowEnableLoadMoreListener);
        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (layoutRender.getAllSectionLayoutManager().size() == 0) {
                    return 0;
                }
                return 12 / layoutRender.getAllSectionLayoutManager().get(position).getItemSpan();
            }
        });
        //  mRecyclerView.setItemAnimator(new NoAlphaItemAnimator());
        // 关闭动画,防止刷新闪烁
        RecyclerView.ItemAnimator animator = mRecyclerView.getItemAnimator();
        if (animator instanceof SimpleItemAnimator) {
            ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
        }

        RecyclerView.RecycledViewPool pool = new RecyclerView.RecycledViewPool();
        pool.setMaxRecycledViews(0, 10);
        mRecyclerView.setRecycledViewPool(pool);
        mRecyclerView.getItemAnimator().setChangeDuration(0);

        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.addItemDecoration(new Decoration());

        mRecyclerView.setAdapter((BaseAdapter) layoutRender);


        // 预先加载更多
        if (aheadLoadScrollListener == null) {
            aheadLoadScrollListener = new VerticalLoadScrollListener(onAheadLoadListener);
            mRecyclerView.addOnScrollListener(aheadLoadScrollListener);
        }

        aheadLoadScrollListener.setOneAheadLoadMore(false);


        mRecyclerView.openGlobalLayout();
        mRecyclerView.itemVisibilityHelper.attachToRecyclerView(mRecyclerView, R.id.player_container, true, RecyclerView.VERTICAL, false, new ItemStateChangeListener() {

            @Override
            public void onActivateItem(@NotNull View view, int position) {
                super.onActivateItem(view, position);
                ((LayoutAdapter) layoutRender).onItemVisible(position);
            }

            @Override
            public void onDeactivateItem(@NotNull View view, int position) {
                super.onDeactivateItem(view, position);
                ((LayoutAdapter) layoutRender).onItemInVisible(position);
            }

            @Override
            public void onPauseItem(@NotNull View view, int position) {
                super.onPauseItem(view, position);
                ((LayoutAdapter) layoutRender).onItemInVisible(position);
            }

            @Override
            public void onResumeItem(@NotNull View view, int position) {
                super.onResumeItem(view, position);
                ((LayoutAdapter) layoutRender).onItemVisible(position);
            }
        });


    }


    @Override
    protected void lazyLoadData() {
        refreshHeader = null;
        footView = null;
        // 获取页面数据
        if (loadingView != null) {
            loadingView.setVisibility(View.VISIBLE);
            loadingView.showLoading();
        }
        refreshData();
        if (IntentConstants.PAGETYPE_MYLEVEWORD.equals(channelId)) {
            //我的留言列表
            refreshAskMarkData();
        }
    }

    /**
     * 刷新请求数据
     */
    private void refreshData() {

        pageNum = 1;
        templatePageDataViewModel.sendPageDataRequest(getContext(), pageNum, 20, menuBean);
    }

    /**
     * 加载更多数据
     */
    private void loadMoreData() {
        templatePageDataViewModel.sendPageDataRequest(getContext(), pageNum, 20, menuBean);
    }

    @Override
    public void onLoadMore(@NonNull @NotNull RefreshLayout refreshLayout) {
        loadMoreData();
    }

    @Override
    public void onRefresh(@NonNull @NotNull RefreshLayout refreshLayout) {
        refreshData();
    }

    /**
     * 监听加载更多事件
     */
    private VerticalLoadScrollListener.OnAheadLoadListener onAheadLoadListener =
            new VerticalLoadScrollListener.OnAheadLoadListener() {

                @Override
                public void aheadLoadMoreData() {
                    // 翻页必须大于1
                    if (pageNum > 1) {
                        loadMoreData();
                    }
                }

                @Override
                public void isTop() {

                }
            };

    /**
     * 检测是否有下一页
     *
     * @return
     */
    private boolean checkHaveMoreLoad() {
        // 组件数量
        int requestDataCompSize = mPageBean.totalCompSize;
        boolean openLoadMore = requestDataCompSize > 0;
        return openLoadMore;
    }


    public void hideLoading() {
        if (refreshLayout != null) {
            refreshLayout.finishRefresh();
            refreshLayout.finishLoadMore();
        }
        if (aheadLoadScrollListener != null) {
            aheadLoadScrollListener.setOneAheadLoadMore(true);
        }
    }

    /**
     * 隐藏关闭加载动效
     */
    private void hidePageLoadingView() {
        if (loadingView != null) {
            loadingView.stopLoading();
            loadingView.setVisibility(View.GONE);
        }
    }


    /**
     * 隐藏缺省页
     */
    private void hideDefaultView() {
        if (defaultView != null) {
            defaultView.hide();
        }
        contentFrameLayout.setVisibility(View.VISIBLE);
    }

    /**
     * 显示缺省页
     */
    private void showDefaultView(int type) {
        if (defaultView == null) {
            return;
        }
        contentFrameLayout.setVisibility(View.GONE);

        if (!NetworkUtils.isNetAvailable()) {
            type = DefaultViewConstant.TYPE_NO_NETWORK;
        }
        defaultView.setRetryBtnClickListener(new DefaultView.RetryClickListener() {
            @Override
            public void onRetryClick() {
                hideDefaultView();
                refreshData();
            }
        });
        if(DefaultViewConstant.TYPE_NO_CONTENT == type){
            //搜索推荐页、搜索tab页、搜索结果页
            if(menuBean != null && (CompDataSourceBean.RECOMMEND_LIST_SEARCH.equals(menuBean.dataSourceType)
                    || CompDataSourceBean.LOCAL_SEARCHRESULTTAB.equals(menuBean.dataSourceType)
                    || CompDataSourceBean.LOCAL_SEARCHRESULTPAGE.equals(menuBean.dataSourceType)
            )){
                //搜索结果缺省页样式
                defaultView.showWithWeight(DefaultViewConstant.TYPE_NO_CONTENT_FOUND,154,392);
            }else{
                defaultView.show(type);
            }
        }else{
            defaultView.show(type);
        }    }


    public void requestMessageBoard(List<MoreItemBean> moreSelectList, String fid) {

        if (refreshLayout != null && menuBean != null) {
            menuBean.fid = fid;
            menuBean.moreSelectList = moreSelectList;
            refreshLayout.autoRefresh();
        }

    }

    /**
     * 刷新个人中心问政小红点
     */
    private void refreshAskMarkData() {
        Logger.t(TAG).d("refreshAskMarkData======>0");
        CommonNetUtils.getInstance().getMyAskMarkData(new BaseObserver<MyAskMarkBean>() {
            @Override
            protected void dealSpecialCode(int code, String message) {

            }

            @Override
            protected void onSuccess(MyAskMarkBean myAskMarkBean) {

            }

            @Override
            protected void onSuccess(MyAskMarkBean myAskMarkBean, MetaBean metaBean, String msg, int code) {
                if (metaBean != null && !StringUtils.isEmpty(metaBean.getMd5())) {
                    SpUtils.saveAskMarkMD5(metaBean.getMd5());
                    Logger.t(TAG).d("refreshAskMarkData======>1");
                }
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mPageBean != null){
            TrackContentBean bean = new TrackContentBean();
            bean.pageBeanToTrackContentBean(mPageBean);
            bean.setExposure(duration);
            CommonTrack.getInstance().channelExposureTrack(bean);
        }
        if(menuBean != null && CompDataSourceBean.LOCAL_HIGHQUALITYCOMMENTSPAGECARD.equals(menuBean.dataSourceType)){
            LiveDataBus.getInstance()
                    .with(EventConstants.COMMENT_OPERATION_EVENT, CommentOperationBean.class).removeObservers(this);
        }
    }

    /**
     * 判断当前点击哪一个
     */
    private void judeClickType(CompBean selectCompBean, int showType) {
        //回复
        if (showType == CommentClickShowType.reply) {
            if (!PDUtils.isLogin()) {
                ProcessUtils.toOneKeyLoginActivity();
                return;
            }
            showInputDialog(selectCompBean,0);
        }
        //删除评论
        else if (showType == CommentClickShowType.delete) {
            if (!PDUtils.isLogin()) {
                ProcessUtils.toOneKeyLoginActivity();
                return;
            }
            new AlertDialog(getActivity()).builder()
                    .setTitle(ResUtils.getString(com.people.comment.R.string.del_comment_tip))
                    .setPositiveButton(ResUtils.getString(com.people.comment.R.string.res_cancel), v -> {

                    })
                    .setNegativeButton(ResUtils.getString(com.people.comment.R.string.yes_btn), v -> {
                        delComment(selectCompBean, 0);
                    })
                    .show();
        }
        //复制信息
        else if (showType == CommentClickShowType.copy) {
            boolean isCopySuccess = false;
            if (!StringUtils.isEmpty(selectCompBean.getOperDataList().get(0).getCommentInfo().getRealCommentContent())) {
                isCopySuccess = true;
                StrUtils.copy(selectCompBean.getOperDataList().get(0).getCommentInfo().getRealCommentContent());
            }
            //是否复制成功
            if (isCopySuccess) {
                ToastNightUtil.showShort(ResUtils.getString(com.people.comment.R.string.comment_copy_success));
            } else {
                ToastNightUtil.showShort(ResUtils.getString(com.people.comment.R.string.comment_copy_fail));
            }
        }
        //举报
        else if (showType == CommentClickShowType.report) {
            if (!PDUtils.isLogin()) {
                ProcessUtils.toOneKeyLoginActivity();
                return;
            }
            TransparentBean transparentBean = new TransparentBean();
            transparentBean.setContentId(selectCompBean.getOperDataList().get(0).getObjectId());
            transparentBean.setContentType(selectCompBean.getOperDataList().get(0).getObjectType());
            transparentBean.setTargetRelId(selectCompBean.getOperDataList().get(0).getRelId());
            transparentBean.setTargetRelType(selectCompBean.getOperDataList().get(0).getRelType()+"");
            transparentBean.setCommentId(String.valueOf(selectCompBean.getOperDataList().get(0).getCommentInfo().getCommentId()));
            ProcessUtils.goReport(GsonUtils.objectToJson(transparentBean), "0");

        }
    }

    /**
     * 发布评论信息
     */
    public void showInputDialog(CompBean selectCompBean,int position) {
//        this.submitPos = position;
        // 判断是否登录
        if (TextUtils.isEmpty(SpUtils.getUserToken())) {
            ProcessUtils.toOneKeyLoginActivity();
            return;
        }
        //初始化弹出框
        if (commitDialog == null) {
            commitDialog = new CommentCommitDialog(getActivity());
            // 2023/11/3 设置评论发布点击埋点数据
//            if (transparentBean != null) {
//                TrackContentBean trackContentBean = CommonTrack.getInstance().getTrackContentBean(pageName, pageId, contentId, contentType, targetTitle, "");
//                commitDialog.setTrackContentBean(trackContentBean);
//            }
            commitDialog.setCommitDialogListener(new CommitDialogListener() {
                @Override
                public void publish(String text) {
                    commitDialog.dismiss();
                    String comment = text.trim();
                    if (StringUtils.isEmpty(comment)) {
                        ToastNightUtil.showShort("您还未输入任何信息");
                        return;
                    }
                    commitDialog.clearEditText();
                    submitComment(selectCompBean,text, "2", "");
                    //发布评论
                }

                @Override
                public void getUnloadImg(ArrayList<String> images) {
                }
            });
        }
        //设置弹出框 hint
        if (null != commitDialog) {
            String replyUserName = "";
            if (selectCompBean != null && selectCompBean.getOperDataList() != null){
                ContentBean contentBean = selectCompBean.getOperDataList().get(0);
                if (contentBean != null){
                    if(contentBean.getRmhInfo() != null){
                        replyUserName = contentBean.getRmhInfo().getRmhName();
                    }
                }
            }
            if (position == -1) {
                commitDialog.showDefaultHint(bestNoticer);
            } else {
                if(StringUtils.isNotBlank(replyUserName)){
                    commitDialog.showUserName(replyUserName);
                }else{
                    commitDialog.showDefaultHint(bestNoticer);
                }
            }
            commitDialog.showWithSoftBoard();
        }

    }

    /**
     * 删除评论
     */
    private void delComment(CompBean compBean, int position) {
        if (null == commentViewModel) {
            initCommentViewmModel();
        }
        commentViewModel.delComment(compBean.getOperDataList().get(0).getCommentInfo().getCommentId(),
                compBean.getOperDataList().get(0).getObjectId(),compBean.getOperDataList().get(0).getCommentInfo().uuid, position);
    }

    private void initCommentViewmModel() {
        commentViewModel = getViewModel(CommentViewModel.class);
        commentViewModel.observeCommentListener(getActivity(), new ICommentDataNewListener() {
            @Override
            public void onGetCommentListSuccess(CommentListBean commentList) {

            }

            @Override
            public void onGetCommentListFail(int code, String msg) {

            }

            @Override
            public void onGetSecondCommentListSuccess(int position, CommentListBean childCommentList) {

            }

            @Override
            public void onGetSecondCommentListFail() {

            }

            @Override
            public void onSubmitPushCommentSuccess(CommentItem pushListBean, int position, String msg) {

            }

            @Override
            public void onSubmitPushCommentFail(int code, String msg) {

            }

            @Override
            public void onGetMastersAuthenticationListSuccess(List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {

            }

            @Override
            public void onGetMastersAuthenticationListFailure(String errorInfo, int listLevel) {

            }

            @Override
            public void onGetAllDataSuccess(List<CommentStatusBean> statusList, List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {

            }

            @Override
            public void onGetCommentStatusListFailure(String errorInfo, int listLevel) {

            }

            @Override
            public void delCommentSuccess(int freshPosition) {
                refreshData();
            }

            @Override
            public void delCommentFail(String e) {
                ToastNightUtil.showShort(e);
            }

            @Override
            public void onGetSingleMastersAuthenticationDataSuccess(PersonalInfoBean mMasterInfoBean, int freshPosition) {

            }

            @Override
            public void onGetLevelInfoBeanListSuccess(List<CommentItem> data, int freshStartIndex, int listLevel) {

            }
        });
    }

    /**
     * 发布评论
     *
     * @param text        内容
     * @param commentType
     * @param commentPics 图片地址
     */
    private void submitComment(CompBean selectCompBean,String text, String commentType, String commentPics) {
        if(commentViewModel == null){
            initCommentViewmModel();
        }
        commentViewModel.submitComment(text, commentType, commentPics, selectCompBean.getOperDataList().get(0).getObjectId()
                        , selectCompBean.getOperDataList().get(0).getObjectType(),
                        selectCompBean.getOperDataList().get(0).getRelId(), selectCompBean.getOperDataList().get(0).getRelType()+"", "-1", "-1",
                        selectCompBean.getOperDataList().get(0).getNewsTitle(), selectCompBean.getOperDataList().get(0).getKeyArticle()
                        , selectCompBean.getOperDataList().get(0).getContentRelId(), -1);

    }
}