CommentOperationsDialog.java 4.16 KB

package com.wd.comment.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.wd.comment.R;
import com.wd.foundation.bean.custom.content.CommentItem;

/**
 * 个人主页-我的评论列表操作弹框
 *  * @author ouyang
 *  * @version [V1.0.0, 2023/5/10]
 */
public class CommentOperationsDialog extends BottomSheetDialog implements View.OnClickListener {


    /**
     * 回复
     */
    public static final int OPERATION_TYPE_ANSWER = 1;
    /**
     * 删除
     */
    public static final int OPERATION_TYPE_DELETE = 2;
    /**
     * 复制
     */
    public static final int OPERATION_TYPE_COPY = 3;
    /**
     * 分享
     */
    public static final int OPERATION_TYPE_SHARE = 4;
    /**
     * 举报
     */
    public static final int OPERATION_TYPE_REPORT = 5;

    /**
     * 是否主态
     */
    private boolean isSelf;

    private OnButtonClickListener listener;

    private TextView tv_share, tv_answer_delete, tv_copy;

    private CommentItem currentEditObj;

    private int currentEditPosition;




    public CommentOperationsDialog(@NonNull Context context,boolean isSelf) {
        super(context, R.style.BottomSheetDialog);
        this.isSelf = isSelf;
    }

    public void setData(CommentItem currentEditFeedObj, int currentEditPosition) {
        this.currentEditObj = currentEditFeedObj;
        this.currentEditPosition = currentEditPosition;
        initView();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comment_operations_dialog);
        initOption();
        TextView tv_cancel = findViewById(R.id.tv_cancel);
        tv_answer_delete = findViewById(R.id.tv_answer_delete);
        tv_copy = findViewById(R.id.tv_copy);
        tv_share = findViewById(R.id.tv_share);
        tv_cancel.setOnClickListener(this);
        tv_answer_delete.setOnClickListener(this);
        tv_copy.setOnClickListener(this);
        tv_share.setOnClickListener(this);
        initView();
    }

    public void initView() {
        if (tv_share == null){
            return;
        }
        if (isSelf) {
            tv_answer_delete.setText("删除");
        } else {
            tv_answer_delete.setText("回复");
        }
    }

    private void initOption() {
        getDelegate().findViewById(com.google.android.material.R.id.design_bottom_sheet)
            .setBackgroundColor(ContextCompat.getColor(getContext(),android.R.color.transparent));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_cancel) {
            dismiss();
        } else if (v.getId() == R.id.tv_answer_delete) {
            if (listener != null) {
                if (isSelf) {
                    // 删除
                    listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_DELETE, currentEditObj,currentEditPosition);
                }else{
                    // 回复
                    listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_ANSWER, currentEditObj,currentEditPosition);
                }

            }
            dismiss();
        } else if (v.getId() == R.id.tv_copy) {
            // 复制
            if (listener != null) {
                listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_COPY, currentEditObj,currentEditPosition);
            }
        } else if (v.getId() == R.id.tv_share) {
            // 分享
            if (listener != null) {
                listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_SHARE, currentEditObj,currentEditPosition);
            }
        }
    }

    public interface OnButtonClickListener {
        void onDialogItemClick(int types, CommentItem currentObj, int currentPosition);
    }

    public void setListener(OnButtonClickListener listener) {
        this.listener = listener;
    }
}