package ai.pai.client.views;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;

import com.android.views.popup.BasePopupWindow;

import ai.pai.client.R;

/**
 * Created by chengzhenyu on 2016/3/4.
 */
public class DeleteConfirmPopup extends BasePopupWindow implements View.OnClickListener{

    private View popupView;
    private View.OnClickListener listener;

    public DeleteConfirmPopup(Activity context, View.OnClickListener clickListener) {
        super(context);
        this.listener = clickListener;
        bindEvent();
    }

    @Override
    protected Animation getShowAnimation() {
        return getDefaultScaleAnimation();
    }

    @Override
    protected View getClickToDismissView() {
        return popupView.findViewById(R.id.click_to_dismiss);
    }

    @Override
    public View getPopupView() {
        popupView= LayoutInflater.from(mContext).inflate(R.layout.popup_delete_confirm,null);
        return popupView;
    }

    @Override
    public View getAnimaView() {
        return popupView.findViewById(R.id.popup_anima);
    }

    private void bindEvent() {
        if (popupView!=null){
            popupView.findViewById(R.id.btn_cancel_delete).setOnClickListener(this);
            popupView.findViewById(R.id.btn_delete_confirm).setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_cancel_delete:
                dismiss();
                break;
            case R.id.btn_delete_confirm:
                dismiss();
                if(listener!=null){
                    listener.onClick(v);
                }
                break;
        }
    }
}
