package com.sheep.gamegroup.view.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.UserCommentWithReply;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.gamegroup.util.ApiUtil;
import com.sheep.gamegroup.util.TextViewUtil;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.jiuyan.samllsheep.utils.G;

import java.util.List;

/**
 * Created by realicing on 2018/11/1.
 * realicing@sina.com
 * 用户主页回复列表adapter
 */
public class AdpUserAppHomeReply extends BaseQuickAdapter<UserCommentWithReply, BaseViewHolder> {
    public AdpUserAppHomeReply(List<UserCommentWithReply> list) {
        super(R.layout.item_user_app_home_reply, list);
    }

    @Override
    protected void convert(BaseViewHolder helper, final UserCommentWithReply item) {
        int position = helper.getAdapterPosition() - getHeaderLayoutCount();
        View user_reply_detail_line_top = helper.itemView.findViewById(R.id.user_reply_detail_line_top);
        final TextView user_reply_detail_num1 = helper.itemView.findViewById(R.id.user_reply_detail_num1);
        View intro_1 = helper.itemView.findViewById(R.id.intro_1);
        View intro_2 = helper.itemView.findViewById(R.id.intro_2);
        ViewUtil.setVisibility(user_reply_detail_line_top, position != 0);
        TextViewUtil.initIntroView(intro_1, item.getReplyShowAll().setMaxLine(5));
        TextViewUtil.initIntroView(intro_2, item.getContentShowAll().setMaxLine(4));
        ViewUtil.setText(user_reply_detail_num1, item.getLike());
        user_reply_detail_num1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                user_reply_detail_num1.setEnabled(false);
                ApiUtil.postGameUserUserGameCommentLike(item.getUser_comment_id(), new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        item.setLike(item.getLike() + 1);
                        ViewUtil.setText(user_reply_detail_num1, item.getLike());
                        user_reply_detail_num1.setEnabled(true);
                        G.showToast("操作成功");
                    }

                    @Override
                    public void onError(BaseMessage baseMessage) {
                        user_reply_detail_num1.setEnabled(true);
                        G.showToast("操作失败");
                    }
                });
            }
        });
    }
}
