ItemNewsHomeMenuTopLayoutManager.java 54 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 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
/*
 * Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
 */

package com.wd.capability.layout.page;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;


import com.wd.base.log.Logger;
import com.wd.capability.layout.R;
import com.wd.capability.layout.comp.ICompService;
import com.wd.capability.layout.comp.layoutmanager.ItemContainerManager;
import com.wd.capability.layout.constant.LaunchPageConstant;
import com.wd.capability.layout.constant.ProcessConstant;
import com.wd.capability.layout.fragment.ColumnFragment;
import com.wd.capability.layout.fragment.NewsHomeFragment;
import com.wd.capability.layout.listener.ColumnFragmentCallback;
import com.wd.capability.layout.page.data.IPaperPageListener;
import com.wd.capability.layout.page.data.PaperPageModel;
import com.wd.capability.layout.ui.widget.commonnavigator.HomeCommonNavigator;
import com.wd.capability.layout.ui.widget.commonnavigator.titles.TopNavEffectTitleView;
import com.wd.capability.layout.uitls.CompentLogicUtil;
import com.wd.capability.network.utils.NetworkUtil;
import com.wd.capability.network.cachedata.CacheData;
import com.wd.foundation.bean.custom.comp.PageBean;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.wdinterface.comp.IProcess;
import com.wd.foundation.wdinterface.constant.InterfaceConstant;
import com.wd.foundation.wdkit.constant.DefaultViewConstant;
import com.wd.foundation.wdkit.constant.EventConstants;
import com.wd.foundation.wdkit.imageglide.ImageUtils;

import com.wd.foundation.wdkit.utils.GrayManager;
import com.wd.foundation.wdkit.utils.ToastNightUtil;
import com.wd.foundation.wdkit.viewclick.BaseClickListener;
import com.wd.foundation.wdkit.view.DefaultView;
import com.wd.foundation.bean.custom.MenuBean;
import com.wd.foundation.bean.custom.SimpleTabBean;
import com.wd.foundation.bean.paper.PaperBean;
import com.wd.foundation.bean.paper.PaperNumInforListBean;
import com.wd.foundation.bean.paper.PaperPageBean;
import com.wd.foundation.bean.response.ChannelBean;
import com.wd.foundation.bean.response.PageTopNavBean;
import com.wd.foundation.wdkit.json.GsonUtils;
import com.wd.foundation.wdkit.system.DeviceUtil;
import com.wd.foundation.wdkit.utils.ScreenUtils;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.bean.utils.TimeUtil;
import com.wd.foundation.wdkit.utils.UiUtils;
import com.wd.foundation.wdkit.utils.ViewUtils;
import com.wd.foundation.wdkit.view.MarqueeView;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.router.ArouterServiceManager;
import com.wd.foundation.wdkitcore.scheduler.WComponent;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.JsonUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * 首页新闻菜单栏目样式<BR>
 *
 * @author liyubing
 * @version [V1.0.0, 2022/7/7]
 * @since V1.0.0
 */
public class ItemNewsHomeMenuTopLayoutManager extends ItemContainerManager<SimpleTabBean> {

    private static final String TAG = "ItemNewsHomeMenuTopLayoutManager";

    /**
     * 默认 频道名称选中 /未选中颜色 、下划线
     */
    private String TITLE_TEXT_SELECTED_COLOR = "#222222";
    private String TITLE_TEXT_UNSELECTED_COLOR = "#80222222";

    private String THEME_IMAGE_TXT_COLOR = "#000000";
    private String THEME_MENU_MORE_COLOR = "#000000";

    /**
     * 启动默认选中的channelId
     */
    private String defaultShowChannelId;

    private String TAB_LINE_URL = null;

    private SimpleTabBean mTabBean;

    private ViewPager2 viewPager;

    private FragmentAdapter fragmentAdapter;

    private RelativeLayout llHeadInfor;

    private MagicIndicator tabLayout;

    private FrameLayout flTab;

    /**
     * 页面背景
     */
    private ImageView pageBackground, ivCenter, ivIconLeft, ivRightIcon, ivToMusicChannel;
    private View vLineMusicChannel;
    private ImageView imgSearchManage;

    private FrameLayout grayFrameLayout;

    private DefaultView mErrorView;

    private ConstraintLayout clParent;

    private MenuBean bottomMenuBean;

    private LinearLayout llRight, llLeft;

    private MarqueeView mMarqueeView;

    private TextView tvRight;

    private HomeCommonNavigator commonNavigator;

    private CommonNavigatorAdapter commonNavigatorAdapter;

    /*
     * 占位、规避 当liveData多次调用observe时, 如果Observer使用lambda, 并且lamba中没有引用非静态变量或方法时, 可能就会出现crash! (为什么是可能, 可以看 后续)
     * */
    private int forLiveDataBus;

    private List<String> searchHotWordList;

    private PaperPageModel paperPageModel;

//    private CompAssistFetcher mDataFetcher;
    /**
     * 默认选中的第几个频道
     */
    private int defaultSelChannelIndex;

    public ItemNewsHomeMenuTopLayoutManager(MenuBean menuData) {
        this.bottomMenuBean = menuData;
    }

    /**
     * 切换横竖屏
     *
     * @param isLandscape 是否横屏
     */
    public void changeOrientation(boolean isLandscape) {
        if (flTab != null) {
            flTab.setVisibility(isLandscape ? View.GONE : View.VISIBLE);
        }
        if (pageBackground != null) {
            pageBackground.setVisibility(isLandscape ? View.GONE : View.VISIBLE);
        }
        if (imgSearchManage != null) {
            imgSearchManage.setVisibility(isLandscape ? View.GONE : View.VISIBLE);
        }

    }


