package com.sheep.gamegroup.view.fragment;

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

import com.sheep.gamegroup.event.BigEvent;
import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.Release_task;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.gamegroup.view.adapter.WelfareAdapter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.Locale;

import io.reactivex.Observable;
import rx.functions.Action1;

/**
 * Created by realicing on 2018/9/3.
 * realicing@sina.com
 */
public class FgtDownloadWelfareList extends BaseListFragment2<Release_task> implements Action1<Integer> {
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void call(Integer integer) {
        switch (integer){
            case WelfareAdapter.TO_REFRESH:
                refreshData();
                break;
        }
    }
    @Subscribe
    public void onEventMainThread(BigEvent event) {
        CommonUtil.getInstance().setEventResultViewStatus(event, view_list);
    }
    @Override
    protected RecyclerView.Adapter getAdapter() {
        return new WelfareAdapter(activity, list, this);
    }

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

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

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