package com.wasu.cs.ui;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.wasu.authsdk.AuthSDK;
import com.wasu.authsdk.IAuthInterface;
import com.wasu.cs.module.FavAndHisModule;
import com.wasu.cs.mvp.IView.IRecomMvpView;
import com.wasu.cs.mvp.model.AssetsDataModel;
import com.wasu.cs.mvp.presenter.MainRecomPagePresenter;
import com.wasu.cs.widget.MainPageLiveVideoView;
import com.wasu.frescoimagefetchermodule.FrescoImageFetcherModule;
import com.wasu.frescoimagefetchermodule.RecyclerPauseOnScrollListener;
import com.wasu.module.log.WLog;
import com.wasu.statistics.WasuStatistics;
import com.wasu.util.ConfigUtils;
import com.wasu.widgets.adapter.BaseFocusRecyclerViewAdapterTv;
import com.wasu.widgets.adapter.BaseFocusRecyclerViewHolderTv;
import com.wasu.widgets.focuswidget.FocusLinearLayout;
import com.wasu.widgets.focuswidget.IRecyclerView;
import com.wasu.widgets.focuswidget.ItemViewFocusSearchListener;
import com.wasu.widgets.focuswidget.SmoothHorizontalScrollView;
import com.wasu.widgets.focuswidget.TvRecyclerView;

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

import basic.db.model.DBProgramHistory;
import cn.com.wasu.main.AppUtil;
import cn.com.wasu.main.IntentMap;
import cn.com.wasu.main.R;

/**
 * @Description: 新版首页推荐屏
 *
 * @Author: Danxingxi
 *
 * @CreateDate: 2016/9/5 14:29
 */
public class MainRecomPageView extends ScrollView implements IRecomMvpView, View.OnClickListener{

    private final static String TAG = "MainRecomPageView";
    private final static String PageName = "推荐";
    private final static int CHANE_MSG = 100;
    private final static int LEFT_PAGE = 0;
    private final static int RIGHT_PAGE = 2;
    private final static int MSG_RecycleImageView = 1;
    private final static int MSG_ShowImageView = 2;
    private Context mContext;
    /**推荐屏数据请求地址**/
    private String url = "http://120.26.137.228/?s=2002&p=sjctRecomend&k=1&v=3&type=18&subjectId=53&indCatId=222985";

    /**直播播放器**/
    private MainPageLiveVideoView liveVideoView;
    private FocusLinearLayout focusLayout;
    /**品牌专区recyclerView**/
    private TvRecyclerView pinpaiRecyclerView;
    /**会员专享recyclerView**/
    private TvRecyclerView huiyuanRecyclerView;
    /**更多精彩recyclerView**/
    private TvRecyclerView moreRecyclerView;
    private TextView rowTitle01,rowTitle02,rowTitle03, hisName, hisTime;

    private ViewPager parentViewPager;
    private SmoothHorizontalScrollView headerScrollView;
    /**
     * 记录主动切屏时的焦点view
     */
    private View changePageFocusView;
    /**换一换itemView**/
    private FrameLayout changeItem01,changeItem02,changeItem03,changeItem04,changeItem05,changeButton;
    private ImageView free10Img, hfImg, searchImg;
    private LinearLayout hisImg;

    /**Adapter**/
    private PinpaiAdapter pinpaiAdapter;
    private HuiyuanAdapter huiyuanAdapter;
    private MoreAdapter moreAdapter;
    /**广告条左侧数据**/
    private List<AssetsDataModel> bannerLeft = new ArrayList<>();
    /*********换一换控件**********/

    ImageView img01, img02,img03,img04,img05 ;

    TextView tvName01,tvName02,tvName03,tvName04,tvName05, rowNum202;

    /*********换一换控件**********/

    /**推荐屏数据操作presenter**/
    private MainRecomPagePresenter mainRecomPagePresenter;
    /**
     * 所有的换一换数据
     */
    private List<AssetsDataModel> changeData = new ArrayList<>();
    /**
     *  换一换数据当前的五个数据
     */
    private List<AssetsDataModel> currentChangeData = new ArrayList<>();
    /**当提供的数据少于15个时就不支持换一换**/
    private boolean canChange = false;
    /**1到3依次换一换**/
    private int changePosition = 1;

    public MainRecomPageView(Context context, String url, ViewPager viewPager) {
        super(context, null, 0);
        this.parentViewPager = viewPager;
        init(context, url);
    }
    private void init(Context context, String url){
        this.mContext = context;
        this.url = url;
        setSmoothScrollingEnabled(true);
        setVerticalScrollBarEnabled(false);
        LayoutInflater.from(mContext).inflate(R.layout.main_recom_pageview, this);

        findViewById();
        initListener();
    }

