package com.tenlionsoft.baselib.core.widget.views;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.tenlionsoft.baselib.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * 作者: adam
 * 日期: 2021/9/30 - 2:58 下午
 * 邮箱: itgaojian@163.com
 * 描述: 新建或者搜索
 */
public class CreateOrSearchPopup extends BasePopupWindow {
    private OnItemClick mOnItemClick;

    public CreateOrSearchPopup(Context context) {
        super(context);
        View view = createPopupById(R.layout.popup_create_search_layout);
        TextView tvCreate = view.findViewById(R.id.tv_create);
        TextView tvSearch = view.findViewById(R.id.tv_search);
        setContentView(view);
        setPopupGravity(Gravity.BOTTOM | Gravity.CENTER);
        setViewClickListener(v -> {
            int id = v.getId();
            if (id == R.id.tv_search) {
                mOnItemClick.onSearch();
            } else {
                mOnItemClick.onCreate();
            }
        }, tvCreate, tvSearch);
    }


    public void addOnItemClick(OnItemClick listener) {
        this.mOnItemClick = listener;
    }

    public interface OnItemClick {
        void onSearch();

        void onCreate();
    }
}
