package com.lc.myapplication.security.locks.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.lc.myapplication.security.locks.R;
import com.lc.myapplication.security.locks.databinding.PermissionDialogBinding;
import com.lc.myapplication.security.locks.tool.LockPremission;
import com.lc.myapplication.security.locks.tool.MyTools;

public class PermissionDialog extends DialogFragment {
    private Context mcon;
    private boolean privacysuccess;
    private boolean showonsuccess;
    private PermissionDialogBinding permissionDialogBinding;
    public PermissionDialog(Context context){
        mcon = context;
    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        permissionDialogBinding = PermissionDialogBinding.inflate(inflater,null,false);
        initdialog();
        return permissionDialogBinding.getRoot();
    }

    private void initdialog() {
        Window window = getDialog().getWindow();
        window.setBackgroundDrawableResource(R.color.no_color);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.gravity = Gravity.BOTTOM;
        wl.height = WindowManager.LayoutParams.WRAP_CONTENT;
        wl.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(wl);
        setCancelable(true);
        permissionDialogBinding.dialogButton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 LockPremission.Privacypremit(mcon);
            }
        });
        permissionDialogBinding.dialogButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LockPremission.ShowOnpremit(mcon);
            }
        });
    }


    @Override
    public void onResume() {
        super.onResume();
        frashButton();
        initdialog();
    }

    private void frashButton() {
        privacysuccess = LockPremission.privacysuccess(mcon);
        showonsuccess = LockPremission.showonsuccess(mcon);
        permissionDialogBinding.dialogButton1.setSelected(privacysuccess);
        permissionDialogBinding.dialogButton2.setSelected(showonsuccess);
    }
}
