package com.base.pdfreaderallpdfreader.widget

import android.app.Service
import android.content.Context
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.view.WindowManager
import androidx.drawerlayout.widget.DrawerLayout
import com.google.android.material.navigation.NavigationView


class FullScreenNavigationView : NavigationView {

    constructor(context: Context) : super(context) {
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView(context)
    }

    private fun initView(context: Context) {
        val vto = this.viewTreeObserver
        vto.addOnGlobalLayoutListener { setFullScreenWidth(context) }
    }

    fun setFullScreenWidth(context: Context) {

        val displayMetrics = DisplayMetrics()
        val windowManager = context.getSystemService(Service.WINDOW_SERVICE) as WindowManager
        windowManager.getDefaultDisplay().getMetrics(displayMetrics)
        val screenWidth = displayMetrics.widthPixels
        val params = this.layoutParams as DrawerLayout.LayoutParams
        params.width = screenWidth
        this.layoutParams = params
    }
}