package com.sheep.gamegroup.view.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
import com.kfzs.appstore.utils.adapter.recyclerview.ViewHolder;
import com.kfzs.duanduan.utils.NumberFormatUtils;
import com.sheep.gamegroup.model.entity.DiscoveryVideo;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.TimeUtil;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;
import java.util.Locale;

/**
 * Created by realicing on 2018/11/27.
 * realicing@sina.com
 * 小绵羊3.4.5新增 -- 视频
 */
public class AdpVideo extends RecyclerViewAdapter<DiscoveryVideo> {
    public AdpVideo(int layoutId, List<DiscoveryVideo> datas) {
        super(SheepApp.getInstance(), layoutId, datas);
    }

    private int width = (G.WIDTH - G.getRealPix(48)) / 2;

    @Override
    public void convert(ViewHolder viewHolder, final DiscoveryVideo item, int position) {
        ImageView item_video_cover = viewHolder.itemView.findViewById(R.id.item_video_cover);
        TextView item_video_play_no_tv = viewHolder.itemView.findViewById(R.id.item_video_play_no_tv);
        TextView item_video_time_tv = viewHolder.itemView.findViewById(R.id.item_video_time_tv);
        ViewUtil.setViewWH(item_video_cover, item.getCover(), width);
        ViewUtil.setImage(item_video_cover, item.getCover(), G.getRealPix(5));
        ViewUtil.setVisibility(item_video_play_no_tv, item.getPlay() > 0);
        ViewUtil.setText(item_video_play_no_tv, String.format(Locale.CHINA, "%s次播放", NumberFormatUtils.getText(item.getPlay())));
        ViewUtil.setText(item_video_time_tv, TimeUtil.getDurationText(item.getDuration()));

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Jump2View.getInstance().goActPlayVideoArticle(item);
            }
        });
    }
}
