package com.sheep.gamegroup.view.fragment;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.widget.TextView;

import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.UserComment;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.view.adapter.AdpUserAppHomeComment;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.Locale;

import io.reactivex.Observable;

/**
 * Created by realicing on 2018/11/6.
 * realicing@sina.com
 * 用户游戏主页--子页面--评论
 */
public class FgtUserAppHomeCommentList extends BaseListFragment3<UserComment>{

    private TextView headerView;
    @Override
    public void initView() {
        super.initView();
        headerView = (TextView) LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.include_total_count_tv, null);
        if(headerView != null){
            ViewUtil.setText(headerView, getString(R.string.total_x_comment, ViewUtil.BLOCK));
        }
    }

    @Override
    protected RecyclerView.Adapter getAdapter() {
        AdpUserAppHomeComment adpUserAppHomeComment = new AdpUserAppHomeComment(list);
        adpUserAppHomeComment.addHeaderView(headerView);
        return adpUserAppHomeComment;
    }

    private int focus_user_id;

    public void setFocus_user_id(int focus_user_id) {
        this.focus_user_id = focus_user_id;
    }

    @Override
    protected String getKey(int page, int per_page) {
        return String.format(Locale.CHINA, "app/game_user/comment_list?page_no=%d&page_size=%d&focus_user_id=%d", page, per_page, focus_user_id);
    }

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

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

    @Override
    public void notifyDataSetChanged() {
        if(lastMessage != null && headerView != null){
            ViewUtil.setText(headerView, getString(R.string.total_x_comment, String.valueOf(lastMessage.getTotal())));
        }
        super.notifyDataSetChanged();
    }
}
