package com.sheep.gamegroup.view.fragment;

import android.support.v7.widget.RecyclerView;

import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.GameEntity;
import com.sheep.gamegroup.view.adapter.PlayGameItemAdapter;

import java.util.Locale;

import io.reactivex.Observable;

/**
 * Created by realicing on 2018/9/13.
 * realicing@sina.com
 */
public class FgtSearchApp extends BaseListFragment2<GameEntity> {

    @Override
    public int refreshDataType() {
        return -1;
    }

    @Override
    public void initView() {
        super.initView();
        view_list.setPullRefreshEnabled(false);
    }

    private String name;
    private int type = 0;
    @Override
    protected RecyclerView.Adapter getAdapter() {
        return new PlayGameItemAdapter(activity, list);
    }

    @Override
    protected String getKey(int page, int per_page) {
        return String.format(Locale.CHINA, "app/find?page=%d&per_page=%d&name=%s&type=%d", page, per_page, name, type);
    }

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

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

    public void clear() {
        list.clear();
    }
    public void toSearch(String name) {
        this.name = name;
        refreshData();
    }
}
