package com.example.myapplication.ui.common

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.myapplication.R

class LoadingOverlay private constructor(
    private val parent: ViewGroup,
    private val overlay: View
) {
    companion object {
        fun attach(parent: ViewGroup): LoadingOverlay {
            val overlay = LayoutInflater.from(parent.context)
                .inflate(R.layout.view_fullscreen_loading, parent, false)

            overlay.visibility = View.GONE
            parent.addView(overlay) // 加到最上层（最后添加的在最上面）
            return LoadingOverlay(parent, overlay)
        }
    }

    fun show() {
        overlay.visibility = View.VISIBLE
    }

    fun hide() {
        overlay.visibility = View.GONE
    }

    fun remove() {
        parent.removeView(overlay)
    }
}
