package com.phone.wall.paper.view;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

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

import com.phone.wall.paper.databinding.SelectWallpaperTypeBinding;
import com.phone.wall.paper.listener.OnType;

public class SelectWallpaperType extends DialogFragment {

    private SelectWallpaperTypeBinding vb;
    private OnType listener;

    public static final int type_home =0;
    public static final int type_lock =1;
    public static final int type_both =2;

    public void setListener(OnType listener) {
        this.listener = listener;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        vb = SelectWallpaperTypeBinding.inflate(getLayoutInflater());

        init();
        return vb.getRoot();
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            dialog.setCanceledOnTouchOutside(true);
            Window window = dialog.getWindow();
            if (window != null) {
                window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
            }
        }
    }

    private void init(){
        vb.layoutHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!= null){
                    listener.onSelectType(type_home);
                    dismiss();

                }

            }
        });
        vb.layoutLock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!= null){
                    listener.onSelectType(type_lock);
                    dismiss();

                }
            }
        });
        vb.layoutBoth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!= null){
                    listener.onSelectType(type_both);
                    dismiss();

                }
            }
        });
    }
}
