package com.gallery.free.wallpaper

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment

class Dialog_SetWp : DialogFragment() {

    companion object {
        const val TYPE_HOME = 1
        const val TYPE_LOCK = 2
        const val TYPE_BOTH = 3
    }

    interface OnWallpaperTypeSelectedListener {
        fun onWallpaperTypeSelected(type: Int)
    }

    private var listener: OnWallpaperTypeSelectedListener? = null

    fun setListener(listener: OnWallpaperTypeSelectedListener) {
        this.listener = listener
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_setwp, container, false)
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        // 设置对话框样式
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
        return dialog
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.findViewById<View>(R.id.layout_home).setOnClickListener {
            listener?.onWallpaperTypeSelected(TYPE_HOME)
            dismiss()
        }

        view.findViewById<View>(R.id.layout_lock).setOnClickListener {
            listener?.onWallpaperTypeSelected(TYPE_LOCK)
            dismiss()
        }

        view.findViewById<View>(R.id.layout_both).setOnClickListener {
            listener?.onWallpaperTypeSelected(TYPE_BOTH)
            dismiss()
        }
    }
}