package com.sheep.gamegroup.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
import com.kfzs.appstore.utils.adapter.recyclerview.ViewHolder;
import com.sheep.gamegroup.model.entity.NoviceGuidance;
import com.sheep.gamegroup.util.DetailTagHandler;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.ListUtil;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;

/**
 * Created by realicing on 2018/11/9.
 * realicing@sina.com
 */
public class AdpNoviceGuidance extends RecyclerViewAdapter<NoviceGuidance> {
    public AdpNoviceGuidance(Context context, List<NoviceGuidance> dataList) {
        super(context, R.layout.item_novice_guidance, dataList);
    }

    private DetailTagHandler tagHandler = new DetailTagHandler();
    @Override
    public void convert(ViewHolder viewHolder, final NoviceGuidance item, int position) {
        TextView item_novice_guidance_title = viewHolder.itemView.findViewById(R.id.item_novice_guidance_title);
//        VideoView item_novice_guidance_video = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video);
        final ImageView item_novice_guidance_image = viewHolder.itemView.findViewById(R.id.item_novice_guidance_image);
        final ImageView item_novice_guidance_video_image = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_image);
        final ImageView item_novice_guidance_video_control = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_control);
        final ImageView item_novice_guidance_video_full = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video_full);
        TextView item_novice_guidance_content = viewHolder.itemView.findViewById(R.id.item_novice_guidance_content);

        ViewUtil.setVisibility(item_novice_guidance_title, !TextUtils.isEmpty(item.getTitle()));
        ViewUtil.setVisibility(item_novice_guidance_content, !TextUtils.isEmpty(item.getContent()));
        ViewUtil.setVisibility(item_novice_guidance_image, !TextUtils.isEmpty(item.getImage_url()));
//        ViewUtil.setVisibility(item_novice_guidance_video, !TextUtils.isEmpty(item.getVideo_url()));
        ViewUtil.setVisibility(item_novice_guidance_video_control, !TextUtils.isEmpty(item.getVideo_url()));
        ViewUtil.setVisibility(item_novice_guidance_video_image, !TextUtils.isEmpty(item.getPre_url()));
        ViewUtil.setVisibility(item_novice_guidance_video_full, false);

        ViewUtil.setImage(item_novice_guidance_video_full, ViewUtil.getNetImgByName("fangda"));
        ViewUtil.setImage(item_novice_guidance_video_image, item.getPre_url());
        ViewUtil.setImage(item_novice_guidance_image, item.getImage_url());
        ViewUtil.setText(item_novice_guidance_title, item.getTitle());
        ViewUtil.setText(item_novice_guidance_content, item, G.WIDTH - G.getRealPix(32), tagHandler);
//        ViewUtil.setVideoAndFull(item_novice_guidance_video, item_novice_guidance_video_image, item_novice_guidance_video_control, item.getVideo_url());
        item_novice_guidance_video_control.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Jump2View.getInstance().goActPlayVideo(item.getVideo_url(), true);
            }
        });
//        if(!viewHolderList.contains(viewHolder) && !TextUtils.isEmpty(item.getVideo_url()))
//            viewHolderList.add(viewHolder);
    }
//
//    private List<ViewHolder> viewHolderList = ListUtil.emptyList();
    public void beforeNotifyDataSetChanged(){
        tagHandler.clear();
//        viewHolderList.clear();
    }
//    public void onPause() {
//        for (ViewHolder viewHolder : viewHolderList) {
//            VideoView item_novice_guidance_video = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video);
//            if(item_novice_guidance_video != null)
//                item_novice_guidance_video.pause();
//        }
//    }
//
//    public void onDestroy() {
//        for (ViewHolder viewHolder : viewHolderList) {
//            VideoView item_novice_guidance_video = viewHolder.itemView.findViewById(R.id.item_novice_guidance_video);
//            if(item_novice_guidance_video != null)
//                item_novice_guidance_video.stopPlayback();
//        }
//        viewHolderList.clear();
//    }
}
