package com.sheep.gamegroup.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.DiscoveryVideo;
import com.sheep.gamegroup.view.adapter.AdpVideo;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;

import org.afinal.simplecache.ApiKey;

import io.reactivex.Observable;

/**
 * Created by realicing on 2018/9/7.
 * realicing@sina.com
 * 小绵羊3.4.5新增 -- 发现视频列表
 */
public class FgtArticleVideo extends BaseListFragment2<DiscoveryVideo> {
    @Override
    public void initView() {
        super.initView();
        view_list.setPadding(G.getRealPix(8), G.getRealPix(14), G.getRealPix(8), G.getRealPix(14));
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
//        layoutManager.setItemPrefetchEnabled(true);
//        layoutManager.setMeasurementCacheEnabled(true);
        return layoutManager;
    }

    @Override
    protected RecyclerView.Adapter getAdapter() {
        return new AdpVideo(R.layout.item_video, list);
    }

    @Override
    protected String getKey(int page, int per_page) {
        return ApiKey.pageKeyUrl2(ApiKey.getVideoList, page, per_page);
    }

    @Override
    protected Observable<BaseMessage> getApi(ApiService apiService) {
        return apiService.getVideoList(page, per_page);
    }

    @Override
    protected Class<DiscoveryVideo> getTClass() {
        return DiscoveryVideo.class;
    }

    private int type;

    public static FgtArticleVideo newInstance(int type) {
        FgtArticleVideo fgt = new FgtArticleVideo();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        fgt.setArguments(bundle);
        return fgt;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            type = bundle.getInt("type", 0);
        }
    }

}
