package com.sheep.gamegroup.view.dialog;

import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.kfzs.duanduan.utils.dlg.ViewFindUtils;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.gamegroup.absBase.AbsChooseImageActivity;

import me.iwf.photopicker.PhotoPicker;


public class DialogChooseImage {


    public static AlertDialog showDialog(final AbsChooseImageActivity activity) {
        View view = View.inflate(activity, R.layout.dialog_choose_image, null);
        final AlertDialog mAlertDialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
                .setView(view)
                .create();
        ViewFindUtils.find(view, R.id.dialog_camera)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                    }
                });
        ViewFindUtils.find(view, R.id.dialog_close)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();

                    }
                });
        ViewFindUtils.find(view, R.id.dialog_choose)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                        PhotoPicker.builder()
                                .setPhotoCount(1)
                                .setShowCamera(true)
                                .setShowGif(false)
                                .setPreviewEnabled(false)
                                .start(activity, PhotoPicker.REQUEST_CODE);
                    }
                });
        Window window = mAlertDialog.getWindow();
        if(window != null) {
            WindowManager.LayoutParams params = window.getAttributes();
            if(params != null){
                params.gravity = Gravity.BOTTOM;
                window.setAttributes(params);
            }
        }
        try {
            mAlertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mAlertDialog;
    }
}