    ViewPager2.OnPageChangeCallback onPageChangeListener = new ViewPager2.OnPageChangeCallback() {

        private int state = 0;

        private boolean fistFlag = false;

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            tabLayout.onPageScrolled(position, positionOffset, positionOffsetPixels);

            if (state == ViewPager2.SCROLL_STATE_SETTLING && fistFlag) {
                int newsIndex = viewPager.getCurrentItem();
                // 特殊频道
                ChannelBean tabBean = mTabBean.getTopNavChannelList().get(newsIndex);
                if (tabBean.isSpecialChannel()) {
                    // 特殊频道跳转方法
                    IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
                    process.specialChannelJumpPage(tabBean);
                    fistFlag = false;
                    int total = fragmentAdapter.getItemCount();
                    int oldIndex = position;
                    //向右滑动
                    if (newsIndex > oldIndex) {
                        int index = newsIndex + 1;

                        if (index == total) {
                            // 最后一笔数据
                            viewPager.setCurrentItem(oldIndex);
                        } else {
                            if (index <= total) {
                                ChannelBean adOne = mTabBean.getTopNavChannelList().get(index);
                                boolean oneFlag = process.checkSpacialChannel(adOne);
                                if (oneFlag) {
                                    index = index + 1;
                                }
                            }

                            if (index >= total) {
                                index = newsIndex - 1;
                            }
                            viewPager.setCurrentItem(index);

                        }
                        // 向左滑动
                    } else if (newsIndex <= oldIndex) {
                        int index = newsIndex - 1;
                        if (index < total) {
                            ChannelBean sOne = mTabBean.getTopNavChannelList().get(index);
                            boolean oneFlag = process.checkSpacialChannel(sOne);
                            if (oneFlag) {
                                index = index - 1;
                            }
                        }

                        if (index < 0) {
                            index = newsIndex + 1;
                        }
                        viewPager.setCurrentItem(index);
                    }
                }

            }
        }

        @Override
        public void onPageSelected(int position) {
            // 检测出特殊频道不跳转
//            ChannelBean tabBean = mTabBean.getTopNavChannelList().get(position);
//            if (tabBean.isSpecialChannel()) {
//
//            } else {
            tabLayout.onPageSelected(position);
            // 检测频道对应的页面是否开启了国殇
            ChannelBean menuData = ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), position);
            handleGrayViewByGrayFlag(menuData.isGrayFlag());
            // 埋点
