@Component(modules = {AppModule.class, RabbitApiModule.class})
public interface AppComponent {

    Context getContext();

    RabbitApi getRabbitApi();

} public class LiveTypeBannerAdapter extends LoopPagerAdapter {

    public static final String TYPE_RECOMMEND = "recommend";
    public static final String TYPE_CATE = "cate";

    private List<LiveRoomListBean.DataBean.BannersBean> bannersData;
    private List<RecommendHeaderBean.DataBean.BannersBean> mRecommendBanners;
    private Context mContext;
    private OnBannerClickListener mBannerClickListener;
    private String dataType;

    public LiveTypeBannerAdapter(RollPagerView viewPager, Context context, String type) {
        super(viewPager);
        this.mContext = context;
        this.dataType = type;
    }

    public interface OnBannerClickListener {
        void onClick(int position);
    }

    public void setBannerClickListener(OnBannerClickListener bannerClickListener) {
        mBannerClickListener = bannerClickListener;
    }

    public void setBannersData(List<LiveRoomListBean.DataBean.BannersBean> bannersData) {
        this.bannersData = bannersData;
        notifyDataSetChanged();
    }

    public void setRecommendBanners(List<RecommendHeaderBean.DataBean.BannersBean>
                                            recommendBanners) {
        mRecommendBanners = recommendBanners;
        notifyDataSetChanged();
    }

    @Override
    public View getView(ViewGroup container, final int position) {
        String imgUrl;
        if (dataType.equals(TYPE_RECOMMEND)) {
            RecommendHeaderBean.DataBean.BannersBean bannersBean = mRecommendBanners.get(position);
            imgUrl = bannersBean.getImg();
        } else {
            LiveRoomListBean.DataBean.BannersBean bannersBean = bannersData.get(position);
            imgUrl = bannersBean.getBigimg();
        }
        ImageView view = new ImageView(container.getContext());
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mBannerClickListener.onClick(position);
            }
        });
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        LoaderImage.loadBannerImg(mContext, imgUrl, view);
        return view;
    }

    @Override
    public int getRealCount() {
        if (dataType.equals(TYPE_RECOMMEND)) {
            return mRecommendBanners == null ? 0 : mRecommendBanners.size();
        }
        return bannersData == null ? 0 : bannersData.size();
    }
} public class LiveTypeDetailActivity extends BaseActivity implements LiveTypeDetailContract.View {

    @BindView(R.id.livetype_refresh)
    SwipeRefreshLayout mRefreshLayout;
    @BindView(R.id.livetype_recyclerview)
    RecyclerView mRecyclerView;

    private View headerView;
    private RollPagerView mBannerView;

    @Inject
    LiveTypeDetailPresenter mDetailPresenter;

    //更新
    private final int REFRESH_STATE_UPDATE = 0;
    //加载更多
    private final int REFRESH_STATE_MORE = 1;
    //当前状态
    private int mRefreshState = 0;

    private String mTypeString;
    private int pagerNow = 1;
    private int pagerNum = 20;

    private int loadedItemDataNum;
    private int spacing;
    private boolean isFirstEnter = true;

    private Uri mUri;

    //Banner数据
    private List<LiveRoomListBean.DataBean.BannersBean> mBannersBeen;
    private LiveTypeBannerAdapter mBannerAdapter;

    private HeaderAndFooterRecyclerViewAdapter mHeaderAndFooterRecyclerViewAdapter;

    //item数据
    private List<LiveRoomListBean.DataBean.ItemsBean> mItemsBeen;
    private LiveTypeItemAdapter mTypeItemAdapter;

    @Override
    protected void requestLayout() {
        setContentView(R.layout.activity_livetype_detail);
    }

    @Override
    protected void initToolBar() {

        String typeName = getIntent().getStringExtra("typeName");
        setToolbarTitle(typeName);
    }

    public static void toLiveTypeDetailActivity(
            BaseActivity activity, String typeName, String type) {
        Intent intent = new Intent(activity, LiveTypeDetailActivity.class);
        intent.putExtra("typeName", typeName);
        intent.putExtra("typeString", type);
        activity.startActivity(intent);
    }

    @Override
    protected void initUi() {

    }

    @Override
    protected void initData() {
        mUri = getIntent().getData();
        //当为隐式启动时
        if (mUri != null) {
            switch (mUri.getHost()) {
                case "cate":
                    mTypeString = mUri.getLastPathSegment();
                    break;
                case "mixcate":
                    mTypeString = mUri.getQueryParameter("cate");
                    break;
            }
        } else {
            mTypeString = getIntent().getStringExtra("typeString");
        }

        spacing = ScreenHelper.dp2px(this, 15);
        mBannersBeen = new ArrayList<>();
        mItemsBeen = new ArrayList<>();
        mTypeItemAdapter = new LiveTypeItemAdapter(this, LiveTypeItemAdapter.TYPE_CATE);

        mHeaderAndFooterRecyclerViewAdapter = new HeaderAndFooterRecyclerViewAdapter
                (mTypeItemAdapter);
        mRecyclerView.setAdapter(mHeaderAndFooterRecyclerViewAdapter);

        GridLayoutManager manager = new GridLayoutManager(this, 2);
        manager.setSpanSizeLookup(new HeaderSpanSizeLookup((HeaderAndFooterRecyclerViewAdapter)
                mRecyclerView.getAdapter(), manager.getSpanCount()));
        mRecyclerView.setLayoutManager(manager);

        headerView = getLayoutInflater().inflate(R.layout.viewpager_layout, mRecyclerView,
                false);
        mBannerView = ButterKnife.findById(headerView, R.id.livetype_banner);
        mBannerView.setPlayDelay(3000);
        mBannerAdapter = new LiveTypeBannerAdapter(mBannerView, this, LiveTypeBannerAdapter.TYPE_CATE);
        mBannerView.setAdapter(mBannerAdapter);

        mDetailPresenter.attachView(this);
        mDetailPresenter.getLiveTypeData(mTypeString, pagerNow, pagerNum);

    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerActivityComponent.builder()
                .appComponent(appComponent)
                .build()
                .inject(this);
    }

    @Override
    protected void initListener() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mBannerAdapter.setBannerClickListener(new LiveTypeBannerAdapter.OnBannerClickListener() {
            @Override
            public void onClick(int position) {
                LiveRoomListBean.DataBean.BannersBean bean = mBannersBeen.get(position);
                LiveRoomActivity.toLiveRoomActivity(LiveTypeDetailActivity.this, bean.getRoomid());
            }
        });

        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mRefreshState = REFRESH_STATE_UPDATE;
                pagerNow = 1;
                mDetailPresenter.getLiveTypeData(mTypeString, pagerNow, pagerNum);
            }
        });

        mTypeItemAdapter.setItemClickListener(new LiveTypeItemAdapter.
                OnLiveTypeItemClickListener() {

            @Override
            public void onClick(int position) {
                //添加了header后，RecyclerView 子item的点击位置往后偏移header的数量个位置
                LiveRoomListBean.DataBean.ItemsBean bean;
                if (mHeaderAndFooterRecyclerViewAdapter.getHeaderViewsCount() != 0) {
                    bean = mItemsBeen.get(position - mHeaderAndFooterRecyclerViewAdapter.getHeaderViewsCount());
                } else {
                    bean = mItemsBeen.get(position);
                }
                LiveRoomActivity.toLiveRoomActivity(LiveTypeDetailActivity.this, bean.getId());
            }
        });

        mRecyclerView.addOnScrollListener(mOnScrollListener);

    }

    private EndlessRecyclerOnScrollListener mOnScrollListener = new
            EndlessRecyclerOnScrollListener() {

        @Override
        public void onLoadNextPage(View view) {
            super.onLoadNextPage(view);

            LoadingFooter.State state = RecyclerViewStateUtils.getFooterViewState(mRecyclerView);
            if (state == LoadingFooter.State.Loading) {
                return;
            }

            if (loadedItemDataNum < pagerNum) {
                //the end
                RecyclerViewStateUtils.setFooterViewState(App.getAppInstance(),
                        mRecyclerView, pagerNum, LoadingFooter.State.TheEnd, null);
            } else {
                // loading more
                mRefreshState = REFRESH_STATE_MORE;
                pagerNow = pagerNow + 1;
                mDetailPresenter.getLiveTypeData(mTypeString, pagerNow, pagerNum);
                RecyclerViewStateUtils.setFooterViewState(App.getAppInstance(),
                        mRecyclerView, pagerNum, LoadingFooter.State.Loading, null);
            }
        }
    };

    @Override
    public void showLiveTypeBannerData(List<LiveRoomListBean.DataBean.BannersBean> data) {

        if (mRefreshState == REFRESH_STATE_UPDATE) {
            mBannersBeen.clear();
            mBannersBeen.addAll(data);
        } else {
            mBannersBeen.addAll(data);
        }
        //第一次调用，判断是否添加头部view，以及对间隔的处理。
        if (isFirstEnter) {
            if (data.size() == 0) {
                mRecyclerView.addItemDecoration(new SpaceItemDecoration(2, spacing, spacing, false));
                mBannerView.setVisibility(View.GONE);
            } else {
                mRecyclerView.addItemDecoration(new SpaceItemDecoration(2, spacing, spacing, true));
                mHeaderAndFooterRecyclerViewAdapter.addHeaderView(headerView);
                mBannerView.setVisibility(View.VISIBLE);

                if (data.size() == 1) {
                    mBannerView.setHintView(null);
                } else {
                    //banner数据大于1时才开启轮播
                    mBannerView.setPlayDelay(2000);
                    mBannerView.setHintView(new ColorPointHintView
                            (this, ContextCompat.getColor(this, R.color.md_green_A200),
                                    Color.WHITE));
                }
                mBannerAdapter.setBannersData(mBannersBeen);
            }
        }

        isFirstEnter = false;
    }

    @Override
    public void showLiveTypeItemsData(List<LiveRoomListBean.DataBean.ItemsBean> data) {
        loadedItemDataNum = data.size();
        mRefreshLayout.setRefreshing(false);
        RecyclerViewStateUtils.setFooterViewState(mRecyclerView, LoadingFooter.State.Normal);
        switch (mRefreshState) {
            case REFRESH_STATE_UPDATE:
                mItemsBeen.clear();
                mItemsBeen.addAll(data);
                break;
            case REFRESH_STATE_MORE:
                mItemsBeen.addAll(data);
                break;
        }

        mTypeItemAdapter.setItemList(mItemsBeen);
    }

    @Override
    public void showError() {

    }

    @Override
    public void complete() {

    }

    @Override
    public void onPause() {
        super.onPause();
        mBannerView.pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mBannerView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mDetailPresenter != null) {
            mDetailPresenter.detachView();
        }
    }

} public class LiveRoomActivity extends BaseActivity implements LiveRoomContract.View,
        Handler.Callback {

    @BindView(R.id.video_view)
    PLVideoTextureView mVideoPlayView;
    @BindView(R.id.danmu_view)
    DanmakuView mDanmakuView;
    @BindView(R.id.fl_video_content)
    FrameLayout mVideoContent;
    //动态隐藏的控制布局
    @BindView(R.id.rl_room_live_control)
    RelativeLayout mControlLayout;
    //返回按钮
    @BindView(R.id.img_liveroom_back)
    ImageView mRoomBack;
    //显示的房间信息布局
    @BindView(R.id.rl_room_info)
    RelativeLayout mRoomInfoLayout;
    @BindView(R.id.tv_room_name)
    TextView mRoomName;
    @BindView(R.id.tv_room_num)
    TextView mRoomNum;
    @BindView(R.id.tv_room_person_num)
    TextView mRoomPersonNum;
    @BindView(R.id.tv_room_live_type)
    TextView mRoomLiveType;

    @BindView(R.id.progress_live_room)
    ProgressBar mProgressBar;
    //全屏控制按钮
    @BindView(R.id.img_fullscreen)
    ImageView mFullScreen;

    @BindView(R.id.live_room_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.live_room_viewpager)
    ViewPager mViewPager;

    //弹幕消息列表
    private RecyclerView mChatInfoView;
    private Button mRetryGetDanmuBtn;
    private List<DanMuDataBean> mMuDataBeen;
    private ChatListAdapter mChatListAdapter;

    //房主房间信息
    private ImageView mAnchorHead;
    private TextView mAnchorName;
    private TextView mAnchorRoomId;
    private TextView mAnchorHeight;
    private TextView mAnchorFans;
    private TextView mAnchorLiveRoomDetail;

    @Inject
    LiveRoomPresenter mRoomPresenter;

    private static final int HANDLER_HIDE_CONTROL = 100;    //自动隐藏mControlLayout
    private static final int HANDLER_HIDE_TIME = 5 * 1000; //mControlLayout的自动隐藏时间

    private Uri mUri;

    private Handler mControlHandler;
    private boolean isControlLayoutVisible = true;

    private String roomId;

    private String[] mTitles;
    private LiveRoomViewPagerAdapter mPagerAdapter;
    private List<View> mViewList;

    private boolean isShowDanmu = false;
    private DanmakuContext mDanmakuContext;
    private final BaseDanmakuParser parser = new BaseDanmakuParser() {
        @Override
        protected IDanmakus parse() {
            return new Danmakus();
        }
    };

    @Override
    protected void initToolBar() {
        mToolbar.setVisibility(View.GONE);
    }

    @Override
    protected void requestLayout() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_live_room);
    }


    public static void toLiveRoomActivity(BaseActivity activity, String roomId) {
        Intent intent = new Intent(activity, LiveRoomActivity.class);
        intent.putExtra("roomId", roomId);
        activity.startActivity(intent);
    }

    @Override
    protected void initData() {
        mUri = getIntent().getData();
        if (mUri != null) {
            roomId = mUri.getLastPathSegment();
        } else {
            roomId = getIntent().getStringExtra("roomId");
        }

        mTitles = new String[]{"聊天", "主播"};
        mViewList = new ArrayList<>();
        mPagerAdapter = new LiveRoomViewPagerAdapter(mTitles);
        initPagerView();
        mViewPager.setAdapter(mPagerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);

        //初始化handler 刚进来mControlLayout是显示的，发送个延时消息 5秒后自动隐藏
        mControlHandler = new Handler(this);
        mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
        mControlHandler.sendEmptyMessageDelayed(HANDLER_HIDE_CONTROL, HANDLER_HIDE_TIME);

        mRoomPresenter.attachView(this);
        mRoomPresenter.getRoomInfo(roomId);
        mRoomPresenter.getChatListInfo(roomId);

    }

    private void initPagerView() {
        //弹幕列表view
        View chatContentView = getLayoutInflater().inflate(R.layout.fragment_chatlist,null);
        mViewList.add(chatContentView);
        mChatInfoView = ButterKnife.findById(chatContentView,R.id.chat_recycler_view);
        mRetryGetDanmuBtn = ButterKnife.findById(chatContentView,R.id.re_load_chat);

        mMuDataBeen = new ArrayList<>();
        mChatListAdapter = new ChatListAdapter(this,mMuDataBeen);
        mChatInfoView.setLayoutManager(new LinearLayoutManager(this));
        mChatInfoView.setAdapter(mChatListAdapter);

        //房间信息view
        View roomInfoView = getLayoutInflater().inflate(R.layout.fragment_anchor_info,null);
        mViewList.add(roomInfoView);
        mAnchorHead = ButterKnife.findById(roomInfoView,R.id.img_anchor_head);
        mAnchorName = ButterKnife.findById(roomInfoView,R.id.tv_anchor_name);
        mAnchorRoomId = ButterKnife.findById(roomInfoView,R.id.tv_live_room_room_id);
        mAnchorHeight = ButterKnife.findById(roomInfoView,R.id.tv_anchor_height);
        mAnchorFans = ButterKnife.findById(roomInfoView,R.id.tv_anchor_fans);
        mAnchorLiveRoomDetail = ButterKnife.findById(roomInfoView,R.id.tv_live_room_livedetail);

        mPagerAdapter.setViewList(mViewList);
    }

    @Override
    protected void initUi() {
        updateVideoLayoutParams();
        mVideoPlayView.setBufferingIndicator(mProgressBar);
        mDanmakuView.enableDanmakuDrawingCache(true);
        mDanmakuContext = DanmakuContext.create();
        mDanmakuContext.setDuplicateMergingEnabled(true);
        mDanmakuView.prepare(parser, mDanmakuContext);
        if (!isLandscape()) {
            mDanmakuView.hideAndPauseDrawTask();
            isShowDanmu = false;
        }
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerActivityComponent.builder()
                .appComponent(appComponent)
                .build()
                .inject(this);
    }

    @Override
    protected void initListener() {
        mDanmakuView.setCallback(new DrawHandler.Callback() {
            @Override
            public void prepared() {
                mDanmakuView.start();
            }

            @Override
            public void updateTimer(DanmakuTimer timer) {

            }

            @Override
            public void danmakuShown(BaseDanmaku danmaku) {

            }

            @Override
            public void drawingFinished() {

            }
        });

        mRetryGetDanmuBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mRoomPresenter.getChatListInfo(roomId);
            }
        });
    }

    @OnClick({R.id.img_liveroom_back, R.id.img_fullscreen, R.id.fl_video_content})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_liveroom_back:
                //返回按钮
                clickBack();
                break;
            case R.id.img_fullscreen:
                //全屏控制 横屏
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                //点击后重新倒计时
                mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
                mControlHandler.sendEmptyMessageDelayed(HANDLER_HIDE_CONTROL, HANDLER_HIDE_TIME);
                break;
            case R.id.fl_video_content:
                //点击播放器
                if (isControlLayoutVisible) { //显示状态
                    mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
                    mControlHandler.sendEmptyMessage(HANDLER_HIDE_CONTROL);
                } else { //隐藏状态 点击变为显示，倒计时5秒再隐藏
                    mControlLayout.setVisibility(View.VISIBLE);
                    isControlLayoutVisible = true;
                    mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
                    mControlHandler.sendEmptyMessageDelayed(HANDLER_HIDE_CONTROL,
                            HANDLER_HIDE_TIME);
                }
                break;
        }
    }

    /**
     * 直播地址拼接
     * @param flag
     * @param room_key
     * @return
     */
    private String stitchingAddress(String flag, String room_key) {
        String url = "";
        String[] flags = flag.split("_");
        url = String.format(getString(R.string.video_url), flags[1], room_key);
        return url;
    }

    @Override
    public void showRoomInfo(LiveRoomBean.DataBean.InfoBean data) {
        setRoomInfo(data);
        String url = stitchingAddress(data.getVideoinfo().getPlflag(),
                data.getVideoinfo().getRoom_key());
        mVideoPlayView.setVideoPath(url);
    }

    @Override
    public void showChatListInfo(LiveChatInfoBean bean) {
        mRoomPresenter.connectToChatRoom(roomId, bean);
    }

    @Override
    public void showDanMuData(DanMuDataBean bean) {
        if (!bean.getFrom().getRid().equals("-1")) {
            if (!bean.getFrom().getNickName().equals("")) {
                mMuDataBeen.add(bean);
                mChatListAdapter.notifyDataSetChanged();
                mChatInfoView.scrollToPosition(mMuDataBeen.size()-1);
            }
        }

        if (isShowDanmu) { //当弹幕显示时才填装
            BaseDanmaku danmaku = mDanmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
            danmaku.text = bean.getContent();
            danmaku.textSize = ScreenHelper.sp2px(this, 14);
            danmaku.textColor = Color.WHITE;
            danmaku.setTime(mDanmakuView.getCurrentTime());
            mDanmakuView.addDanmaku(danmaku);
        }
    }

    /**
     * 设置房间信息显示
     *
     * @param data
     */
    private void setRoomInfo(LiveRoomBean.DataBean.InfoBean data) {
        mRoomName.setText(data.getRoominfo().getName());
        mRoomNum.setText(String.format(getString(R.string.room_num), roomId));
        mRoomPersonNum.setText(String.format(getString(R.string.room_person_num),
                data.getRoominfo().getPerson_num()));
        mRoomLiveType.setText(String.format(getString(R.string.room_type),
                data.getRoominfo().getClassification()));
        setAnchorInfo(data);
    }

    /**
     * 设置房主房间信息
     * @param data
     */
    private void setAnchorInfo(LiveRoomBean.DataBean.InfoBean data) {
        LoaderImage.loadCircleImg(this,data.getHostinfo().getAvatar(),mAnchorHead);
        mAnchorName.setText(data.getHostinfo().getName());
        mAnchorRoomId.setText(String.format(getString(R.string.room_id),
                data.getRoominfo().getId()));
        String banboos = data.getHostinfo().getBamboos();
        mAnchorHeight.setText(String.format(getString(R.string.anchor_height), SmallToolsHelper.unitConversion(banboos)));
        int person_num = Integer.parseInt(data.getRoominfo().getFans());
        String persons;
        if (person_num > 10000) {
            persons = String.format("%.1f", (person_num / 10000.0));
            persons = persons + "万";
        } else {
            persons = String.valueOf(person_num);
        }
        mAnchorFans.setText(String.format(getString(R.string.anchor_fans), persons));
        mAnchorLiveRoomDetail.setText(data.getRoominfo().getBulletin());
    }

    @Override
    public void showError() {

    }

    @Override
    public void complete() {

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //当屏幕变为横屏时
        if (isLandscape()) {
            //设置为全屏
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mControlLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
            mRoomInfoLayout.setVisibility(View.GONE);
            mFullScreen.setVisibility(View.GONE);
            mDanmakuView.show();
            isShowDanmu = true;
        } else {
            //退出全屏
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mRoomInfoLayout.setVisibility(View.VISIBLE);
            mFullScreen.setVisibility(View.VISIBLE);
            mDanmakuView.hide();
            isShowDanmu = false;
        }

        updateVideoLayoutParams();
    }

    /**
     * 动态更新视频播放父view的高度
     */
    private void updateVideoLayoutParams() {
        ViewGroup.LayoutParams lp = mVideoContent.getLayoutParams();
        if (isLandscape()) {
            lp.height = ScreenHelper.getScreenY(this);
        } else {
            lp.height = ScreenHelper.dp2px(this, 200);
        }
        mVideoContent.setLayoutParams(lp);
    }

    /**
     * 判断是否是横屏
     *
     * @return
     */
    public boolean isLandscape() {
        return getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    }

    /**
     * 返回键方法
     */
    public void clickBack() {
        if (isLandscape()) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            //重新倒计时
            mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
            mControlHandler.sendEmptyMessageDelayed(HANDLER_HIDE_CONTROL, HANDLER_HIDE_TIME);
        } else {
            if (mDanmakuView != null) {
                mDanmakuView.release();
                mDanmakuView = null;
            }
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mVideoPlayView != null) {
            mVideoPlayView.stopPlayback();
        }
        if (mRoomPresenter != null) {
            mRoomPresenter.detachView();
            mRoomPresenter.closeConnection();
        }
        if (mDanmakuView != null) {
            mDanmakuView.release();
            mDanmakuView = null;
        }
        mControlHandler.removeMessages(HANDLER_HIDE_CONTROL);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mVideoPlayView != null) {
            mVideoPlayView.start();
        }
        if (mDanmakuView != null && mDanmakuView.isPrepared() && mDanmakuView.isPaused()) {
            mDanmakuView.resume();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mVideoPlayView != null) {
            mVideoPlayView.pause();
        }
        if (mDanmakuView != null && mDanmakuView.isPrepared()) {
            mDanmakuView.pause();
        }
    }

    @Override
    public void onBackPressed() {
        clickBack();
    }

    @Override
    public boolean handleMessage(Message message) {
        if (message.what == HANDLER_HIDE_CONTROL) {
            mControlLayout.setVisibility(View.GONE);
            isControlLayoutVisible = false;
        }
        return true;
    }
} public abstract class MainFragment extends BaseFragment {

    protected MainActivity mMainActivity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mMainActivity = (MainActivity) context;
    }

} public interface RecommendContract {

    interface View extends BaseContract.BaseView {

        void showHeaderData(RecommendHeaderBean data);

        void showCardListData(List<RecommendCardListBean.DataBean> dataBeanList);

    }

    interface Presenter<T> extends BaseContract.BasePresenter<T> {

        void getHeaderData();

        void getCardListData();
    }

} public class RecommendPresenter extends RxPresenter<RecommendContract.View> implements
        RecommendContract.Presenter<RecommendContract.View> {

    private RabbitApi mRabbitApi;

    @Inject
    RecommendPresenter(RabbitApi rabbitApi) {
        this.mRabbitApi = rabbitApi;
    }

    @Override
    public void getHeaderData() {
        Disposable disposable = mRabbitApi.getRecommendHeaderData()
                .subscribe(new Consumer<RecommendHeaderBean>() {
                    @Override
                    public void accept(@NonNull RecommendHeaderBean data) throws Exception {
                        if (data != null && mView != null) {
                            mView.showHeaderData(data);
                        }

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {
                        mView.showError();
                    }
                });
        addDisposable(disposable);
    }

    @Override
    public void getCardListData() {
        Disposable disposable = mRabbitApi.getRecommendCardList()
                .map(new Function<RecommendCardListBean, List<RecommendCardListBean.DataBean>>() {
                    @Override
                    public List<RecommendCardListBean.DataBean> apply(@NonNull RecommendCardListBean
                                                                        recommendCardListBean) throws Exception {
                        return recommendCardListBean.getData();
                    }
                })
                .subscribe(new Consumer<List<RecommendCardListBean.DataBean>>() {
                    @Override
                    public void accept(@NonNull List<RecommendCardListBean.DataBean> dataBeen) throws Exception {
                        if (dataBeen != null && mView != null) {
                            mView.showCardListData(dataBeen);
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {
                        mView.showError();
                    }
                });
        addDisposable(disposable);
    }
} public class RecommendCardListBean {

    private int errno;
    private String errmsg;
    private String authseq;
    private List<DataBean> data;

    public int getErrno() {
        return errno;
    }

    public void setErrno(int errno) {
        this.errno = errno;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public String getAuthseq() {
        return authseq;
    }

    public void setAuthseq(String authseq) {
        this.authseq = authseq;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {

        private String id;
        private String card_type;
        private String card_title;
        private String room_cate;
        private String datanum;
        private String click_trace;
        private String total;
        private List<ItemsBean> items;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getCard_type() {
            return card_type;
        }

        public void setCard_type(String card_type) {
            this.card_type = card_type;
        }

        public String getCard_title() {
            return card_title;
        }

        public void setCard_title(String card_title) {
            this.card_title = card_title;
        }

        public String getRoom_cate() {
            return room_cate;
        }

        public void setRoom_cate(String room_cate) {
            this.room_cate = room_cate;
        }

        public String getDatanum() {
            return datanum;
        }

        public void setDatanum(String datanum) {
            this.datanum = datanum;
        }

        public String getClick_trace() {
            return click_trace;
        }

        public void setClick_trace(String click_trace) {
            this.click_trace = click_trace;
        }

        public String getTotal() {
            return total;
        }

        public void setTotal(String total) {
            this.total = total;
        }

        public List<ItemsBean> getItems() {
            return items;
        }

        public void setItems(List<ItemsBean> items) {
            this.items = items;
        }

        public static class ItemsBean {
            /**
             * classification : {"cname":"王者荣耀","ename":"kingglory"}
             * display_type : 1
             * img : http://i6.pdim.gs/ffe0b293b386effc5931c028d6b57077.jpeg
             * person_num : 44526
             * roomid : 847407
             * style_type : 1
             * tag :
             * tag_color : 1
             * tag_switch : 1
             * title : 国服第一射手！新赛季带一波房管
             * userinfo : {"nickName":"紅尘丶青衣","rid":34212558,"avatar":"http://i7.pdim
             * .gs/1b1456354aaf3a7801e87b955d2ef2e7.jpeg","userName":""}
             * xid : 7227979
             * streamurl : http://flv-live-qn.xingyan.panda
             * .tv/panda-xingyan/96bb8a5f626fc145ecc3ef0dd839f325.flv
             * streaminfo : {"width":"480","height":"848","decode_type":2}
             * taginfo : {"text":"","color":"","icon":""}
             * city : 成都市
             */

            private ClassificationBean classification;
            private String display_type;
            private String img;
            private String person_num;
            private String roomid;
            private String style_type;
            private String tag;
            private String tag_color;
            private String tag_switch;
            private String title;
            private UserinfoBean userinfo;
            private String xid;
            private String streamurl;
            private StreaminfoBean streaminfo;
            private TaginfoBean taginfo;
            private String city;

            public ClassificationBean getClassification() {
                return classification;
            }

            public void setClassification(ClassificationBean classification) {
                this.classification = classification;
            }

            public String getDisplay_type() {
                return display_type;
            }

            public void setDisplay_type(String display_type) {
                this.display_type = display_type;
            }

            public String getImg() {
                return img;
            }

            public void setImg(String img) {
                this.img = img;
            }

            public String getPerson_num() {
                return person_num;
            }

            public void setPerson_num(String person_num) {
                this.person_num = person_num;
            }

            public String getRoomid() {
                return roomid;
            }

            public void setRoomid(String roomid) {
                this.roomid = roomid;
            }

            public String getStyle_type() {
                return style_type;
            }

            public void setStyle_type(String style_type) {
                this.style_type = style_type;
            }

            public String getTag() {
                return tag;
            }

            public void setTag(String tag) {
                this.tag = tag;
            }

            public String getTag_color() {
                return tag_color;
            }

            public void setTag_color(String tag_color) {
                this.tag_color = tag_color;
            }

            public String getTag_switch() {
                return tag_switch;
            }

            public void setTag_switch(String tag_switch) {
                this.tag_switch = tag_switch;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public UserinfoBean getUserinfo() {
                return userinfo;
            }

            public void setUserinfo(UserinfoBean userinfo) {
                this.userinfo = userinfo;
            }

            public String getXid() {
                return xid;
            }

            public void setXid(String xid) {
                this.xid = xid;
            }

            public String getStreamurl() {
                return streamurl;
            }

            public void setStreamurl(String streamurl) {
                this.streamurl = streamurl;
            }

            public StreaminfoBean getStreaminfo() {
                return streaminfo;
            }

            public void setStreaminfo(StreaminfoBean streaminfo) {
                this.streaminfo = streaminfo;
            }

            public TaginfoBean getTaginfo() {
                return taginfo;
            }

            public void setTaginfo(TaginfoBean taginfo) {
                this.taginfo = taginfo;
            }

            public String getCity() {
                return city;
            }

            public void setCity(String city) {
                this.city = city;
            }

            public static class ClassificationBean {
                /**
                 * cname : 王者荣耀
                 * ename : kingglory
                 */

                private String cname;
                private String ename;

                public String getCname() {
                    return cname;
                }

                public void setCname(String cname) {
                    this.cname = cname;
                }

                public String getEname() {
                    return ename;
                }

                public void setEname(String ename) {
                    this.ename = ename;
                }

                @Override
                public String toString() {
                    return "ClassificationBean{" +
                            "cname='" + cname + '\'' +
                            ", ename='" + ename + '\'' +
                            '}';
                }
            }

            public static class UserinfoBean {
                /**
                 * nickName : 紅尘丶青衣
                 * rid : 34212558
                 * avatar : http://i7.pdim.gs/1b1456354aaf3a7801e87b955d2ef2e7.jpeg
                 * userName :
                 */

                private String nickName;
                private int rid;
                private String avatar;
                private String userName;

                public String getNickName() {
                    return nickName;
                }

                public void setNickName(String nickName) {
                    this.nickName = nickName;
                }

                public int getRid() {
                    return rid;
                }

                public void setRid(int rid) {
                    this.rid = rid;
                }

                public String getAvatar() {
                    return avatar;
                }

                public void setAvatar(String avatar) {
                    this.avatar = avatar;
                }

                public String getUserName() {
                    return userName;
                }

                public void setUserName(String userName) {
                    this.userName = userName;
                }

                @Override
                public String toString() {
                    return "UserinfoBean{" +
                            "nickName='" + nickName + '\'' +
                            ", rid=" + rid +
                            ", avatar='" + avatar + '\'' +
                            ", userName='" + userName + '\'' +
                            '}';
                }
            }

            public static class StreaminfoBean {
                /**
                 * width : 480
                 * height : 848
                 * decode_type : 2
                 */

                private String width;
                private String height;
                private int decode_type;

                public String getWidth() {
                    return width;
                }

                public void setWidth(String width) {
                    this.width = width;
                }

                public String getHeight() {
                    return height;
                }

                public void setHeight(String height) {
                    this.height = height;
                }

                public int getDecode_type() {
                    return decode_type;
                }

                public void setDecode_type(int decode_type) {
                    this.decode_type = decode_type;
                }

                @Override
                public String toString() {
                    return "StreaminfoBean{" +
                            "width='" + width + '\'' +
                            ", height='" + height + '\'' +
                            ", decode_type=" + decode_type +
                            '}';
                }
            }

            public static class TaginfoBean {
                /**
                 * text :
                 * color :
                 * icon :
                 */

                private String text;
                private String color;
                private String icon;

                public String getText() {
                    return text;
                }

                public void setText(String text) {
                    this.text = text;
                }

                public String getColor() {
                    return color;
                }

                public void setColor(String color) {
                    this.color = color;
                }

                public String getIcon() {
                    return icon;
                }

                public void setIcon(String icon) {
                    this.icon = icon;
                }

                @Override
                public String toString() {
                    return "TaginfoBean{" +
                            "text='" + text + '\'' +
                            ", color='" + color + '\'' +
                            ", icon='" + icon + '\'' +
                            '}';
                }
            }

            @Override
            public String toString() {
                return "ItemsBean{" +
                        "classification=" + classification +
                        ", display_type='" + display_type + '\'' +
                        ", img='" + img + '\'' +
                        ", person_num='" + person_num + '\'' +
                        ", roomid='" + roomid + '\'' +
                        ", style_type='" + style_type + '\'' +
                        ", tag='" + tag + '\'' +
                        ", tag_color='" + tag_color + '\'' +
                        ", tag_switch='" + tag_switch + '\'' +
                        ", title='" + title + '\'' +
                        ", userinfo=" + userinfo +
                        ", xid='" + xid + '\'' +
                        ", streamurl='" + streamurl + '\'' +
                        ", streaminfo=" + streaminfo +
                        ", taginfo=" + taginfo +
                        ", city='" + city + '\'' +
                        '}';
            }
        }

        @Override
        public String toString() {
            return "DataBean{" +
                    "id='" + id + '\'' +
                    ", card_type='" + card_type + '\'' +
                    ", card_title='" + card_title + '\'' +
                    ", room_cate='" + room_cate + '\'' +
                    ", datanum='" + datanum + '\'' +
                    ", click_trace='" + click_trace + '\'' +
                    ", total='" + total + '\'' +
                    ", items=" + items +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "RecommendCardListBean{" +
                "errno=" + errno +
                ", errmsg='" + errmsg + '\'' +
                ", authseq='" + authseq + '\'' +
                ", data=" + data +
                '}';
    }
} public class RecommendHeaderBean {

    private int errno;
    private String errmsg;
    private DataBean data;
    private String authseq;

    public int getErrno() {
        return errno;
    }

    public void setErrno(int errno) {
        this.errno = errno;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public String getAuthseq() {
        return authseq;
    }

    public void setAuthseq(String authseq) {
        this.authseq = authseq;
    }

    public static class DataBean {
        private List<BannersBean> banners;
        private List<NavsBean> navs;

        public List<BannersBean> getBanners() {
            return banners;
        }

        public void setBanners(List<BannersBean> banners) {
            this.banners = banners;
        }

        public List<NavsBean> getNavs() {
            return navs;
        }

        public void setNavs(List<NavsBean> navs) {
            this.navs = navs;
        }

        public static class BannersBean {
            /**
             * img : http://i7.pdim.gs/76c527b898a3cad1d57295302a8b72e8.jpeg
             * url : http://img.yoyojie.com/templates/default/download/tlbb/
             * title :
             * type : 3
             * click_trace : banners_index
             * roomid : 1094979
             * display_type : 1
             * style_type : 1
             */

            private String img;
            private String url;
            private String title;
            private String type;
            private String click_trace;
            private String roomid;
            private String display_type;
            private String style_type;

            public String getImg() {
                return img;
            }

            public void setImg(String img) {
                this.img = img;
            }

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public String getType() {
                return type;
            }

            public void setType(String type) {
                this.type = type;
            }

            public String getClick_trace() {
                return click_trace;
            }

            public void setClick_trace(String click_trace) {
                this.click_trace = click_trace;
            }

            public String getRoomid() {
                return roomid;
            }

            public void setRoomid(String roomid) {
                this.roomid = roomid;
            }

            public String getDisplay_type() {
                return display_type;
            }

            public void setDisplay_type(String display_type) {
                this.display_type = display_type;
            }

            public String getStyle_type() {
                return style_type;
            }

            public void setStyle_type(String style_type) {
                this.style_type = style_type;
            }

            @Override
            public String toString() {
                return "BannersBean{" +
                        "img='" + img + '\'' +
                        ", url='" + url + '\'' +
                        ", title='" + title + '\'' +
                        ", type='" + type + '\'' +
                        ", click_trace='" + click_trace + '\'' +
                        ", roomid='" + roomid + '\'' +
                        ", display_type='" + display_type + '\'' +
                        ", style_type='" + style_type + '\'' +
                        '}';
            }
        }

        public static class NavsBean {
            /**
             * type : 4
             * img : http://i6.pdim.gs/113b4716cb11efc0dbeab03ec9f87150.png
             * title : 英雄联盟
             * url : pandatv://cate/lol?title=英雄联盟
             * click_trace : navs_index
             */

            private String type;
            private String img;
            private String title;
            private String url;
            private String click_trace;

            public String getType() {
                return type;
            }

            public void setType(String type) {
                this.type = type;
            }

            public String getImg() {
                return img;
            }

            public void setImg(String img) {
                this.img = img;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }

            public String getClick_trace() {
                return click_trace;
            }

            public void setClick_trace(String click_trace) {
                this.click_trace = click_trace;
            }

            @Override
            public String toString() {
                return "NavsBean{" +
                        "type='" + type + '\'' +
                        ", img='" + img + '\'' +
                        ", title='" + title + '\'' +
                        ", url='" + url + '\'' +
                        ", click_trace='" + click_trace + '\'' +
                        '}';
            }
        }

        @Override
        public String toString() {
            return "DataBean{" +
                    "banners=" + banners +
                    ", navs=" + navs +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "RecommendHeaderBean{" +
                "errno=" + errno +
                ", errmsg='" + errmsg + '\'' +
                ", data=" + data +
                ", authseq='" + authseq + '\'' +
                '}';
    }
} public class HeaderAndFooterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final int TYPE_HEADER_VIEW = Integer.MIN_VALUE;
    private static final int TYPE_FOOTER_VIEW = Integer.MIN_VALUE + 1;

    /**
     * RecyclerView使用的，真正的Adapter
     */
    private RecyclerView.Adapter<RecyclerView.ViewHolder> mInnerAdapter;

    private ArrayList<View> mHeaderViews = new ArrayList<>();
    private ArrayList<View> mFooterViews = new ArrayList<>();

    private RecyclerView.AdapterDataObserver mDataObserver = new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            super.onChanged();
            notifyDataSetChanged();
        }

        @Override
        public void onItemRangeChanged(int positionStart, int itemCount) {
            super.onItemRangeChanged(positionStart, itemCount);
            notifyItemRangeChanged(positionStart + getHeaderViewsCount(), itemCount);
        }

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            notifyItemRangeInserted(positionStart + getHeaderViewsCount(), itemCount);
        }

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            super.onItemRangeRemoved(positionStart, itemCount);
            notifyItemRangeRemoved(positionStart + getHeaderViewsCount(), itemCount);
        }

        @Override
        public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
            super.onItemRangeMoved(fromPosition, toPosition, itemCount);
            int headerViewsCountCount = getHeaderViewsCount();
            notifyItemRangeChanged(fromPosition + headerViewsCountCount, toPosition + headerViewsCountCount + itemCount);
        }
    };

    public HeaderAndFooterRecyclerViewAdapter(RecyclerView.Adapter innerAdapter) {
        setAdapter(innerAdapter);
    }

    /**
     * 设置adapter
     * @param adapter
     */
    public void setAdapter(RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {

        if (adapter != null) {
            if (!(adapter instanceof RecyclerView.Adapter))
                throw new RuntimeException("your adapter must be a RecyclerView.Adapter");
        }

        //当存在一个RecyclerView.Adapter时，先移除它
        if (mInnerAdapter != null) {
            notifyItemRangeRemoved(getHeaderViewsCount(), mInnerAdapter.getItemCount());
            mInnerAdapter.unregisterAdapterDataObserver(mDataObserver);
        }

        this.mInnerAdapter = adapter;
        assert mInnerAdapter != null;
        mInnerAdapter.registerAdapterDataObserver(mDataObserver);
        notifyItemRangeInserted(getHeaderViewsCount(), mInnerAdapter.getItemCount());
    }

    public RecyclerView.Adapter getInnerAdapter() {
        return mInnerAdapter;
    }

    public void addHeaderView(View header) {

        if (header == null) {
            throw new RuntimeException("header is null");
        }
        LinearLayout.LayoutParams lm = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
                ,LinearLayout.LayoutParams.WRAP_CONTENT);
        lm.gravity = Gravity.CENTER;
        header.setLayoutParams(lm);

        mHeaderViews.add(header);
        this.notifyDataSetChanged();
    }

    public void addFooterView(View footer) {

        if (footer == null) {
            throw new RuntimeException("footer is null");
        }

        mFooterViews.add(footer);
        this.notifyDataSetChanged();
    }

    /**
     * 返回第一个FoView
     * @return
     */
    public View getFooterView() {
        return  getFooterViewsCount()>0 ? mFooterViews.get(0) : null;
    }

    /**
     * 返回第一个HeaderView
     * @return
     */
    public View getHeaderView() {
        return  getHeaderViewsCount()>0 ? mHeaderViews.get(0) : null;
    }

    public void removeHeaderView(View view) {
        mHeaderViews.remove(view);
        this.notifyDataSetChanged();
    }

    public void removeFooterView(View view) {
        mFooterViews.remove(view);
        this.notifyDataSetChanged();
    }

    public int getHeaderViewsCount() {
        return mHeaderViews.size();
    }

    public int getFooterViewsCount() {
        return mFooterViews.size();
    }

    public boolean isHeader(int position) {
        return getHeaderViewsCount() > 0 && position == 0;
    }

    public boolean isFooter(int position) {
        int lastPosition = getItemCount() - 1;
        return getFooterViewsCount() > 0 && position == lastPosition;
    }

    @Override
    public int getItemViewType(int position) {
        int innerCount = mInnerAdapter.getItemCount();
        int headerViewsCountCount = getHeaderViewsCount();
        if (position < headerViewsCountCount) { //类型为headerView
            return TYPE_HEADER_VIEW + position;
        } else if (headerViewsCountCount <= position && position < headerViewsCountCount + innerCount) {
            //中间RecyclerView本身的item的position
            int innerItemViewType = mInnerAdapter.getItemViewType(position - headerViewsCountCount);
            if(innerItemViewType >= Integer.MAX_VALUE / 2) {
                throw new IllegalArgumentException("your adapter's return value of getViewTypeCount() must < Integer.MAX_VALUE / 2");
            }
            return innerItemViewType + Integer.MAX_VALUE / 2;
        } else { //类型为footerView
            return TYPE_FOOTER_VIEW + position - headerViewsCountCount - innerCount;
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int headerViewsCountCount = getHeaderViewsCount();
        if (viewType < TYPE_HEADER_VIEW + headerViewsCountCount) {
            //类型为headerView
            return new ViewHolder(mHeaderViews.get(viewType - TYPE_HEADER_VIEW));
        } else if (viewType >= TYPE_FOOTER_VIEW && viewType < Integer.MAX_VALUE / 2) {
            //类型为footerView
            return new ViewHolder(mFooterViews.get(viewType - TYPE_FOOTER_VIEW));
        } else {
            //类型为中间view
            return mInnerAdapter.onCreateViewHolder(parent, viewType - Integer.MAX_VALUE / 2);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int headerViewsCountCount = getHeaderViewsCount();
        if (position >= headerViewsCountCount && position < headerViewsCountCount + mInnerAdapter.getItemCount()) {
            mInnerAdapter.onBindViewHolder(holder, position - headerViewsCountCount);
        } else {
            ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
            if(layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
                ((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true);
            }
        }
    }

    @Override
    public int getItemCount() {
        return getHeaderViewsCount() + getFooterViewsCount() + mInnerAdapter.getItemCount();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
import android.content.Intent;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import com.jude.rollviewpager.RollPagerView;
import com.orhanobut.logger.Logger;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import yyl.rabbitcloud.R;
import yyl.rabbitcloud.di.component.AppComponent;
import yyl.rabbitcloud.di.component.DaggerFragmentComponent;
import yyl.rabbitcloud.livebycate.LiveTypeBannerAdapter;
import yyl.rabbitcloud.livebycate.LiveTypeDetailActivity;
import yyl.rabbitcloud.liveroom.LiveRoomActivity;
import yyl.rabbitcloud.main.MainFragment;
import yyl.rabbitcloud.main.home.RecommendContract;
import yyl.rabbitcloud.main.home.RecommendPresenter;
import yyl.rabbitcloud.main.home.bean.RecommendCardListBean;
import yyl.rabbitcloud.main.home.bean.RecommendHeaderBean;
import yyl.rabbitcloud.recyclerview.HeaderAndFooterRecyclerViewAdapter;
package yyl.rabbitcloud.main.home.fragment;






/**
 * Created by yyl on 2017/6/18.
 */

public class RecommendFragment extends MainFragment implements RecommendContract.View {

    @BindView(R.id.recommend_refresh)
    SwipeRefreshLayout mSwipeRefreshLayout;
    @BindView(R.id.recommend_recycler_view)
    RecyclerView mRecyclerView;

    @Inject
    RecommendPresenter mRecommendPresenter;

    private RollPagerView mRecommendBanner;
    private GridView mNavsGridView;

    private List<RecommendHeaderBean.DataBean.BannersBean> mBannersBeanList;
    private LiveTypeBannerAdapter mBannerAdapter;