package com.dahe.mylibrary.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dahe.mylibrary.R;


/**
 * 头像选择 dialog
 *
 * @Description:
 * @Author: tao
 * @CreateDate: 2018/7/26 10:34
 */
public class DialogPhotoSelect extends MyBaseDialog {

    private TextView take_photo;
    private TextView select_photo;
    private TextView do_cancel;

    private onSelectClickListener onSelectClickListener;

    public void setOnSelectClickListener(onSelectClickListener onSelectClickListener) {
        this.onSelectClickListener = onSelectClickListener;
    }

    public DialogPhotoSelect(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_photo_select);

        initView();
        initListener();
    }

    private void initView() {
        take_photo = findViewById( R.id.take_photo);
        select_photo = findViewById(R.id.select_photo);
        do_cancel = findViewById(R.id.do_cancel);
    }

    private void initListener() {

        //拍照
        take_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                onSelectClickListener.onTakePhoto();
            }
        });

        //相册选择
        select_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                onSelectClickListener.onSelectPhoto();
            }
        });

        do_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });


    }

    @Override
    public void init(@NonNull Context context) {
        Window window = getWindow();
        window.setWindowAnimations(R.style.BottomAnim);
        window.setGravity( Gravity.BOTTOM);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    @Override
    public boolean isCancelAble() {
        return true;
    }

    public interface onSelectClickListener {

        void onTakePhoto();

        void onSelectPhoto();
    }
}
