2023-01-31 21:13:39 +05:30
|
|
|
package com.github.libretube.helpers
|
2023-01-17 02:38:08 +05:30
|
|
|
|
2023-03-06 10:56:42 +05:30
|
|
|
import android.app.Activity
|
2023-01-17 02:38:08 +05:30
|
|
|
import android.os.Build
|
|
|
|
import android.view.WindowManager
|
|
|
|
import androidx.core.view.WindowCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
2023-03-30 06:53:37 +05:30
|
|
|
import com.github.libretube.ui.extensions.hideSystemBars
|
|
|
|
import com.github.libretube.ui.extensions.showSystemBars
|
2023-01-17 02:38:08 +05:30
|
|
|
|
2023-03-06 10:56:42 +05:30
|
|
|
object WindowHelper {
|
|
|
|
fun toggleFullscreen(activity: Activity, isFullscreen: Boolean) {
|
|
|
|
val window = activity.window
|
2023-01-17 02:38:08 +05:30
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
2023-03-06 10:56:42 +05:30
|
|
|
window.attributes.layoutInDisplayCutoutMode = if (isFullscreen) {
|
2023-01-17 02:38:08 +05:30
|
|
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
2023-03-06 10:56:42 +05:30
|
|
|
} else {
|
|
|
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
|
|
|
}
|
2023-01-17 02:38:08 +05:30
|
|
|
}
|
|
|
|
|
2023-03-06 10:56:42 +05:30
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, !isFullscreen)
|
2023-01-17 02:38:08 +05:30
|
|
|
|
2023-03-06 10:56:42 +05:30
|
|
|
if (isFullscreen) {
|
2023-03-31 07:01:49 +05:30
|
|
|
activity.hideSystemBars(WindowInsetsCompat.Type.systemBars())
|
2023-03-06 10:56:42 +05:30
|
|
|
} else {
|
2023-03-31 07:01:49 +05:30
|
|
|
activity.showSystemBars(WindowInsetsCompat.Type.systemBars())
|
2023-01-17 02:38:08 +05:30
|
|
|
}
|
2023-03-29 09:24:39 +05:30
|
|
|
}
|
|
|
|
}
|