package com.naz.sdkdemo.picselect;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;

import com.naz.sdkdemo.R;

/**
 * @Date: 2022/5/12 9:17 下午
 * @author: sunjichang
 * @Description:
 */
public class SPictureSelectorDialog {

    private SDialogHelper selectDialog;
    private SPictureSelector selector;

    public SPictureSelectorDialog(Activity context, int resultType) {
        selector = new SPictureSelector(context, resultType);
        View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_picture_select, null);
        rootView.findViewById(R.id.btn_camera).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != selector) {
                    selector.fromCamera();
                }
                selectDialog.dismiss();
            }
        });
        rootView.findViewById(R.id.btn_gallery).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != selector) {
                    selector.fromGallery();
                }
                selectDialog.dismiss();
            }
        });
        rootView.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectDialog.dismiss();
            }
        });
        selectDialog = SDialogHelper.newBuilder()
                .setRootView(rootView)
                .setDialogStyle(SDialogHelper.DIALOG_STYLE_BOTTOM)
                .setContext(context)
                .builder();
    }

    public void setTargetSize(int size) {
        selector.setTargetImageSize(size);
    }

    public void setResultCallback(SPictureSelector.ResultCallback callback) {
        selector.setCallback(callback);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data){
        selector.onActivityResult(requestCode, resultCode, data);
    }

    public void show() {
        selectDialog.show();
    }

    public boolean isShowing() {
        return selectDialog.isShowing();
    }

    public void dismiss() {
        selectDialog.dismiss();
    }
}
