package com.prank.funny.pranks.pager;

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.funny.pranks.databinding.PopupLayouttRecordBinding;
import com.prank.funny.pranks.listener.RecordListener;


public class PopImport implements View.OnClickListener {
    private PopupLayouttRecordBinding binding;
    private PopupWindow popupWindow;
    private RecordListener mListener;

    public PopImport(Activity context, RecordListener listener) {
        mListener = listener;
        binding = PopupLayouttRecordBinding.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();
        }
    }
}
