package io.rong.imkit.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;


import com.cooleshow.usercenter.helper.UserHelper;

import java.util.HashMap;

import io.rong.imkit.R;
import io.rong.imlib.RongIMClient;

// 群公告
public class NoticyMsaPop extends PopupWindow {
    public NoticyMsaPop(Context context, final String currentMessageUid, final String noticeContext) {
        super(context);
        try {
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
            setOutsideTouchable(false);
            setFocusable(false);
            setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            View contentView = LayoutInflater.from(context).inflate(R.layout.item_announcement_view, null, false);
            TextView tvContext = contentView.findViewById(R.id.tv_notice_content);
            TextView tvIKnow = contentView.findViewById(R.id.tv_i_know);

            tvContext.setText(noticeContext);

            tvIKnow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String selectedMsgUid = currentMessageUid;
                    if (!TextUtils.isEmpty(currentMessageUid)) {
                        HashMap expansionKey = new HashMap();
                        String  localUserid= UserHelper.getUserId();
                        expansionKey.put(localUserid, "1");
                        RongIMClient.getInstance().updateMessageExpansion(expansionKey, selectedMsgUid, new RongIMClient.OperationCallback() {
                            @Override
                            public void onSuccess() {
                                dismiss();
                            }

                            @Override
                            public void onError(RongIMClient.ErrorCode errorCode) {
                                dismiss();
                            }
                        });
                    } else {
                        dismiss();
                    }
                }
            });

            setContentView(contentView);
        } catch (Exception e) {

        }

    }
}
