package com.doverfuelingsolutions.issp.utils

import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.doverfuelingsolutions.issp.utils.log.DFSLog
import kotlinx.coroutines.delay

class ActivityUtil {

    companion object {

        @Suppress("DEPRECATION")
        fun setFullscreen(activity: AppCompatActivity) {
            makeFullscreen(activity)

            activity.window.decorView.setOnSystemUiVisibilityChangeListener {
                makeFullscreen(activity)
            }
        }

        @Suppress("DEPRECATION")
        private fun makeFullscreen(activity: AppCompatActivity) {
            val systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            activity.lifecycleScope.launchWhenStarted {
                activity.window.decorView.systemUiVisibility = systemUiVisibility
                delay(1000)
                activity.window.decorView.systemUiVisibility = systemUiVisibility
            }
        }
    }
}