package com.sheep.gamegroup.view.fragment;


import android.content.Intent;
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.MessageReplyEntity;
import com.sheep.gamegroup.util.DataUtil;
import com.sheep.gamegroup.view.activity.ActMsg;
import com.sheep.gamegroup.view.activity.MessageInteractionDetailActivity;
import com.sheep.gamegroup.view.adapter.MessageRightAdapter;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.Locale;

import io.reactivex.Observable;

/**
 * Created by realicing on 2018/9/7.
 * realicing@sina.com
 */
public class FgtMsgReply extends BaseListFragment2<MessageReplyEntity> implements MessageRightAdapter.ItemOnClickListener {
    @Override
    protected boolean isFirstGetACache() {
        return false;
    }

    @Override
    protected RecyclerView.Adapter getAdapter() {
        return new MessageRightAdapter(SheepApp.getInstance(), list, this);
    }

    @Override
    protected String getKey(int page, int per_page) {
        return String.format(Locale.CHINA, "app/message/system_message?page=%d&per_page=%d&user_id=%s", page, per_page, DataUtil.getInstance().getUserId());
    }

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

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

    @Override
    public void notifyData() {
        if(activity instanceof ActMsg) {
            ((ActMsg) activity).updateMsgOval(1, lastMessage != null && lastMessage.getTotal() > 0);
        }
    }

    @Override
    public void itemClick(int position) {
        Intent intent = new Intent(activity, MessageInteractionDetailActivity.class);
        intent.putExtra("id", position);
        startActivity(new Intent(intent));
    }
}
