package com.prank.simulator.sounds.dialog;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.prank.simulator.sounds.databinding.PopupImportBinding;
import com.prank.simulator.sounds.listener.OnClickImport;

public class PopupImport implements View.OnClickListener {
    private PopupImportBinding binding;
    private PopupWindow popupWindow;
    private OnClickImport mListener;

    public PopupImport(Activity context, OnClickImport listener) {
        mListener = listener;
        binding = PopupImportBinding.inflate(context.getLayoutInflater());
        popupWindow = new PopupWindow(binding.getRoot(), ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        binding.imImport.setOnClickListener(this);
        binding.recordBtn.setOnClickListener(this);

    }

    public void showBottom(View view) {

        int[] location = new int[2];
        view.getLocationOnScreen(location);

        int x = location[0];
        int y = location[1];


        int popupHeight = popupWindow.getHeight();
        int height = view.getHeight();
        int width = view.getWidth();
        Log.d("-------------", "--------x=" + x + "---y=" + y + "----popupHeight=" + popupHeight);
//        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, x-30, y - popupHeight+height);
        popupWindow.showAsDropDown(view, -80,
                0,
                Gravity.NO_GRAVITY);
    }


    public void hide() {
        popupWindow.dismiss();

    }


    @Override
    public void onClick(View v) {

        if (v.equals(binding.imImport)) {
            mListener.onClickTimerListener(0);
            hide();
        } else if (v.equals(binding.recordBtn)) {
            mListener.onClickTimerListener(1);
            hide();
        }
    }
}