//            GeneralTrack.getInstance().homeTabClick(menuData.getName(), menuData.getPageId(), menuData.getName());
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            this.state = state;
            if (state == ViewPager2.SCROLL_STATE_SETTLING) {
                fistFlag = true;
            }
            tabLayout.onPageScrollStateChanged(state);
        }
    };


    @Override
    public int getItemViewType() {
        return R.layout.page_item_layout_menu_layout_news;
    }


    @Override
    public void prepareItem(View itemView, int position) {
        Logger.t(TAG).d("prepareItem");
        mErrorView = ViewUtils.findViewById(itemView, R.id.default_view);
        viewPager = ViewUtils.findViewById(itemView, R.id.tab_fragment_container);
        tabLayout = ViewUtils.findViewById(itemView, R.id.tab_layout);
        flTab = ViewUtils.findViewById(itemView, R.id.flTab);
        llHeadInfor = ViewUtils.findViewById(itemView, R.id.llHeadInfor);
        pageBackground = ViewUtils.findViewById(itemView, R.id.fragment_top_bg_item);
        imgSearchManage = ViewUtils.findViewById(itemView, R.id.img_search_manage);
        clParent = ViewUtils.findViewById(itemView, R.id.clParent);
        grayFrameLayout = ViewUtils.findViewById(itemView, R.id.page_gray_frame_layout);

        llRight = ViewUtils.findViewById(itemView, R.id.llRight);

        llLeft = ViewUtils.findViewById(itemView, R.id.llLeft);

        ivCenter = ViewUtils.findViewById(itemView, R.id.ivCenter);

        tvRight = ViewUtils.findViewById(itemView, R.id.tvRight);

        ivRightIcon = ViewUtils.findViewById(itemView, R.id.ivRightIcon);
        ivIconLeft = ViewUtils.findViewById(itemView, R.id.ivIconLeft);
        //播报入口
        ivToMusicChannel = ViewUtils.findViewById(itemView, R.id.ivToMusicChannel);
        vLineMusicChannel = ViewUtils.findViewById(itemView, R.id.vLineMusicChannel);
        mMarqueeView = ViewUtils.findViewById(itemView, R.id.mMarqueeView);

        // 设置头部 距离
        setTopViewForFold();
        //夜间模式设置
        setNightModeColor(itemView.getContext());
        hideErrorView();
        //点击事件监听
        setClickListen(itemView);
        loadHeadViewSource();
        // 处理clParent 距底部距离
        FrameLayout.LayoutParams clParentLp = (FrameLayout.LayoutParams) clParent.getLayoutParams();
        clParentLp.bottomMargin = (int) clParent.getContext().getResources().getDimension(R.dimen.rmrb_dp36_5);
        clParent.setLayoutParams(clParentLp);
    }

    /**
     * 点击事件监听
     */
    private void setClickListen(View itemView) {
        IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
        if (process == null) {
            Logger.t(TAG).e("setClickListen, IProcess has not impl");
        }
        ViewUtils.findViewById(itemView, R.id.ivCenter).setOnClickListener(new BaseClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                process.goToPaperActivity();
            }
        });
        //跳转到播报频道 pageId:21003, channelId:2066, 名称:播报
        ViewUtils.findViewById(itemView, R.id.llToMusicChannel).setOnClickListener(new BaseClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                ChannelBean channelBean = new ChannelBean();
                channelBean.setChannelId(ProcessConstant.CHANNEL_ID_VOICE);
                channelBean.setPageId(ProcessConstant.PAGE_ID_VOICE);
                channelBean.setName("播报");
                process.specialChannelJumpPage(channelBean);
            }
        });
        ViewUtils.findViewById(itemView, R.id.llDialyNews).setOnClickListener(new BaseClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
//                GeneralTrack.getInstance().E_MEN_CLICK(bottomMenuBean.getTitle(), bottomMenuBean.getNavId());
                llRight.setClickable(false);
                process.goToCommonSubjectPage(llRight);
            }
        });

        llLeft.setOnClickListener(new BaseClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                int marqueePosition = -1;
                if (searchHotWordList != null && searchHotWordList.size() > 0 && mMarqueeView != null) {
                    marqueePosition = mMarqueeView.getPosition();
                }
                process.toSearchActivity(marqueePosition, bottomMenuBean.getTitle());

//                CommonTrack.getInstance().clickSearchButton(bottomMenuBean.getTitle(), bottomMenuBean.getNavId());
            }
        });
        mMarqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
            @Override
            public void onItemClick(int position, TextView textView) {
                if (searchHotWordList != null) {
                    process.toSearchActivity(position, bottomMenuBean.getTitle());
                } else {
                    process.toSearchActivity(-1, bottomMenuBean.getTitle());
                }

//                CommonTrack.getInstance().clickSearchButton(bottomMenuBean.getTitle(), bottomMenuBean.getNavId());
            }
        });
    }

    /**
     * 折叠屏展开-折叠时候调用
     */
    public void setTopViewForFold() {
        if (getFragment() != null) {
            //   int status_height = StatusBarCompat.getStatusBarHeight(getFragment().getActivity());
            int status_height = (int) flTab.getContext().getResources().getDimension(R.dimen.rmrb_dp44);//104;
            initTopView(status_height);
            clParent.setVisibility(View.VISIBLE);
        }
    }


    @Override
    public void bindItem(View itemView, int position, SimpleTabBean data) {
        if (data == null) {
            return;
        }
        Logger.t(TAG).d("bindItem position:" + position + ",data.getMenus:" + data.getTopNavChannelList());

        if (data.getTopNavChannelList() != null && data.getTopNavChannelList().size() > 0) {
            imgSearchManage.setVisibility(View.VISIBLE);
        } else {
            showErrorView(data.errorCode);
            return;
        }
        hideErrorView();
        mTabBean = data;

        imgSearchManage.setOnClickListener(new BaseClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
                if (process == null) {
                    Logger.t(TAG).e("imgSearchManage OnClickListener, IProcess has not impl");
                }
                String tabId = mTabBean.getTabChannleId();
                Fragment fragment = getFragment();
                process.goToNavBarActivity(fragment, tabId);
            }
        });

        if (fragmentAdapter != null) {

            int currentIndex = viewPager.getCurrentItem();
            int cacheIndex = currentIndex;

            // 检测出指定跳转的频道
            if (!TextUtils.isEmpty(bottomMenuBean.jumpChannelId)) {
                cacheIndex = getDefaultSelectIndex();
                bottomMenuBean.jumpChannelId = null;
            } else {
                int count = fragmentAdapter.getItemCount();
                if (cacheIndex + 1 > count) {
                    cacheIndex = getDefaultSelectIndex();
                } else {
                    if (mTabBean.initTabData) {
                        cacheIndex = getDefaultSelectIndex();
                    }
                }
            }

            // 检测出特殊频道,按默认频道走
            ChannelBean tempChannelBean = mTabBean.getTopNavChannelList().get(cacheIndex);
            if (tempChannelBean.isSpecialChannel()) {
                cacheIndex = getDefaultSelectIndex();
                // 特殊频道跳转方法
                IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
                process.specialChannelJumpPage(tempChannelBean);
            }
            //  viewPager.setCurrentItem(cacheIndex);
            int finalCacheIndex = cacheIndex;
            // 更新数据
            fragmentAdapter.prepare(data);
            //更新频道策略
            updateChannelStrategy();
            viewPager.setOffscreenPageLimit(fragmentAdapter.getItemCount());
            fragmentAdapter.notifyDataSetChanged();
            commonNavigatorAdapter.notifyDataSetChanged();
            //initMagicIndicator();
            viewPager.post(new Runnable() {
                @Override
                public void run() {
                    viewPager.setCurrentItem(finalCacheIndex, false);
                    onPageChangeListener.onPageSelected(finalCacheIndex);
                }
            });

            mTabBean.initTabData = false;
            return;
        }
        mTabBean.initTabData = false;
        commonNavigator = new HomeCommonNavigator(tabLayout.getContext());
        setViewPager2TouchSlop();
        fragmentAdapter = createFragmentAdapter(data);
        viewPager.setOffscreenPageLimit(fragmentAdapter.getItemCount());
        viewPager.setAdapter(fragmentAdapter);
        // 去除viewpage 阴影
        View childView = viewPager.getChildAt(0);
        if (childView instanceof RecyclerView) {
            childView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        }

        initMagicIndicator();
        viewPager.registerOnPageChangeCallback(onPageChangeListener);

        setDefaultTab();
        // 注册Event 事件
        registerEventBus();

        grayUiPage(false);
        //关键字
//        obtainKeyWord();
        //接口合并,搜索词处理
        dealHints();
        //提前加载电子报->随机延迟5~10秒
