package com.rv.component.dialog;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ruiwenliu.wrapper.dialog.BaseDialog;
import com.ruiwenliu.wrapper.dialog.BasePopupWindow;
import com.ruiwenliu.wrapper.util.ViewHolder;
import com.rv.component.dialog.adapter.OrderPriceDetailAdapter;
import com.rv.component.dialog.bean.OrderPriceDetailBean;

/**
 * Created :Auser
 * Date: 2019/5/31.
 * Desc:订单价格明细
 */

public class OrderPriceDetailPw extends BaseDialog {

    private OrderPriceDetailAdapter detailAdapter;
    private TextView tvTitle;
    public OrderPriceDetailPw(@NonNull Activity activity) {
        super(activity);
//        setClippingEnabled(true);
//        setOutsideTouchable(true);
//        setFocusable(true);
//        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setDialogParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
    }

    @Override
    public int getViewLayout() {
        return R.layout.rv_pw_order_price_detail;
    }

    @Override
    public void helper(ViewHolder helper) {
        super.helper(helper);

        tvTitle=helper.getView(R.id.tv_title);
        RecyclerView recyclerView = helper.getView(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getDialogContext()));
        detailAdapter = new OrderPriceDetailAdapter();
        recyclerView.setAdapter(detailAdapter);
    }

    public void setNewData(OrderPriceDetailBean bean) {
        if (detailAdapter != null && bean != null) {
            tvTitle.setText(bean.getKey());
            detailAdapter.setNewData(bean.getChildren());
        }
    }




//    @Override
//    public void showAsDropDown(View parent, int xoff, int yoff, int gravity) {
//        if (Build.VERSION.SDK_INT >= 24) {
//            Rect visibleFrame = new Rect();
//            parent.getGlobalVisibleRect(visibleFrame);
//            int height = parent.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
////            int height = anchor.getResources().getDisplayMetrics().heightPixels;
//            setHeight(height);
//        }
//        super.showAsDropDown(parent, xoff, yoff, gravity);
//    }
}