    /**
     *
     */
    private void findViewById(){
        changeItem01 = (FrameLayout) findViewById(R.id.changeItem01);
        changeItem02 = (FrameLayout) findViewById(R.id.changeItem02);
        changeItem03 = (FrameLayout) findViewById(R.id.changeItem03);
        changeItem04 = (FrameLayout) findViewById(R.id.changeItem04);
        changeItem05 = (FrameLayout) findViewById(R.id.changeItem05);
        changeButton = (FrameLayout) findViewById(R.id.changeButton);

        initChangeView();

        rowTitle01 = (TextView) findViewById(R.id.rowTitle01);
        rowTitle02 = (TextView) findViewById(R.id.rowTitle02);
        rowTitle03 = (TextView) findViewById(R.id.rowTitle03);
        hisName = (TextView) findViewById(R.id.hisName);
        hisTime = (TextView) findViewById(R.id.hisTime);

        hfImg = (ImageView) findViewById(R.id.hfImg);
        searchImg = (ImageView) findViewById(R.id.searchImg);
        free10Img = (ImageView) findViewById(R.id.free10Img);
        hisImg = (LinearLayout) findViewById(R.id.hisImg);
        headerScrollView = (SmoothHorizontalScrollView) findViewById(R.id.headerScrollView);
        rowNum202 = (TextView) findViewById(R.id.rowNum202);
        liveVideoView  = (MainPageLiveVideoView) findViewById(R.id.liveVideoView);
        focusLayout = (FocusLinearLayout) findViewById(R.id.focusLayout);
        pinpaiRecyclerView = (TvRecyclerView) findViewById(R.id.pingpaiRecyclerView);
        huiyuanRecyclerView = (TvRecyclerView) findViewById(R.id.huiyuanRecyclerView);
        moreRecyclerView = (TvRecyclerView) findViewById(R.id.moreRecyclerView);
        /**RecyclerView滚动时停止Fresco图片加载**/
        huiyuanRecyclerView.addOnScrollListener(new RecyclerPauseOnScrollListener(true, true));
        liveVideoView.setOnStartListener(new MainPageLiveVideoView.LiveVideoViewOnStartListener() {
            @Override
            public void onResume() {
                /**当轮播播放器播放成后把页面滚动到最顶部*/
                scrollTo(0, 0);
            }
        });
        /**
         * 初始化适配器
         */
        pinpaiAdapter = new PinpaiAdapter(pinpaiRecyclerView);
        huiyuanAdapter = new HuiyuanAdapter(huiyuanRecyclerView);
        moreAdapter = new MoreAdapter(moreRecyclerView);

    }