//        ThreadPoolUtils.postToMainDelay(new Runnable() {
//            @Override
//            public void run() {
//                loadMorningAndNightData();
//            }
//        }, RandomUtil.getRandomDelaySeconds(5000, 10*1000));
//
//        return position;
    }

    /**
     * 接口合并,搜索词处理
     */
    private void dealHints() {
        if (ArrayUtils.isNotEmpty(searchHotWordList)) {
            return;
        }
        if (ArrayUtils.isEmpty(LaunchPageConstant.hintsBeans)) {
            List<String> list = new ArrayList<>();
            list.add("搜索");
            mMarqueeView.startWithList(list);
        } else {
            searchHotWordList = LaunchPageConstant.hintsBeans;
            mMarqueeView.startWithList(LaunchPageConstant.hintsBeans);
        }
    }

    /**
     * 提前加载
     * 每天首次启动,缓存数据,后续启动不调用
     */
    private void loadMorningAndNightData() {
        //不用请求
        String paperTodayMd5 = SpUtils.getPaperTodayMd5();
        if (StringUtils.isNotBlank(paperTodayMd5)) {
            String[] split = paperTodayMd5.split("_");
            if (split != null) {
                String date = split[0];
                String currentDate = TimeUtil.getCurrentDate();
                String pagePic = split[2];
                if (date.equals(currentDate)) {
                    //预加载缓存下第一页图片
                    ImageUtils.getInstance().preloadImage(getFragment().getContext(), pagePic);
                    return;
                }
            }
        }

        // 提前加载电子报第一版面数据
        if (paperPageModel == null) {
            //566d / 378d;
            double unproprotion = 1018d / 720d;
            int screenWith = DeviceUtil.getDeviceWidth();
            double paddingLr = UiUtils.dp2px(10) * 2d;
            double maxWidth = screenWith - paddingLr;
            int maxWith = (int) CompentLogicUtil.checkElePaperImageHeight(maxWidth, getFragment().getActivity());
            maxWidth = maxWith;
            double paperCanvasWidth = maxWidth - UiUtils.dp2px(26);
            double paperCanvasHeight = paperCanvasWidth * unproprotion;
            String xy = paperCanvasWidth + "x" + paperCanvasHeight;
            if (getFragment() == null || getFragment().isDetached()) {
                //Fragment如果Detached就不往下执行了,否则一样异常
                return;
            }
            paperPageModel = new ViewModelProvider(getFragment()).get(PaperPageModel.class);
            paperPageModel.setElWh(xy);
            paperPageModel.observeChannelListener(getFragment(), new IPaperPageListener() {
                @Override
                public void onSuccess(PaperBean list) {
                    if (list.getList() != null && list.getList().size() > 0) {
                        PaperPageBean paperPageBean = list.getList().get(0);
                        String pagePic = paperPageBean.getPagePic();
                        ImageUtils.getInstance().preloadImage(getFragment().getContext(), pagePic);
                    }

                }

                @Override
                public void onPageNumSuccess(List<PaperNumInforListBean> listBeans, String date) {

                }

                @Override
                public void onError(int code, String message) {

                }
            });
        }
        paperPageModel.requestPaperList(null, true, true);
    }


    /**
     * 获取热词
     */
    private void obtainKeyWord() {

//        if (mDataFetcher == null) {
//            mDataFetcher = new CompAssistFetcher();
//        }
//
//        mDataFetcher.getSearchHints(new SearchHotWordListener() {
//            @Override
//            public void onGetSearchHintsSuccess(List<String> hintsBeans) {
//
//                if (hintsBeans != null && hintsBeans.size() > 0) {
//                    searchHotWordList = hintsBeans;
//                    mMarqueeView.startWithList(hintsBeans);
//                } else {
//                    List<String> list = new ArrayList<>();
//                    list.add("搜索");
//                    mMarqueeView.startWithList(list);
//                }
//
//            }
//
//            @Override
//            public void onGetSearchHintsFailure() {
//                List<String> list = new ArrayList<>();
//                list.add("搜索");
//                mMarqueeView.startWithList(list);
//            }
//        });
    }


    /**
     * 初始化顶部导航
     */
    private void initMagicIndicator() {
        commonNavigator.setLeftPadding((int) commonNavigator.getContext().getResources().getDimension(R.dimen.rmrb_dp8));

        commonNavigatorAdapter = new CommonNavigatorAdapter() {

            @Override
            public int getCount() {
                return getSubItemCount();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {

                ChannelBean tabBean = mTabBean.getTopNavChannelList().get(index);
                tabBean.setFontCColor(TITLE_TEXT_SELECTED_COLOR);
                tabBean.setFontColor(TITLE_TEXT_UNSELECTED_COLOR);

                TopNavEffectTitleView topNavEffectTitleView = new TopNavEffectTitleView(context, TAB_LINE_URL);
                topNavEffectTitleView.setChannelBean(tabBean);

                topNavEffectTitleView.setOnClickListener(new BaseClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        int currentIndex = viewPager.getCurrentItem();
                        if (currentIndex == index) {
                            ChannelBean menuData = ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), currentIndex);
                            Fragment fragment = fragmentAdapter.getFragmentByPageId(menuData.getPageId());
                            if (fragment != null) {
                                if (fragment instanceof ColumnFragment) {
                                    ColumnFragment columnFragment = (ColumnFragment) fragment;
                                    columnFragment.clickTabAutoRefresh();

                                    // 埋点
//                                    GeneralTrack.getInstance().homeTabClick(menuData.getName(), menuData.getPageId(), menuData.getName());
                                }
                            }
                        } else {
                            // 特殊频道
                            ChannelBean tabBean = mTabBean.getTopNavChannelList().get(index);
                            if (tabBean.isSpecialChannel()) {//
                                // 特殊频道跳转方法
                                IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
                                process.specialChannelJumpPage(tabBean);
                            } else {
                                viewPager.setCurrentItem(index);
                            }
                        }

                    }
                });
                return topNavEffectTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                return null;
            }
        };

        commonNavigator.setAdapter(commonNavigatorAdapter);
        tabLayout.setNavigator(commonNavigator);

    }

    @Override
    public void onResume() {
        super.onResume();
        // Log.e("DDDDSSS", "onResume");
//        if (mMarqueeView != null) {
//            mMarqueeView.startAnimal();
//        }

    }

    @Override
    public void onPause() {
        super.onPause();
        //  Log.e("DDDDSSS","onPause");
//        if (mMarqueeView != null) {
//            mMarqueeView.stopAnimal();
//        }
    }

    @Override
    public void onDestory() {
        super.onDestory();
        if (viewPager != null) {
            viewPager.unregisterOnPageChangeCallback(onPageChangeListener);
            commonNavigator = null;
        }

//        if (mMarqueeView != null) {
//            mMarqueeView.stopAnimal();
//        }

        LiveDataBus.getInstance()
                .with(EventConstants.COLUMN_NAVIGATION_SELECT,
                        com.wd.room.entity.ChannelBean.class).removeObservers(getFragment());
        LiveDataBus.getInstance()
                .with(EventConstants.USER_ALREADY_LOGIN, Boolean.class).removeObservers(getFragment());
        if (mTabBean != null) {
            LiveDataBus.getInstance()
                    .with(EventConstants.HOME_TAB_REFRESH + mTabBean.getTabChannleId(), Boolean.class).removeObservers(getFragment());
        }

    }

    /**
     * 动态设置ViewPager2 灵敏度
     */
    public void setViewPager2TouchSlop() {
        try {
            Field mRecyclerView = ViewPager2.class.getDeclaredField("mRecyclerView");
            mRecyclerView.setAccessible(true);
            RecyclerView recyclerView = (RecyclerView) mRecyclerView.get(viewPager);

            Field mTouchSlop = RecyclerView.class.getDeclaredField("mTouchSlop");
            mTouchSlop.setAccessible(true);
            int touchSlop = (int) mTouchSlop.get(recyclerView);

            mTouchSlop.set(recyclerView, touchSlop * 4);

        } catch (Exception e) {
            e.printStackTrace();
            Log.e("反射异常", e.getMessage());
        }
    }


    /**
     * 设置默认状态的 Tab
     */
    public void setDefaultTab() {
        // 设置默认选中
        if (tabLayout != null) {
            int selectIndex = getDefaultSelectIndex();
            defaultSelChannelIndex = selectIndex;
            int currentIndex = viewPager.getCurrentItem();
            if (currentIndex != selectIndex) {
                viewPager.setCurrentItem(selectIndex, false);
            }
        }
    }

    /**
     * 设置头部 距离
     *
     * @param topMargin
     */
    private void initTopView(int topMargin) {

        ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) viewPager.getLayoutParams();
        params.topMargin = topMargin + (int) tabLayout.getContext().getResources().getDimension(R.dimen.rmrb_dp44)
                + (int) tabLayout.getContext().getResources().getDimension(R.dimen.rmrb_dp32) + (int) tabLayout.getContext().getResources().getDimension(R.dimen.rmrb_dp6);
        viewPager.setLayoutParams(params);

        ConstraintLayout.LayoutParams llHeadInforParams = (ConstraintLayout.LayoutParams) llHeadInfor.getLayoutParams();
        llHeadInforParams.topMargin = topMargin + (int) tabLayout.getContext().getResources().getDimension(R.dimen.rmrb_dp6);

        // 普通导航栏
        ConstraintLayout.LayoutParams flTabLp = (ConstraintLayout.LayoutParams) flTab.getLayoutParams();
        flTabLp.rightMargin = (int) flTab.getContext().getResources().getDimension(R.dimen.rmrb_dp40);
        int withS = ScreenUtils.getScreenWidth() - flTabLp.leftMargin - flTabLp.rightMargin;
        flTabLp.width = withS;
        flTab.setLayoutParams(flTabLp);
        // tabLayout.setTabGravity(TabLayout.GRAVITY_START);
    }


    /**
     * 注册EventBus接收器
     */
    private void registerEventBus() {
        // 注册页面刷新
        LiveDataBus.getInstance()
                .with(EventConstants.HOME_TAB_REFRESH + mTabBean.getTabChannleId(), Boolean.class)
                .observe(getFragment(), new Observer<Boolean>() {
                    @Override
                    public void onChanged(Boolean flag) {
                        int currentIndex = viewPager.getCurrentItem();
                        ChannelBean menuData = ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), currentIndex);
                        Fragment fragment = fragmentAdapter.getFragmentByPageId(menuData.getPageId());
                        if (fragment != null) {
                            if (fragment instanceof ColumnFragment) {
                                ColumnFragment columnFragment = (ColumnFragment) fragment;
                                columnFragment.clickTabAutoRefresh();
                            }
                        }
                    }
                });


        // 注册登录EventBus
        LiveDataBus.getInstance().with(EventConstants.USER_ALREADY_LOGIN, Boolean.class).observe(getFragment(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {

                if (fragmentAdapter != null) {
                    ArrayList<Fragment> list = fragmentAdapter.fragments;
                    if (list != null) {
                        for (Fragment fragment : list) {
                            if (fragment instanceof ColumnFragment) {
                                ColumnFragment columnFragment = (ColumnFragment) fragment;
                                columnFragment.handlerLoginLogic(aBoolean);
                            }

                        }
                    }
                }
            }
        });

        //切换指定栏目
        LiveDataBus.getInstance().with(EventConstants.COLUMN_NAVIGATION_SELECT,
                com.wd.room.entity.ChannelBean.class).observe(getFragment(),
                new Observer<com.wd.room.entity.ChannelBean>() {
            @Override
            public void onChanged(com.wd.room.entity.ChannelBean channelEntity) {
                if (channelEntity != null) {
                    ChannelBean channelBean = convertBean(channelEntity);
                    if (channelBean.isSpecialChannel()) {//
                        // 特殊频道跳转方法
                        IProcess process = ArouterServiceManager.provide(InterfaceConstant.PATH_COMP_PROCESS);
                        process.specialChannelJumpPage(channelBean);
                    } else {
                        forLiveDataBus = 1;
                        setTabSelectByChannelId(channelBean.getChannelId());
                    }
                }
            }
        });

        /**
         * 启动接口成功
         */
        LiveDataBus.getInstance().with(EventConstants.LAUNCHPAGE_SUCCESS, Boolean.class).observe(getFragment(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                dealHints();
            }
        });
    }

    private ChannelBean convertBean(com.wd.room.entity.ChannelBean channelEntity) {
        String objectToJson = JsonUtils.convertObjectToJson(channelEntity);
        ChannelBean channelBean = JsonUtils.convertJsonToObject(objectToJson, ChannelBean.class);
        return channelBean;
    }

    /**
     * 获取默认tab index
     *
     * @return
     */
    private int getDefaultSelectIndex() {
        int defaultIndex = 0;
        String jumpChannelId = bottomMenuBean.jumpChannelId;
        if (TextUtils.isEmpty(jumpChannelId)) {
            String preferencesChannelId = SpUtils.getKeyDefaultChannelId();
            //首选设置
            if (!TextUtils.isEmpty(preferencesChannelId) && mTabBean != null
                    && mTabBean.getTopNavChannelList() != null
                    && mTabBean.getTopNavChannelList().size() > 1) {
                int oldPosition = -1;
                for (int i = 0; i < mTabBean.getTopNavChannelList().size(); i++) {
                    if (preferencesChannelId.equals(mTabBean.getTopNavChannelList().get(i).getChannelId())) {
                        oldPosition = i;
                        break;
                    }
                }
                if (oldPosition > 0) {
                    return oldPosition;
                }
            } else {
                List<ChannelBean> menus = mTabBean.getTopNavChannelList();
                SpUtils.setKeyDefaultChannelId(menus.get(defaultIndex).getChannelId());
                return defaultIndex;
            }
        } else {
            List<ChannelBean> menus = mTabBean.getTopNavChannelList();
            int size = menus.size();
            for (int i = 0; i < size; i++) {
                ChannelBean bean = menus.get(i);
                if (jumpChannelId.equals(bean.getChannelId())) {
                    defaultIndex = i;
                    defaultShowChannelId = bean.getChannelId();
                    break;
                }
            }
        }

        return defaultIndex;
    }

    private FragmentAdapter createFragmentAdapter(SimpleTabBean data) {
        if (mFragment == null) {
            throw new IllegalArgumentException("Presenter of TabLayoutManager is invalidate");
        }
        FragmentAdapter adapter = new FragmentAdapter(mFragment, this);
        adapter.prepare(data);
        return adapter;
    }


    private ChannelBean getSubItem(int i) {
        if (mTabBean == null || ArrayUtils.isEmpty(mTabBean.getTopNavChannelList())) {
            // 默认pageId
            Logger.t(TAG).e("getItem, SimpleTabBean is null or menus is empty");
            return null;
        }
        return ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), i);
    }

    private int getSubItemCount() {
        if (mTabBean == null) {
            return 0;
        }
        return ArrayUtils.getListSize(mTabBean.getTopNavChannelList());

    }


    /**
     * 获取菜单导航栏里,当前展示fragment
     *
     * @return 当前fragment
     */
    public Fragment getCurFragment() {
        if (fragmentAdapter == null) {
            return null;
        }

        ChannelBean menuData = ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), viewPager.getCurrentItem());
        Fragment fragment = fragmentAdapter.getFragmentByPageId(menuData.getPageId());
        return fragment;
    }

    /**
     * 加载头部资源
     */
    public void loadHeadViewSource() {

        boolean isNightMode = SpUtils.isNightMode();
        // 加载背景图
        String topBackgroundImageUrl = bottomMenuBean.getBackgroundUrl();
        int dropDownAnimationColor = bottomMenuBean.getDropDownAnimationColor();

        ImageUtils.getInstance().homeThemeImageLoadAndSave(pageBackground, 0, topBackgroundImageUrl,
                isNightMode ? R.drawable.shape_ellipse_white_home_y : R.drawable.shape_ellipse_white_home);

        // log
        String logUrl = bottomMenuBean.getLogoUrl();
        if (!TextUtils.isEmpty(logUrl)) {
            ImageUtils.getInstance().loadImage(ivCenter, logUrl, R.drawable.bg_news_home_rmrb_log);
        } else {
            ivCenter.setImageResource(R.drawable.bg_news_home_rmrb_log);
        }
        // 顶部左右文字和icon颜色
        String color = bottomMenuBean.getSearchBothColor();
        if (StringUtils.isEmpty(color)) {
            color = THEME_IMAGE_TXT_COLOR;
        }
        ivIconLeft.setColorFilter(Color.parseColor(addAlphaColorForPercent(color, 128)), PorterDuff.Mode.SRC_IN);
//        ivIconLeft.setImageAlpha(128);
        ivRightIcon.setColorFilter(Color.parseColor(addAlphaColorForPercent(color, 128)), PorterDuff.Mode.SRC_IN);
//        ivRightIcon.setImageAlpha(128);
        ivToMusicChannel.setColorFilter(Color.parseColor(addAlphaColorForPercent(color, 128)), PorterDuff.Mode.SRC_IN);
//        ivToMusicChannel.setImageAlpha(128);
        vLineMusicChannel.setBackgroundColor(Color.parseColor(addAlphaColorForPercent(color, 51)));
        mMarqueeView.setTextColor(Color.parseColor(addAlphaColorForPercent(color, 128)));
        tvRight.setTextColor(Color.parseColor(addAlphaColorForPercent(color, 128)));

        // 搜索背景框url
        String searchUrl = bottomMenuBean.getSearchUrl();
        if (!TextUtils.isEmpty(searchUrl)) {
            ImageUtils.loadBitmapListener(llLeft.getContext(), searchUrl, llLeft, R.mipmap.bg_news_home_top_left);
        }

        //早晚报背景框
        String morningAndEveningUrl = bottomMenuBean.getMorningAndEveningUrl();
        if (!TextUtils.isEmpty(morningAndEveningUrl)) {
            ImageUtils.loadBitmapListener(llRight.getContext(), morningAndEveningUrl, llRight, R.mipmap.bg_news_home_top_right);
        }
        // 频道更多icon
        String channelMoreColor = bottomMenuBean.getChannelMoreColor();
        if (TextUtils.isEmpty(channelMoreColor)) {
            channelMoreColor = THEME_MENU_MORE_COLOR;
        }
//        imgSearchManage.setImageAlpha(128);
        imgSearchManage.setColorFilter(Color.parseColor(addAlphaColorForPercent(channelMoreColor, 128)), PorterDuff.Mode.SRC_IN);


        //顶部频道导航栏颜色
        if (!TextUtils.isEmpty(bottomMenuBean.getChannelChooseColor())) {
            TITLE_TEXT_SELECTED_COLOR = bottomMenuBean.getChannelChooseColor();
        }
        if (!TextUtils.isEmpty(bottomMenuBean.getChannelChooseCColor())) {
            TITLE_TEXT_UNSELECTED_COLOR = addAlphaColorForPercent(bottomMenuBean.getChannelChooseCColor(), 128);
        }
        // 下划线
        if (!TextUtils.isEmpty(bottomMenuBean.getChannelChooseActionUrl())) {
            TAB_LINE_URL = bottomMenuBean.getChannelChooseActionUrl();
        }


    }


    /**
     * ViewPager的adapter
     */
    private class FragmentAdapter extends FragmentStateAdapter {

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

        private SimpleTabBean mSimpleTabBean;

        private int topMarginInt;

        private ItemNewsHomeMenuTopLayoutManager layoutManager;

        public FragmentAdapter(Fragment fragment, ItemNewsHomeMenuTopLayoutManager layoutManager) {
            super(fragment);
            this.layoutManager = layoutManager;
            topMarginInt = 0;
        }

        void prepare(SimpleTabBean data) {
            this.mSimpleTabBean = data;
            int cnt = mSimpleTabBean.getTopNavChannelList() == null ? 0 : mSimpleTabBean.getTopNavChannelList().size();
            for (int i = 0; i < cnt; ++i) {
                ChannelBean menuData = ArrayUtils.getListElement(mSimpleTabBean.getTopNavChannelList(), i);
                if (menuData == null) {
                } else {
                    String channelId = menuData.getChannelId();
                    // 检测频道是否需要开启国殇模式
                    boolean grayFlag = layoutManager.checkPageChannelGray(channelId);
                    menuData.setGrayFlag(grayFlag);
                }
            }

        }


        /**
         * 根据pageid 获取fragment
         *
         * @param pageId
         * @return
         */
        private Fragment getFragmentByPageId(String pageId) {
            // 获取指定位置的fragment
            Fragment pageFragment = null;
            for (Fragment fragment : fragments) {

                if (fragment instanceof ColumnFragment) {
                    ColumnFragment columnFragment = (ColumnFragment) fragment;
                    if (pageId.equals(columnFragment.mPageId)) {
                        pageFragment = fragment;
                        break;
                    }
                }
            }
            return pageFragment;
        }

        @NonNull
        @Override
        public Fragment createFragment(int i) {

            Logger.t(TAG).d("getItem " + i);
            //空 menu数据处理
            boolean emptyFlag = false;
            if (mSimpleTabBean == null || ArrayUtils.isEmpty(mSimpleTabBean.getTopNavChannelList())) {
                // 默认pageId
                Logger.t(TAG).e("getItem, SimpleTabBean is null or menus is empty");
                emptyFlag = true;
            }
            ChannelBean menuData = ArrayUtils.getListElement(mSimpleTabBean.getTopNavChannelList(), i);
            if (menuData == null) {
                // 默认pageId
                Logger.t(TAG).e("getItem, menuData or action is null");
                emptyFlag = true;
            }

            if (emptyFlag) {
                Fragment fragment = WComponent.getService(ICompService.class).createDefaultFragment();
                collectionFragment(fragment, i);
                return fragment;
            }

            String pageId = menuData.getPageId();
            String channelId = menuData.getChannelId();
            //时间线、推荐
            int channelStrategy = menuData.getChannelStrategy();
            String tabChannelId = mTabBean.getTabChannleId();
            //之前版本频道保存数据库没有这个字段导致不更新的数据库表的情况下没有值
            if (0 == channelStrategy) {
                //从缓存取
                CacheData pageTopNavData = CacheData.getLocalCacheDataNoClear(CacheData.channelCacheDataKey + tabChannelId);
                if (pageTopNavData != null && !StringUtils.isBlank(pageTopNavData.getNetWorkData())) {
                    // 缓存数据
                    String netWorkData = pageTopNavData.getNetWorkData();
                    PageTopNavBean pageTopNavBean = GsonUtils.fromJson(netWorkData, PageTopNavBean.class);
                    List<ChannelBean> topNavChannelList = pageTopNavBean.getTopNavChannelList();
                    for (ChannelBean channelBean : topNavChannelList) {
                        if (channelBean != null && channelId.equals(channelBean.getChannelId())) {
                            channelStrategy = channelBean.getChannelStrategy();
//                            Logger.e("tabChannelId == 匹配成功?"+channelBean.getName()+"?channelStrategy=="+channelStrategy);
                            break;
                        }
                    }
                }
            }

            // 检测频道是否需要开启国殇模式
            boolean grayFlag = layoutManager.checkPageChannelGray(channelId);
            // Log.e("DDDDSSS", "menuData=" + menuData.getName() + "  grayFlag=" + grayFlag + "  " + menuData.isGrayFlag());
            menuData.setGrayFlag(grayFlag);

            int dropDownAnimationColor = bottomMenuBean.getDropDownAnimationColor();

            ColumnFragment mColumnFragment = ColumnFragment.newInstance(pageId, mTabBean.getTabChannleId(),
                    topMarginInt, grayFlag, false, dropDownAnimationColor, channelStrategy);
            mColumnFragment.setColumnFragmentCallback(columnFragmentCallback);
            mColumnFragment.setSuperRootLayout(grayFrameLayout);
            if (defaultSelChannelIndex == i) {
                //启动默认选中的
                mColumnFragment.setDefaultShowChannel(true);
            }
            collectionFragment(mColumnFragment, i);

            return mColumnFragment;

        }

        @Override
        public int getItemCount() {
            if (mSimpleTabBean == null) {
                return 0;
            }
            return ArrayUtils.getListSize(mSimpleTabBean.getTopNavChannelList());
        }


        /**
         * 如果使用ViewPager2+FragmentStateAdapter的时候,其Fragment数据是动态变化的话,
         * 那么一定要重写getItemId和containsItem两个方法。并且给每个Fragment定义一个不重复的id。
         * 也就是getItemId()获取到的id不能重复保证唯一性,以免出现因为缓存造成页面信息异常。
         * 意在使用channelId作为通过getItemId方法获取获得id作为key,来缓存fragment
         *
         * @param position Adapter position
         * @return
         */
        @Override
        public long getItemId(int position) {
            ChannelBean menuData = ArrayUtils.getListElement(mSimpleTabBean.getTopNavChannelList(), position);
            if (menuData == null) {
                return super.getItemId(position);
            }
            String channelId = menuData.getChannelId();
            if (TextUtils.isEmpty(channelId)) {
                return super.getItemId(position);
            } else {
                int channelIdInt = Integer.parseInt(channelId);
                return channelIdInt;
            }
        }

        @Override
        public boolean containsItem(long itemId) {
            if (ArrayUtils.isNotEmpty(fragments)) {
                for (Fragment fragment : fragments) {
                    if (fragment.getId() == itemId) {
                        return true;
                    }
                }
            }
            return super.containsItem(itemId);
        }

        /**
         * 收集fragment
         *
         * @param fragment
         * @param i
         */
        private void collectionFragment(Fragment fragment, int i) {

            fragments.add(fragment);
        }
    }

    private ColumnFragmentCallback columnFragmentCallback = new ColumnFragmentCallback() {
        @Override
        public void userRefreshAction() {
            obtainKeyWord();
        }
    };

    /**
     * 检测频道id是否要开启国殇
     *
     * @param channelId
     * @return
     */
    private boolean checkPageChannelGray(String channelId) {

        //检测是否开启国殇模式
        List<String> channelList = null;
        if (bottomMenuBean.isTabNew()) {
            // 新闻
            channelList = GrayManager.getInstance().newsChannelList;
        }
        boolean grayFlag = GrayManager.getInstance().checkChannelHaveGrayView(channelId, channelList);

        return grayFlag;
    }


    /**
     * 添加蒙层 或 清理蒙层
     *
     * @param grayFlag true:添加;false:清理
     */
    private void handleGrayViewByGrayFlag(boolean grayFlag) {

        if (grayFlag) {
            GrayManager.getInstance().setLayerGrayType(pageBackground);
            GrayManager.getInstance().setLayerGrayType(flTab);
            GrayManager.getInstance().setLayerGrayType(imgSearchManage);
            GrayManager.getInstance().setLayerGrayType(llHeadInfor);
        } else {
            GrayManager.getInstance().clearLayerGray(pageBackground);
            GrayManager.getInstance().clearLayerGray(flTab);
            GrayManager.getInstance().clearLayerGray(imgSearchManage);
            GrayManager.getInstance().clearLayerGray(llHeadInfor);
        }

    }


    /**
     * 显示错误视图
     */
    private void showErrorView(int type) {

        if (!NetworkUtil.isNetAvailable()) {
            type = DefaultViewConstant.TYPE_NO_NETWORK;
        }
        mErrorView.setRetryBtnClickListener(new DefaultView.RetryClickListener() {
            @Override
            public void onRetryClick() {
                hideErrorView();
                Fragment fragment = getFragment();
                if (fragment instanceof NewsHomeFragment) {
                    NewsHomeFragment homeFragment = (NewsHomeFragment) fragment;
                    homeFragment.request();
                }
            }
        });
        mErrorView.show(type);
        ViewUtils.setVisible(clParent, View.GONE);
    }

    /**
     * 隐藏错误视图
     */
    private void hideErrorView() {

        if (mErrorView != null) {
            mErrorView.hide();
        }

        ViewUtils.setVisible(clParent, View.VISIBLE);
    }


    /**
     * 切换到指定Tab
     */
    public void setTabSelectByChannelId(String channelId) {
        // 设置默认选中
        if (tabLayout != null && mTabBean != null && mTabBean.getTopNavChannelList() != null) {
            int selectIndex = -1;
            for (int i = 0; i < mTabBean.getTopNavChannelList().size(); i++) {
                if (channelId.equals(mTabBean.getTopNavChannelList().get(i).getChannelId())) {
                    selectIndex = i;
                    break;
                }
            }
            if (selectIndex != -1 && viewPager.getCurrentItem() != selectIndex) {
                viewPager.setCurrentItem(selectIndex);
            }
        }
    }


    /**
     * 获取顶部视图
     *
     * @return
     */
    public View getTopTitleView() {
        return llHeadInfor;
    }


    /**
     * 国殇模式
     *
     * @param grayUiPage true: 对ColumnFragment国殇;false:不对ColumnFragment国殇
     */
    public void grayUiPage(boolean grayUiPage) {
        // 检测频道对应的页面是否开启了国殇
        int currentIndex = viewPager.getCurrentItem();
        ChannelBean menuData = ArrayUtils.getListElement(mTabBean.getTopNavChannelList(), currentIndex);
        String channelId = menuData.getChannelId();
        boolean grayFlag = checkPageChannelGray(channelId);
        if (grayFlag) {
            menuData.setGrayFlag(grayFlag);
            handleGrayViewByGrayFlag(menuData.isGrayFlag());
            if (grayUiPage) {
                Fragment childeFragment = getCurFragment();
                if (childeFragment != null) {
                    ColumnFragment columnFragment = (ColumnFragment) childeFragment;
                    columnFragment.grayUiPage();
                }
            }

        }
        if (GrayManager.getInstance().switchOpen) {
            List<ChannelBean> topNavChannelList = mTabBean.getTopNavChannelList();
            int size = topNavChannelList.size();
            for (int i = 0; i < size; i++) {
                ChannelBean bean = topNavChannelList.get(i);
                if (bean != null) {
                    bean.setGrayFlag(checkPageChannelGray(bean.getChannelId()));
                    if (bean.isGrayFlag()) {
                        Fragment fragment = fragmentAdapter.getFragmentByPageId(bean.getPageId());
                        if (fragment != null) {
                            ColumnFragment columnFragment = (ColumnFragment) fragment;
                            columnFragment.contryGrayFlag = true;
                        }

                    }
                }
            }
        }

    }

    /**
     * 更新频道策略
     */
    private void updateChannelStrategy() {
        if (mTabBean == null) {
            return;
        }
        List<ChannelBean> topNavChannelList = mTabBean.getTopNavChannelList();
        if (ArrayUtils.isEmpty(topNavChannelList)) {
            return;
        }
        int size = topNavChannelList.size();
        for (int i = 0; i < size; i++) {
            ChannelBean bean = topNavChannelList.get(i);
            if (bean != null) {
                Fragment fragment = fragmentAdapter.getFragmentByPageId(bean.getPageId());
                if (fragment != null && fragment instanceof ColumnFragment) {
                    ColumnFragment columnFragment = (ColumnFragment) fragment;
                    columnFragment.channelStrategy = bean.channelStrategy;
                }
            }
        }
    }

    /**
     * 为色值添加透明度
     *
     * @param color
     * @param percent
     * @return
     */
    private String addAlphaColorForPercent(String color, int percent) {
        if (!color.startsWith("#") || color.length() != 7) {
            return color;
        }
        String str = "#" + Integer.toHexString(percent);
        return color.replace("#", str);
    }

    /**
     * 设置夜间模式颜色
     */
    private void setNightModeColor(Context context) {
        //文字选中颜色  "#222222"
        if (SpUtils.isNightMode()) {
            TITLE_TEXT_SELECTED_COLOR = "#DDDDDD";
            //文字未选中颜色 "#999999"
            TITLE_TEXT_UNSELECTED_COLOR = "#80DDDDDD";
            //左右图标颜色 "#80666666"
            THEME_IMAGE_TXT_COLOR = "#FFFFFF";
            THEME_MENU_MORE_COLOR = "#FFFFFF";
        }
    }
}