package com.gh.ndownload.suspendwindow.window

import android.content.Context
import android.util.TypedValue
import android.view.Gravity
import android.view.View.OnClickListener
import android.view.WindowManager.LayoutParams
import com.gh.ndownload.suspendwindow.view.NDownloadDrawOverlayPermissionLayout

class NDownloadDrawOverlayPermissionWindow(context: Context, suspend: Boolean = true) :
    NDownloadSuspendWindow<NDownloadDrawOverlayPermissionLayout>(context, suspend) {

    fun setOnCloseClickListener(onClick: OnClickListener) {
        root.close.setOnClickListener(onClick)
    }

    fun setOnButtonClickListener(onClick: OnClickListener) {
        root.button.setOnClickListener(onClick)
    }

    override fun onCreateView(context: Context): NDownloadDrawOverlayPermissionLayout =
        NDownloadDrawOverlayPermissionLayout(context)

    override fun onLayoutParamsCreated(layoutParams: LayoutParams) {
        layoutParams.apply {
            gravity = Gravity.END or Gravity.CENTER_VERTICAL
            width = LayoutParams.WRAP_CONTENT
            height = LayoutParams.WRAP_CONTENT
            x = TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP,
                42F,
                context.resources.displayMetrics
            ).toInt()
        }
    }
}