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


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.widget.base.BaseRecyclerAdapter;

public class BaseListDialog<D> extends Dialog {
    private Context mContext;
    private View mView;
    private RecyclerView mRlvFunction;
    private BaseRecyclerAdapter mAdapter;

    public BaseListDialog(Context context, BaseRecyclerAdapter adapter) {
        super(context);
        this.mContext = context;
        this.mAdapter = adapter;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mView = LayoutInflater.from(mContext).inflate(R.layout.dialog_function, null);
        mRlvFunction = mView.findViewById(R.id.rlv_base_function);
        mRlvFunction.setLayoutManager(new LinearLayoutManager(mContext));
        mRlvFunction.setAdapter(mAdapter);

        setContentView(mView);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        Window dialogWindow = getWindow();
        WindowManager m = ((Activity) mContext).getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (d.getWidth() * 0.9);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialogWindow.setAttributes(p);
    }

}
