package com.bc_chat.im.messages.systen;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bc_chat.im.R;

import io.rong.imkit.model.ProviderTag;
import io.rong.imkit.model.UIMessage;
import io.rong.imkit.widget.provider.IContainerItemProvider;
import io.rong.imlib.model.Message;

/**
 * Created by 72752 on 2017/10/8.
 */
@ProviderTag(
        messageContent = RCNoticeMessage.class,
        centerInHorizontal = true,
        showPortrait = false,
        showSummaryWithName = false,
        hide = true
)
public class RCNoticeMessageProvider extends IContainerItemProvider.MessageProvider<RCNoticeMessage> {
    @Override
    public void bindView(View view, int i, RCNoticeMessage rCSysMessage, UIMessage uiMessage) {
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.contentView.setText(getMsgContent(rCSysMessage, uiMessage.getMessage()));
    }

    @Override
    public Spannable getContentSummary(RCNoticeMessage rCSysMessage) {
        if (rCSysMessage == null)
            return null;
        return new SpannableString(rCSysMessage.getContent());
    }

    public Spannable getContentSummary1(RCNoticeMessage data) {
        return new SpannableString(data.getContent());
    }

    @Override
    public void onItemClick(View view, int i, RCNoticeMessage RCSysMessage, UIMessage uiMessage) {
    }

    @Override
    public void onItemLongClick(View view, int position, RCNoticeMessage content, UIMessage message) {
        super.onItemLongClick(view, position, content, message);
    }

    @Override
    public View newView(Context context, ViewGroup viewGroup) {
        View view = LayoutInflater.from(context).inflate(R.layout.rc_item_information_notification_message, null);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.contentView = (TextView) view;
        view.setTag(viewHolder);
        return view;
    }

    private class ViewHolder {
        TextView contentView;
    }

    private String getMsgContent(RCNoticeMessage RCSysMessage, Message uiMessage) {
        return RCSysMessage.getContent();
    }
}