    /**
     *
     */
    private void initListener(){
        focusLayout.setItemFocusChangeListener(new FocusLinearLayout.onItemFocusChangeListener() {
            @Override
            public void onItemFocusChange(View itemView, int position, boolean hasFocus) {
                View maskView = itemView.findViewById(R.id.maskView);
                View tvName = itemView.findViewById(R.id.tvName);
                View hisName01 = itemView.findViewById(R.id.hisName);
                if(hasFocus){
                    if(maskView != null){
                        maskView.setVisibility(INVISIBLE);
                    }
                    if(tvName != null){
//                        tvName.setVisibility(VISIBLE);
                        tvName.setSelected(true);
                    }
                    if(0 == position){
                        if(liveVideoView != null){
                            liveVideoView.onFocused();
                        }
                        if(hisName01 != null){
                            hisName01.setSelected(true);
                        }
                    }
                }else{
                    if(maskView != null){
                        maskView.setVisibility(VISIBLE);
                    }
                    if(0 == position){
                        if(hisName01 != null){
                            hisName01.setSelected(false);
                        }
                    }
                    if(tvName != null){
//                        tvName.setVisibility(INVISIBLE);
                        tvName.setSelected(false);
                    }
                }
                if(1 == position){
                    if(hasFocus){
                        liveVideoView.onFocused();
                    }else {
                        liveVideoView.onUnFocused();
                    }
                }

                if(2 == position){
                    if(hasFocus){
                        liveVideoView.onFocused();
                    }else{
                        liveVideoView.onUnFocused();
                    }
                }

                if(3 == position){
                    if(hasFocus){
                        liveVideoView.onFocused();
                    }else{
                        liveVideoView.onUnFocused();
                    }
                }
                if(4 == position){
                    if(hasFocus){
                        liveVideoView.pauseToPlay();
                    }else{

                    }
                }
            }
        });
        focusLayout.setItemViewFocusSearchListener(new FocusLinearLayout.ItemViewFocusSearchListener() {
            ObjectAnimator animator;
            @Override
            public boolean onItemViewFocusSearch(FocusLinearLayout parent, View itemView, int itemCount, int position, KeyEvent event) {

                if( position == 0 && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() != KeyEvent.ACTION_UP){
//                        animator = focusLayout.shockAnim(itemView);
                        changeViewPager(LEFT_PAGE);
                        return true;
                }

                if( position == 7 && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && event.getAction() != KeyEvent.ACTION_UP){
//                    animator = focusLayout.shockAnim(itemView);
                    changeViewPager(RIGHT_PAGE);
                    return true;
                }

                return false;
            }
        });
         // 第一排
        hfImg.setOnClickListener(this);
        searchImg.setOnClickListener(this);
        free10Img.setOnClickListener(this);
        changeButton.setOnClickListener(this);
        changeItem01.setOnClickListener(this);
        changeItem02.setOnClickListener(this);
        changeItem03.setOnClickListener(this);
        changeItem04.setOnClickListener(this);
        changeItem05.setOnClickListener(this);
        hisImg.setOnClickListener(this);
        pinpaiAdapter.setOnItemListener(new BaseFocusRecyclerViewAdapterTv.OnItemListener() {

            @Override
            public void onItemFocusChanged(IRecyclerView parent, View itemView, int position, boolean hasFocus) {
                View maskView = itemView.findViewById(R.id.maskView);
                View tvName = itemView.findViewById(R.id.tvName);
                if(hasFocus){
                    if(maskView != null){
                        maskView.setVisibility(INVISIBLE);
                    }
                    if(tvName!=null){
//                        tvName.setVisibility(VISIBLE);
                        tvName.setSelected(true);
                    }
                    /**当第二排资产获得焦点时马上暂停视频播放器**/
                    liveVideoView.pauseToPlay();
                }else{
                    if(maskView != null){
                        maskView.setVisibility(VISIBLE);
                    }
                    if(tvName!=null){
//                        tvName.setVisibility(INVISIBLE);
                        tvName.setSelected(false);
                    }
                }
            }
             // 第二排
            @Override
            public void onItemClick(IRecyclerView parent, View itemView, int position) {
                AppUtil.playEnter = PageName+"_"+"2_"+(position+1);
                WasuStatistics.getInstance().click(String.valueOf(pinpaiAdapter.getItemData(position).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","2_"+(position+1), String.valueOf(pinpaiAdapter.getItemData(position).getId()), pinpaiAdapter.getItemData(position).getTitle());
                IntentMap.startIntent(mContext, null, pinpaiAdapter.getItemData(position).getLayout(), pinpaiAdapter.getItemData(position).getJsonUrl(), null);
            }

        });
        pinpaiRecyclerView.setItemViewFocusSearchListener(new ItemViewFocusSearchListener() {
            @Override
            public boolean onItemViewFocusSearch(IRecyclerView parent, View itemView, int itemCount, int position, KeyEvent event) {
                if((position+1 == itemCount || position+2 == itemCount) && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT
                        && event.getAction() != KeyEvent.ACTION_UP){
//                    animator = pinpaiRecyclerView.shockAnim(itemView);
                    changeViewPager(RIGHT_PAGE);
                    return true;
                }
                if(position == 0 && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() != KeyEvent.ACTION_UP){
//                        animator = pinpaiRecyclerView.shockAnim(itemView);
                    changeViewPager(LEFT_PAGE);
                        return true;
                }
                return false;
            }
        });



        moreAdapter.setOnItemListener(new BaseFocusRecyclerViewAdapterTv.OnItemListener() {
            @Override
            public void onItemFocusChanged(IRecyclerView parent, View itemView, int position, boolean hasFocus) {
                View maskView = itemView.findViewById(R.id.maskView);
                View tvName = itemView.findViewById(R.id.tvName);
                if (hasFocus) {
                    if(maskView != null){
                        maskView.setVisibility(INVISIBLE);
                    }
                    if(tvName != null){
//                        tvName.setVisibility(VISIBLE);
                        tvName.setSelected(true);
                    }
                } else {
                    if(maskView != null){
                        maskView.setVisibility(VISIBLE);
                    }
                    if(tvName != null){
//                        tvName.setVisibility(INVISIBLE);
                        tvName.setSelected(false);
                    }
                }
            }

             // 第四排
            @Override
            public void onItemClick(IRecyclerView parent, View itemView, int position) {
                AppUtil.playEnter = PageName+"_"+"4_"+(position+1);
                WasuStatistics.getInstance().click(String.valueOf(moreAdapter.getItemData(position).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","4_"+(position+1), String.valueOf(moreAdapter.getItemData(position).getId()), moreAdapter.getItemData(position).getTitle());
                IntentMap.startIntent(mContext,null, moreAdapter.getItemData(position).getLayout(), moreAdapter.getItemData(position).getJsonUrl(),null);
            }

        });
        moreRecyclerView.setItemViewFocusSearchListener(new ItemViewFocusSearchListener() {
            @Override
            public boolean onItemViewFocusSearch(IRecyclerView parent, View itemView, int itemCount, int position, KeyEvent event) {
                if (position + 1 == itemCount && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && event.getAction() != KeyEvent.ACTION_UP) {
//                    animator = moreRecyclerView.shockAnim(itemView);
                    changeViewPager(RIGHT_PAGE);
                    return true;
                }
                if (position == 0 && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() != KeyEvent.ACTION_UP) {
//                    animator = moreRecyclerView.shockAnim(itemView);
                    changeViewPager(LEFT_PAGE);
                    return true;
                }
                return false;
            }
        });

        huiyuanAdapter.setOnItemListener(new BaseFocusRecyclerViewAdapterTv.OnItemListener() {
            @Override
            public void onItemFocusChanged(IRecyclerView parent, View itemView, int position, boolean hasFocus) {
                View maskView = itemView.findViewById(R.id.maskView);
                View tvName = itemView.findViewById(R.id.tvName);
                if(hasFocus){
                    rowNum202.setText((position+1)+" / "+huiyuanAdapter.getItemCount());
                    if(maskView != null){
                        maskView.setVisibility(INVISIBLE);
                    }
                    if(tvName != null){
//                        tvName.setVisibility(VISIBLE);
                        tvName.setSelected(true);
                    }
                }else{
                    if(maskView != null){
                        maskView.setVisibility(VISIBLE);
                    }
                    if(tvName != null){
//                        tvName.setVisibility(INVISIBLE);
                        tvName.setSelected(false);
                    }
                }
            }

             // 第三排
            @Override
            public void onItemClick(IRecyclerView parent, View itemView, int position) {
                AppUtil.playEnter = PageName+"_"+"3_"+(position+1);
                WasuStatistics.getInstance().click(String.valueOf(huiyuanAdapter.getItemData(position).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","3_"+(position+1), String.valueOf(huiyuanAdapter.getItemData(position).getId()), huiyuanAdapter.getItemData(position).getTitle());
                IntentMap.startIntent(mContext,null, huiyuanAdapter.getItemData(position).getLayout(), huiyuanAdapter.getItemData(position).getJsonUrl(),null);
            }

        });
        huiyuanRecyclerView.setItemViewFocusSearchListener(new ItemViewFocusSearchListener() {
            @Override
            public boolean onItemViewFocusSearch(IRecyclerView parent, View itemView, int itemCount, int position, KeyEvent event) {
                if( event.getAction() != KeyEvent.ACTION_UP &&(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP ||  event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN)){
                    rowNum202.setText("0 / "+huiyuanAdapter.getItemCount());
                }
                if (position + 1 == itemCount && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && event.getAction() != KeyEvent.ACTION_UP) {
//                    animator = huiyuanRecyclerView.shockAnim(itemView);
                    rowNum202.setText("0 / "+huiyuanAdapter.getItemCount());
                    changeViewPager(RIGHT_PAGE);
                    return true;
                }
                if (position == 0 && event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && event.getAction() != KeyEvent.ACTION_UP) {
//                    animator = huiyuanRecyclerView.shockAnim(itemView);
                    rowNum202.setText("0 / "+huiyuanAdapter.getItemCount());
                    changeViewPager(LEFT_PAGE);
                    return true;
                }

                return false;
            }
        });

        mainRecomPagePresenter = new MainRecomPagePresenter();
        mainRecomPagePresenter.attachView(this);
        mainRecomPagePresenter.getRecomPageData(url);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        /**
         * 防止第一次安装apk时候进入首页时丢失焦点
         */
    }

    /**
     * 主动使ViewPager翻页
     * @param viewPagerPosition
     */
    @Override
    public void changeViewPager(int viewPagerPosition){
        if(parentViewPager != null){
//            liveVideoView.pauseToPlay();
            liveVideoView.stopPlay(); //为了降低内存占用，翻页时把暂停视频播放改为停止视频播放
            changePageFocusView = findFocus();
            parentViewPager.setCurrentItem(viewPagerPosition, true);
        }
    }

    /**
     *
     */
    @Override
    public void scrollToTop() {
        fullScroll(ScrollView.FOCUS_UP);
    }

    @Override
    protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
        if (getChildCount() == 0)
            return 0;
        int height = getHeight();
        int screenTop = getScrollY();
        int screenBottom = screenTop + height;
        int fadingEdge = this.getResources().getDimensionPixelSize(R.dimen.d_160dp);
        if (rect.top > 0) {
            screenTop += fadingEdge;
        }
        if (rect.bottom < getChildAt(0).getHeight()) {
            screenBottom -= fadingEdge;
        }
        //
        int scrollYDelta = 0;
        if (rect.bottom > screenBottom && rect.top > screenTop) {
            if (rect.height() > height) {
                scrollYDelta += (rect.top - screenTop);
            } else {
                scrollYDelta += (rect.bottom - screenBottom);
            }
            int bottom = getChildAt(0).getBottom();
            int distanceToBottom = bottom - screenBottom;
            scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
        } else if (rect.top < screenTop && rect.bottom < screenBottom) {
            if (rect.height() > height) {
                scrollYDelta -= (screenBottom - rect.bottom);
            } else {
                scrollYDelta -= (screenTop - rect.top);
            }
            scrollYDelta = Math.max(scrollYDelta, -getScrollY());
        }
        return scrollYDelta;
    }

    /**
     * 第一次请求焦点
     * @param direction
     */
    public void firstRequestFocus(int direction ){
        onRequestFocusInDescendants(direction ,null);
    }

    @Override
    protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
        if(previouslyFocusedRect == null) {
            if (direction == View.FOCUS_DOWN) {
                if(headerScrollView!=null)
                    headerScrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT);
                liveVideoView.requestFocus();
                return true;
            }else{
               if (0 == AppUtil.MAIN_PAGERVIEW_POSITION){
                   if(liveVideoView!= null){
                       scrollTo(0, 0);
                       if(headerScrollView!=null)
                       headerScrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT);
                       liveVideoView.requestFocus();
                       return true;
                   }
               }else if(2 == AppUtil.MAIN_PAGERVIEW_POSITION){
                   if(changeButton != null && headerScrollView != null){
                       scrollTo(0, 0);
                       headerScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                       changeButton.requestFocus();
                       return true;
                   }
               }
            }
        }
        return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
    }

    /**
     * 修改scrollview的滚动速度
     * @param velocityY
     */
    @Override
    public void fling(int velocityY) {
        super.fling(velocityY*8);
    }

    /**
     * 是否为用户主动点击导致的用户登陆
     */
    boolean isClickToBindUserData  = false;
    /**
     * Called when a view has been clicked.
     * 第一排功能按钮点击事件
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.free10Img: // 十天包免费领
                if(bannerLeft == null || bannerLeft.size() <1){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_2";
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_2","","活动");
                isClickToBindUserData = true;
                IntentMap.startIntent(mContext, null, "Wasu_UserCenter", bannerLeft.get(0).getJsonUrl(), null);
                break;
            case R.id.hfImg: // 历史收藏
                if(bannerLeft == null || bannerLeft.size() <1){
                    break;
                }
                AppUtil.playEnter = PageName+"_历史收藏";
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_3","","历史收藏");
                IntentMap.startIntent(mContext, null, bannerLeft.get(1).getLayout(), "", null);
                break;
            case R.id.searchImg: // children_search
                if(bannerLeft == null || bannerLeft.size() <1){
                    break;
                }
                AppUtil.playEnter = PageName+"_搜索";
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_4","","children_search");
                String recommendUrl = bannerLeft.get(2).getJsonUrl();
                if(recommendUrl == null || TextUtils.isEmpty(recommendUrl)){
                    return;
                }
                IntentMap.startIntent(mContext, null, bannerLeft.get(2).getLayout(), recommendUrl, null);
                break;
            case R.id.hisImg:
                if(firstHistory != null){
                    int showType = firstHistory.showType;
                    //电影电视剧直接进详情页
                    if(DBProgramHistory.SHOW_TYPE_MOVIE == showType || DBProgramHistory.SHOW_TYPE_SERIES == showType){
                        IntentMap.startIntent(mContext, null,null, firstHistory.detailUrl, ActivityDetail.class);
                    }else if(DBProgramHistory.SHOW_TYPE_NEWS == showType){ //短视频直接进播放器
                        IntentMap.startIntent(mContext, null,null, firstHistory.detailUrl, ActivityPlayer.class);
                    }
                    AppUtil.playEnter = PageName+"_1_1";
                    WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_1","","观看历史-登陆");
                }
                break;
            case R.id.changeButton:
                /**避免频繁换一换**/
                AppUtil.playEnter = PageName+"_换一换";
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_11","","换一换");
                changeHandler.removeMessages(CHANE_MSG);
                changeHandler.sendEmptyMessageDelayed(CHANE_MSG, 500);
                break;
            case R.id.changeItem01:
                if(!canChange){
                    break;
                }
                if(currentChangeData==null || currentChangeData.size()<5){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_6";
                WasuStatistics.getInstance().click(String.valueOf(currentChangeData.get(0).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_6", String.valueOf(currentChangeData.get(0).getId()), "推荐1");
                IntentMap.startIntent(mContext,null, currentChangeData.get(0).getLayout(), currentChangeData.get(0).getJsonUrl(),null);
                break;
            case R.id.changeItem02:
                if(!canChange){
                    break;
                }
                if(currentChangeData==null || currentChangeData.size()<5){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_7";
                WasuStatistics.getInstance().click(String.valueOf(currentChangeData.get(1).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_7", String.valueOf(currentChangeData.get(1).getId()), "推荐2");
                IntentMap.startIntent(mContext,null, currentChangeData.get(1).getLayout(), currentChangeData.get(1).getJsonUrl(),null);
                break;
            case R.id.changeItem03:
                if(!canChange){
                    break;
                }
                if(currentChangeData==null || currentChangeData.size()<5){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_8";
                WasuStatistics.getInstance().click(String.valueOf(currentChangeData.get(2).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_8", String.valueOf(currentChangeData.get(2).getId()),"推荐3");
                IntentMap.startIntent(mContext,null, currentChangeData.get(2).getLayout(), currentChangeData.get(2).getJsonUrl(),null);
                break;
            case R.id.changeItem04:
                if(!canChange){
                    break;
                }
                if(currentChangeData==null || currentChangeData.size()<5){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_9";
                WasuStatistics.getInstance().click(String.valueOf(currentChangeData.get(3).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_9", String.valueOf(currentChangeData.get(3).getId()),"推荐4");
                IntentMap.startIntent(mContext,null, currentChangeData.get(3).getLayout(), currentChangeData.get(3).getJsonUrl(),null);
                break;
            case R.id.changeItem05:
                if(!canChange){
                    break;
                }
                if(currentChangeData==null || currentChangeData.size()<5){
                    break;
                }
                AppUtil.playEnter = PageName+"_1_10";
                WasuStatistics.getInstance().click(String.valueOf(currentChangeData.get(4).getId()));
                WasuStatistics.getInstance().homeItemClick(parentViewPager.getCurrentItem(),"推荐","1_10", String.valueOf(currentChangeData.get(4).getId()), "推荐5");
                IntentMap.startIntent(mContext,null, currentChangeData.get(4).getLayout(), currentChangeData.get(4).getJsonUrl(),null);
                break;
        }
    }

    /**
     * 换一换处理
     */
    private final Handler changeHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            changeRecom(false);
            return false;
        }
    });

    /**
     * 换一换推荐屏第一排的推荐资产
     * @param isFirstInit 是否为第一次加载
     */

    private void changeRecom( boolean isFirstInit){
        if(!isFirstInit){
            if(!canChange){ //换一换数据少于15时就不支持换一换
                Toast.makeText(mContext, "数据准备中，请稍后再试！" , Toast.LENGTH_SHORT).show();
                return;
            }
        }else{
            changePosition = 1;
        }
        switch (changePosition){
            case 1:
                changePosition = 2;
                currentChangeData.clear();
                for(int i=0; i<=4;i++){
                    currentChangeData.add(changeData.get(i));
                }
                changeRecomData();
                break;
            case 2:
                changePosition = 3;
                currentChangeData.clear();
                for(int i=5;i<=9;i++){
                    currentChangeData.add(changeData.get(i));
                }
                changeRecomData();
                break;
            case 3:
                changePosition = 1;
                currentChangeData.clear();
                for(int i=10;i<=14;i++){
                    currentChangeData.add(changeData.get(i));
                }
                changeRecomData();
                break;
        }
    }

    /**
     * 初始化换一换控件
     */
    private void initChangeView(){
         img01 = (ImageView) changeItem01.findViewById(R.id.ivPic);
         img02 = (ImageView) changeItem02.findViewById(R.id.ivPic);
         img03 = (ImageView) changeItem03.findViewById(R.id.ivPic);
         img04 = (ImageView) changeItem04.findViewById(R.id.ivPic);
         img05 = (ImageView) changeItem05.findViewById(R.id.ivPic);

         tvName01 = (TextView) changeItem01.findViewById(R.id.tvName);
         tvName02 = (TextView) changeItem02.findViewById(R.id.tvName);
         tvName03 = (TextView) changeItem03.findViewById(R.id.tvName);
         tvName04 = (TextView) changeItem04.findViewById(R.id.tvName);
         tvName05 = (TextView) changeItem05.findViewById(R.id.tvName);
    }

    private static String sTitle_001 = null;
    private TextWatcher textWatcher_001 =  new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            if(s!=null && !TextUtils.isEmpty(s.toString())){
                sTitle_001 = s.toString();
            }
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if(TextUtils.isEmpty(s.toString()) && !TextUtils.isEmpty(sTitle_001)){
                tvName01.setText(sTitle_001);
            }
        }
    };
    /***
     * 更换换一换的数据
     */
    private void changeRecomData(){
        if (currentChangeData == null || currentChangeData.size()<5){
            WLog.d(TAG, "刷新数据不满足，返回");
            return;
        }

        if(img01 != null && tvName01 != null){
            FrescoImageFetcherModule.getInstance().attachImage(currentChangeData.get(0).getPicUrl(), img01);
            tvName01.setText(currentChangeData.get(0).getTitle());

            //fix bug in ranbow_box ,sometimes can not see first title
            tvName01.addTextChangedListener(textWatcher_001);

        }
        if(img02 != null&& tvName02 != null){
            FrescoImageFetcherModule.getInstance().attachImage(currentChangeData.get(1).getPicUrl(), img02);
            tvName02.setText(currentChangeData.get(1).getTitle());
        }
        if(img03 != null&& tvName03 != null){
            FrescoImageFetcherModule.getInstance().attachImage(currentChangeData.get(2).getPicUrl(), img03);
            tvName03.setText(currentChangeData.get(2).getTitle());
        }
        if(img04 != null&& tvName04 != null){
            FrescoImageFetcherModule.getInstance().attachImage(currentChangeData.get(3).getPicUrl(), img04);
            tvName04.setText(currentChangeData.get(3).getTitle());
        }
        if(img05 != null&& tvName05 != null){
            FrescoImageFetcherModule.getInstance().attachImage(currentChangeData.get(4).getPicUrl(), img05);
            tvName05.setText(currentChangeData.get(4).getTitle());
        }
    }

    /**
     * 暂停视频播放
     */
    public void liveVideoPause(){
        if(liveVideoView != null){
            liveVideoView.pauseToPlay();
        }
    }
    /**
     * 停止视频播放
     */
    public void liveVideoStop(){
        if(liveVideoView != null){
            liveVideoView.stopPlay();
        }
    }
    /**
     * 恢复视频播放
     */
    public void liveVideoResume(){
        if(liveVideoView != null){
            liveVideoView.onFocused();
        }
    }

    /**
     * 播放器是否为全屏
     */
    public boolean liveVideoIsFullScreen(){
        if(liveVideoView != null){
            return liveVideoView.VideoViewIsFullScreen();
        }
        return false;
    }

    public boolean liveVideoIsCover(){
        if(liveVideoView != null){
            return liveVideoView.isCover();
        }
        return true;
    }

    @Override
    public void getBannerLeftSuccess(List<AssetsDataModel> blData) {
        bannerLeft = blData;
        if(free10Img==null || hfImg==null || searchImg==null){  //防止数据加载过快，控件还没来得及初始化
            hfImg = (ImageView) findViewById(R.id.hfImg);
            searchImg = (ImageView) findViewById(R.id.searchImg);
            free10Img = (ImageView) findViewById(R.id.free10Img);
        }
        /**第一排左边功能按钮**/
        FrescoImageFetcherModule.getInstance().attachImage(blData.get(0).getPicUrl(), free10Img);
        FrescoImageFetcherModule.getInstance().attachImage(blData.get(1).getPicUrl(), hfImg);
        FrescoImageFetcherModule.getInstance().attachImage(blData.get(2).getPicUrl(), searchImg);
        // 首次启动判断用户是否登录
        bindUserData();
    }

    @Override
    public void getBannerMiddleSuccess(List<AssetsDataModel> bmData) {
        if(liveVideoView != null){
            liveVideoView.initData(bmData);
        }
        postDelayed(new Runnable() {
            @Override
            public void run() {
                if(liveVideoView!=null && !liveVideoView.isCover() && !liveVideoView.hasFocus()){
                    liveVideoView.requestFocus();
                    WLog.d("danxx","首次安装启动请求焦点");
                }else{
                    WLog.d("danxx","不满足首次请求焦点条件");
                }
            }
        }, 400);
    }

    @Override
    public void getBannerRightSuccess(List<AssetsDataModel> brData) {
        //换一换数据
        changeData = brData;
        if(changeData.size()<15){
            canChange = false;
        } else {
            canChange = true;
        }
        changeRecom(true);
    }

    /**
     * 品牌专区数据获取成功
     *
     * @param bodyData
     **/
    @Override
    public void getBody1DataSuccess(String rowTitle, List<AssetsDataModel> bodyData) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
        gridLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if(0==position || 1==position || 2==position){
                    return 2;
                }
                return 1;
            }
        });

        pinpaiRecyclerView.setLayoutManager(gridLayoutManager);
        pinpaiRecyclerView.setAdapter(pinpaiAdapter);
        rowTitle01.setText(rowTitle);
        pinpaiAdapter.setData(bodyData);
        pinpaiAdapter.notifyDataSetChanged();
    }

    /**
     * 会员专区数据获取成功
     *
     * @param bodyListData
     **/
    @Override
    public void getBody2DataSuccess(String rowTitle, List<AssetsDataModel> bodyListData) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        huiyuanRecyclerView.setLayoutManager(linearLayoutManager);

        huiyuanRecyclerView.setAdapter(huiyuanAdapter);
        rowTitle02.setText(rowTitle);
        huiyuanAdapter.setData(bodyListData);
        huiyuanAdapter.notifyDataSetChanged();
        rowNum202.setText("0 / "+huiyuanAdapter.getItemCount());
    }

    /**
     * 更多惊喜数据获取成功
     *
     * @param bodyListData
     **/
    @Override
    public void getBody3DataSuccess(String rowTitle, List<AssetsDataModel> bodyListData) {
        LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(mContext);
        linearLayoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);
        moreRecyclerView.setLayoutManager(linearLayoutManager2);

        moreRecyclerView.setAdapter(moreAdapter);
        rowTitle03.setText(rowTitle);
        moreAdapter.setData(bodyListData);
        moreAdapter.notifyDataSetChanged();
    }

    /**
     * 获取数据失败
     *
     * @param e
     */
    @Override
    public void getDataError(Throwable e) {
        e.printStackTrace();
        WLog.e(TAG ,e.getMessage());
    }

    /**
     * 显示loading
     */
    @Override
    public void showProgress() {

    }

    /**
     * 隐藏loading
     */
    @Override
    public void hideProgress() {

    }
    DBProgramHistory firstHistory;
    /**
     * 检测用户是否登录
     */
    public void bindUserData(){
        String headUrl = ConfigUtils.getString(mContext, "usercenter", "headUrl");
        // 判断用户是否登录
        if (!TextUtils.isEmpty(headUrl) && AuthSDK.getInstance().getValue(IAuthInterface.KEY_ENCRYPTV) != null
                && AuthSDK.getInstance().getValue(IAuthInterface.KEY_PUBLICKEY) != null) {
            free10Img.setVisibility(GONE);
            hisImg.setVisibility(VISIBLE);
            firstHistory = null;
            firstHistory =  FavAndHisModule.getInstance().readFirstHistory();
            if(firstHistory == null){
                free10Img.setVisibility(GONE);
                hisImg.setVisibility(VISIBLE);
                hisName.setText("暂无历史记录");
                hisTime.setVisibility(GONE);
            }else {
                String name = firstHistory.programName;
                int showType = firstHistory.showType;
                String time = "";
                if(DBProgramHistory.SHOW_TYPE_MOVIE == showType || DBProgramHistory.SHOW_TYPE_NEWS == showType){
                    time ="您观看至 "+getTextTime(firstHistory.lastPlayTime);
                }else if(DBProgramHistory.SHOW_TYPE_SERIES == showType){
                    time ="您观看至第 "+firstHistory.lastSeries+" 集";
                }
                hisName.setText(name);
                hisTime.setText(time);
                hisName.setVisibility(VISIBLE);
                hisName.setVisibility(VISIBLE);
            }
            if(isClickToBindUserData){
                postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if(hisImg.getVisibility() == VISIBLE){
                            hisImg.requestFocus();
                            isClickToBindUserData = false;
                        }
                    }
                },300);
            }
        }else{
            free10Img.setVisibility(VISIBLE);
            hisImg.setVisibility(GONE);
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if(mainRecomPagePresenter != null){
            mainRecomPagePresenter.detachView();
        }
        if(changeData != null){
            changeData.clear();
            changeData = null;
        }
        if(currentChangeData != null){
            currentChangeData.clear();
            currentChangeData = null;
        }
    }

    /**
     * 格式化时间
     * @param time
     * @return
     */
    private String getTextTime(long time) {
        long sec = Math.round(time / 1000.0);//显示少一秒
        long min = sec / 60;
        long hour = min / 60;
        if (min > 0) {
            if (hour > 0) {
                return getformat(hour) + ":" + getformat(min % 60) + ":"
                        + getformat(sec % 60);
            } else {
                return "00:" + getformat(min) + ":" + getformat(sec % 60);
            }
        } else {
            return "00:00:" + getformat(sec);
        }
    }

    private String getformat(long time) {
        if (time < 10) {
            return "0" + time;
        } else {
            return time + "";
        }
    }
    /************************************************************************************/
    class PinpaiAdapter extends BaseFocusRecyclerViewAdapterTv<AssetsDataModel> {

        public PinpaiAdapter(TvRecyclerView recyclerView) {
            super(recyclerView);
        }

        /**
         * 创建item view
         *
         * @param parent
         * @param viewType
         * @return
         */
        @Override
        protected BaseFocusRecyclerViewHolderTv createItem(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_home_recom_span, parent, false);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        /**
         * 绑定数据
         *
         * @param holder
         * @param position
         */
        @Override
        protected void bindData(BaseFocusRecyclerViewHolderTv holder, int position) {
//            ImageFetcherModule.getInstance().attachImage(getItemData(position).getPicUrl(),  ((MyViewHolder)holder).ivPic);
            holder.itemView.setTag(getItemData(position).getPicUrl());
            FrescoImageFetcherModule.getInstance().attachImage(getItemData(position).getPicUrl(), ((MyViewHolder)holder).ivPic);
            ((MyViewHolder) holder).itemView.setContentDescription(getItemData(position).getTitle());
        }

        class MyViewHolder extends BaseFocusRecyclerViewHolderTv{

            public ImageView ivPic;

            /**
             * 创建FocusRecyclerView的itemView
             * @param itemView          item View
             */
            public MyViewHolder(View itemView) {
                super(itemView, getItemParent(), getItemListener());
                ivPic = (ImageView) itemView.findViewById(R.id.ivPic);
            }

            @Override
            protected View getView() {
                return null;
            }
        }
    }

    /****************************************************************************/
    class HuiyuanAdapter extends BaseFocusRecyclerViewAdapterTv<AssetsDataModel> {

        public HuiyuanAdapter(TvRecyclerView recyclerView) {
            super(recyclerView);
        }

        /**
         * 创建item view
         *
         * @param parent
         * @param viewType
         * @return
         */
        @Override
        protected BaseFocusRecyclerViewHolderTv createItem(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_home_recom, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        /**
         * 绑定数据
         *
         * @param holder
         * @param position
         */
        @Override
        protected void bindData(BaseFocusRecyclerViewHolderTv holder, int position) {
            holder.itemView.setTag(getItemData(position).getPicUrl());
            FrescoImageFetcherModule.getInstance().attachImage(getItemData(position).getPicUrl(), ((MyViewHolder)holder).ivPic);
            ((MyViewHolder)holder).tvName.setText(getItemData(position).getTitle());
        }

        class MyViewHolder extends BaseFocusRecyclerViewHolderTv{

            public ImageView ivPic;
            public TextView tvName;
            /**
             * 创建FocusRecyclerView的itemView
             * @param itemView          item View
             */
            public MyViewHolder(View itemView) {
                super(itemView, getItemParent(), getItemListener());
                ivPic = (ImageView) itemView.findViewById(R.id.ivPic);
                tvName = (TextView) itemView.findViewById(R.id.tvName);
            }

            @Override
            protected View getView() {
                return null;
            }
        }
    }

    /****************************************************************************/
    class MoreAdapter extends BaseFocusRecyclerViewAdapterTv<AssetsDataModel> {


        public MoreAdapter(TvRecyclerView recyclerView) {
            super(recyclerView);
        }

        /**
         * 创建item view
         *
         * @param parent
         * @param viewType
         * @return
         */
        @Override
        protected BaseFocusRecyclerViewHolderTv createItem(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_home_recom_more, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        /**
         * 绑定数据
         *
         * @param holder
         * @param position
         */
        @Override
        protected void bindData(BaseFocusRecyclerViewHolderTv holder, int position) {
            holder.itemView.setTag(getItemData(position).getPicUrl());
            FrescoImageFetcherModule.getInstance().attachImage(getItemData(position).getPicUrl(), ((MyViewHolder)holder).ivPic);
            ((MyViewHolder)holder).tvName.setText(getItemData(position).getTitle());
            ((MyViewHolder) holder).itemView.setContentDescription(getItemData(position).getTitle());
        }

        class MyViewHolder extends BaseFocusRecyclerViewHolderTv{

            public ImageView ivPic;
            TextView tvName;
            /**
             * 创建FocusRecyclerView的itemView
             *
             * @param itemView          item View
             */
            public MyViewHolder(View itemView) {
                super(itemView, getItemParent(), getItemListener());
                ivPic = (ImageView) itemView.findViewById(R.id.ivPic);
                tvName = (TextView) findViewById(R.id.tvName);
            }

            @Override
            protected View getView() {
                return null;
            }
        }
    }
    /*********************************************************************/
    /***********************************************************************************************/
    /**
     * 回收和显示页面上的图片资源，减少内存占用
     */
    final Handler imageViewHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            int what = msg.what;
            if(MSG_RecycleImageView == what){
                recycleImageViewTask();
            }else if(MSG_ShowImageView == what){
                showImageViewTask();
            }
            return false;
        }
    });

    public void recycleImageView(){
//        imageViewHandler.removeMessages(MSG_ShowImageView);
//        imageViewHandler.removeMessages(MSG_RecycleImageView);
//        imageViewHandler.sendEmptyMessageDelayed(MSG_RecycleImageView, 600);
    }

    public void showImageView(){
//        imageViewHandler.removeMessages(MSG_ShowImageView);
//        imageViewHandler.removeMessages(MSG_RecycleImageView);
//        imageViewHandler.sendEmptyMessageDelayed(MSG_ShowImageView, 600);
    }

    private void recycleImageViewTask(){

        if(searchImg!=null){
            searchImg.setImageBitmap(null);
        }
        if(hfImg!=null){
            hfImg.setImageBitmap(null);
        }
        if(free10Img!=null){
            free10Img.setImageBitmap(null);
        }
        if(img01!=null){
            img01.setImageBitmap(null);
        }
        if(img02!=null){
            img02.setImageBitmap(null);
        }
        if(img03!=null){
            img03.setImageBitmap(null);
        }
        if(img04!=null){
            img04.setImageBitmap(null);
        }
        if(img05!=null){
            img05.setImageBitmap(null);
        }
        if(pinpaiRecyclerView != null && pinpaiRecyclerView.getChildCount()>0){
            int itemCount = pinpaiRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = pinpaiRecyclerView.getChildAt(i);
                if(itemView != null){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    if(imageView != null){
                        imageView.setImageBitmap(null);
                    }
                }
            }
        }
        if(huiyuanRecyclerView != null && huiyuanRecyclerView.getChildCount()>0){
            int itemCount = huiyuanRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = huiyuanRecyclerView.getChildAt(i);
                if(itemView != null){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    if(imageView != null){
                        imageView.setImageBitmap(null);
                    }
                }
            }
        }
        if(moreRecyclerView != null && moreRecyclerView.getChildCount()>0){
            int itemCount = moreRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = moreRecyclerView.getChildAt(i);
                if(itemView != null){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    if(imageView != null){
                        imageView.setImageBitmap(null);
                    }
                }
            }
        }
    }

    private void showImageViewTask(){
        WLog.d("danxx", "showImageViewTask--->");
        if(free10Img!=null && free10Img.getTag()!=null){
            FrescoImageFetcherModule.getInstance().attachImage(free10Img.getTag().toString(), free10Img);
        }
        if(hfImg!=null && hfImg.getTag()!=null){
            FrescoImageFetcherModule.getInstance().attachImage(hfImg.getTag().toString(), hfImg);
        }
        if(searchImg!=null && searchImg.getTag()!=null){
            FrescoImageFetcherModule.getInstance().attachImage(searchImg.getTag().toString(), searchImg);
        }
        /**显示换一换数据**/
        changeRecomData();
        if(pinpaiRecyclerView != null && pinpaiRecyclerView.getChildCount()>0){
            int itemCount = pinpaiRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = pinpaiRecyclerView.getChildAt(i);
                String url = itemView.getTag().toString();
                if(itemView != null && url != null && !TextUtils.isEmpty(url)){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    FrescoImageFetcherModule.getInstance().attachImage(url, imageView);
                }
            }
        }
        if(huiyuanRecyclerView != null && huiyuanRecyclerView.getChildCount()>0){
            int itemCount = huiyuanRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = huiyuanRecyclerView.getChildAt(i);
                String url = itemView.getTag().toString();
                if(itemView != null && url != null && !TextUtils.isEmpty(url)){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    FrescoImageFetcherModule.getInstance().attachImage(url, imageView);
                }
            }
        }
        if(moreRecyclerView != null && moreRecyclerView.getChildCount()>0){
            int itemCount = moreRecyclerView.getChildCount();
            for(int i=0;i<itemCount;i++){
                View itemView = moreRecyclerView.getChildAt(i);
                String url = itemView.getTag().toString();
                if(itemView != null && url != null && !TextUtils.isEmpty(url)){
                    ImageView imageView = (ImageView) itemView.findViewById(R.id.ivPic);
                    FrescoImageFetcherModule.getInstance().attachImage(url, imageView);
                }
            }
        }
    }
}
