package com.sheep.gamegroup.view.fragment;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sheep.gamegroup.absBase.IApiRefresh;
import com.sheep.gamegroup.absBase.NetApiRefresh;
import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.DiscoveryTopic;
import com.sheep.jiuyan.samllsheep.R;

import org.afinal.simplecache.ApiKey;
import org.greenrobot.eventbus.EventBus;

import java.util.List;

import io.reactivex.Observable;

/**
 * Created by realicing on 2018/11/29.
 * realicing@sina.com
 * 小绵羊3.4.5新增 -- 为视频添加话题，话题列表
 */
public class FgtDiscoveryTopic extends BaseListFragment6<DiscoveryTopic> {

    @Override
    public int getLayoutId() {
        return R.layout.common_srl_rv;
    }

    private NetApiRefresh<DiscoveryTopic> mApiRefresh;
    @Override
    protected void addApiRefresh(List<IApiRefresh> apiRefreshList) {
        mApiRefresh = new NetApiRefresh<DiscoveryTopic>(this) {
            @Override
            protected boolean hasMore() {
                return false;
            }

            @Override
            public String getKey(int page, int per_page) {
                return ApiKey.getVideoTopic;
            }

            @Override
            public Observable<BaseMessage> getApi(ApiService apiService) {
                return apiService.getVideoTopic();
            }

            @Override
            public Class<DiscoveryTopic> getTClass() {
                return DiscoveryTopic.class;
            }
        };
        apiRefreshList.add(mApiRefresh);
    }

    @Override
    protected BaseQuickAdapter<DiscoveryTopic, BaseViewHolder> getAdapter() {
        return new BaseQuickAdapter<DiscoveryTopic, BaseViewHolder>(R.layout.item_discovery_topic, mApiRefresh.getList()) {
            @Override
            protected void convert(BaseViewHolder helper, DiscoveryTopic item) {
                helper.setText(R.id.item_discovery_topic_content, item.getTopic());
            }
        };
    }

    @Override
    public void initListener() {
        super.initListener();
        baseQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                DiscoveryTopic item = mApiRefresh.getItem(position);
                if(item != null) {
                    EventBus.getDefault().post(item);
                }
            }
        });
    }
}
