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.UserCommentWithReply;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.gamegroup.view.adapter.AdpUserAppHomeReply;
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 FgtUserAppHomeReplyList extends BaseListFragment3<UserCommentWithReply> {

    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_reply, ViewUtil.BLOCK));
        }
    }

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

    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/reply_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.getGameUserReplyList(page, per_page, focus_user_id);
    }

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

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