Skip to content

Commit

Permalink
edge to edge updates
Browse files Browse the repository at this point in the history
(cherry picked from commit d9408b1)
  • Loading branch information
crackededed committed Jul 27, 2024
1 parent df2039e commit 231e069
Show file tree
Hide file tree
Showing 47 changed files with 623 additions and 492 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId = "com.github.andreyasadchy.xtra"
minSdk = 21
targetSdk = 34
versionCode = 247
versionName = "2.33.1"
versionCode = 248
versionName = "2.33.2"
}

buildTypes {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ChannelPagerFragment : BaseNetworkFragment(), Scrollable, FragmentHost {
}
}.attach()
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
collapsingToolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class FollowMediaFragment : Fragment(), Scrollable, FragmentHost {
}
}, false)
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class FollowPagerFragment : Fragment(), Scrollable, FragmentHost {
}
}.attach()
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class GameMediaFragment : BaseNetworkFragment(), Scrollable, FragmentHost {
}
}, false)
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class GamePagerFragment : BaseNetworkFragment(), Scrollable, FragmentHost {
}
}.attach()
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class GamesFragment : PagedListFragment(), Scrollable {
appBar.background = null
}
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LoginActivity : AppCompatActivity() {
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = insets.top
leftMargin = insets.left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -176,6 +175,14 @@ class MainActivity : AppCompatActivity(), SlidingLayout.Listener {
putBoolean(C.FIRST_LAUNCH7, false)
}
}
if (prefs.getBoolean(C.FIRST_LAUNCH8, true)) {
prefs.edit {
if (prefs.getString(C.UI_CUTOUTMODE, "0") == "1") {
putBoolean(C.UI_DRAW_BEHIND_CUTOUTS, true)
}
putBoolean(C.FIRST_LAUNCH8, false)
}
}
viewModel.integrity.observe(this) {
if (prefs.getBoolean(C.ENABLE_INTEGRITY, false) && prefs.getBoolean(C.USE_WEBVIEW_INTEGRITY, true)) {
IntegrityDialog.show(supportFragmentManager)
Expand All @@ -185,8 +192,13 @@ class MainActivity : AppCompatActivity(), SlidingLayout.Listener {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setNavBarColor(isInPortraitOrientation)
val ignoreCutouts = prefs.getBoolean(C.UI_DRAW_BEHIND_CUTOUTS, false)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val insets = if (ignoreCutouts) {
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
} else {
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime() or WindowInsetsCompat.Type.displayCutout())
}
binding.navHostFragment.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = insets.left
rightMargin = insets.right
Expand Down Expand Up @@ -234,31 +246,29 @@ class MainActivity : AppCompatActivity(), SlidingLayout.Listener {
}

private fun setNavBarColor(isPortrait: Boolean) {
if (prefs().getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> window.isNavigationBarContrastEnforced = !isPortrait
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
window.navigationBarColor = if (isPortrait) {
Color.TRANSPARENT
} else {
ContextCompat.getColor(this, if (!isLightTheme) R.color.darkScrim else R.color.lightScrim)
}
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> window.isNavigationBarContrastEnforced = !isPortrait
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
window.navigationBarColor = if (isPortrait) {
Color.TRANSPARENT
} else {
ContextCompat.getColor(this, if (!isLightTheme) R.color.darkScrim else R.color.lightScrim)
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
if (!isLightTheme) {
window.navigationBarColor = if (isPortrait) Color.TRANSPARENT else ContextCompat.getColor(this, R.color.darkScrim)
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
if (!isLightTheme) {
window.navigationBarColor = if (isPortrait) Color.TRANSPARENT else ContextCompat.getColor(this, R.color.darkScrim)
}
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> {
@Suppress("DEPRECATION")
if (!isLightTheme) {
if (isPortrait) {
window.navigationBarColor = Color.TRANSPARENT
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
} else {
window.navigationBarColor = ContextCompat.getColor(this, R.color.darkScrim)
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
}
}
Build.VERSION.SDK_INT < Build.VERSION_CODES.M -> {
@Suppress("DEPRECATION")
if (!isLightTheme) {
if (isPortrait) {
window.navigationBarColor = Color.TRANSPARENT
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
} else {
window.navigationBarColor = ContextCompat.getColor(this, R.color.darkScrim)
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
}
}
}
Expand Down Expand Up @@ -500,7 +510,7 @@ class MainActivity : AppCompatActivity(), SlidingLayout.Listener {
}, null)
binding.navBar.apply {
if (!prefs.getBoolean(C.UI_THEME_BOTTOM_NAV_COLOR, true) && prefs.getBoolean(C.UI_THEME_MATERIAL3, true)) {
itemBackground = ColorDrawable(MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface))
setBackgroundColor(MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface))
}
menu.add(Menu.NONE, R.id.rootGamesFragment, Menu.NONE, R.string.games).setIcon(R.drawable.ic_games_black_24dp)
menu.add(Menu.NONE, R.id.rootTopFragment, Menu.NONE, R.string.popular).setIcon(R.drawable.ic_trending_up_black_24dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ import android.content.SharedPreferences
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageButton
import android.widget.LinearLayout
import androidx.activity.OnBackPressedCallback
import androidx.activity.trackPipAnimationHintView
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
Expand All @@ -30,6 +27,7 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
Expand Down Expand Up @@ -66,13 +64,11 @@ import com.github.andreyasadchy.xtra.util.gone
import com.github.andreyasadchy.xtra.util.hideKeyboard
import com.github.andreyasadchy.xtra.util.isInPortraitOrientation
import com.github.andreyasadchy.xtra.util.isKeyboardShown
import com.github.andreyasadchy.xtra.util.isLightTheme
import com.github.andreyasadchy.xtra.util.prefs
import com.github.andreyasadchy.xtra.util.shortToast
import com.github.andreyasadchy.xtra.util.toast
import com.github.andreyasadchy.xtra.util.visible
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.color.MaterialColors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -104,7 +100,6 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
protected lateinit var prefs: SharedPreferences

private var chatWidthLandscape = 0
private var isLightTheme = false

private val backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
Expand All @@ -119,7 +114,6 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
isPortrait = activity.isInPortraitOrientation
activity.onBackPressedDispatcher.addCallback(this, backPressedCallback)
WindowCompat.getInsetsController(requireActivity().window, requireActivity().window.decorView).systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
isLightTheme = requireContext().isLightTheme
}

override fun onStart() {
Expand Down Expand Up @@ -217,14 +211,27 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
slidingLayout = view as SlidingLayout
slidingLayout = view.findViewById(R.id.slidingLayout)
slidingLayout.updateBackgroundColor(isPortrait)
chatLayout = if (this is ClipPlayerFragment) view.findViewById(R.id.clipChatContainer) else view.findViewById(R.id.chatFragmentContainer)
val ignoreCutouts = prefs.getBoolean(C.UI_DRAW_BEHIND_CUTOUTS, false)
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
slidingLayout.apply {
updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = if (isPortrait) insets.top else 0
val insets = if (!isPortrait && ignoreCutouts) {
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime())
} else {
windowInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime() or WindowInsetsCompat.Type.displayCutout())
}
if (isPortrait) {
view.updatePadding(left = 0, top = insets.top, right = 0)
} else {
if (ignoreCutouts) {
view.updatePadding(left = 0, top = 0, right = 0)
} else {
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
view.updatePadding(left = cutoutInsets.left, top = 0, right = cutoutInsets.right)
}
}
slidingLayout.apply {
savedInsets = insets
if (!isMaximized && !isPortrait) {
init()
Expand Down Expand Up @@ -414,6 +421,7 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
isPortrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT
slidingLayout.updateBackgroundColor(isPortrait)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !requireActivity().isInPictureInPictureMode) {
chatLayout.hideKeyboard()
chatLayout.clearFocus()
Expand Down Expand Up @@ -453,15 +461,7 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
}
backPressedCallback.remove()
playerView.useController = false
if (isPortrait) {
if (prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("DEPRECATION")
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
requireActivity().window.statusBarColor = Color.TRANSPARENT
}
} else {
if (!isPortrait) {
showStatusBar()
val activity = requireActivity()
activity.lifecycleScope.launch {
Expand All @@ -480,21 +480,7 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
if (!playerView.controllerHideOnTouch) { //TODO
playerView.showController()
}
if (isPortrait) {
if (prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("DEPRECATION")
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
requireActivity().window.statusBarColor = if (!isLightTheme) {
MaterialColors.getColor(requireView(), com.google.android.material.R.attr.colorSurface)
} else {
ContextCompat.getColor(requireContext(), R.color.darkScrimOnLightSurface)
}
} else {
requireActivity().window.statusBarColor = MaterialColors.getColor(requireView(), com.google.android.material.R.attr.colorSurface)
}
}
} else {
if (!isPortrait) {
hideStatusBar()
}
}
Expand Down Expand Up @@ -640,19 +626,6 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
it.gone()
}
}
if (slidingLayout.isMaximized && prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("DEPRECATION")
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
requireActivity().window.statusBarColor = if (!isLightTheme) {
MaterialColors.getColor(requireView(), com.google.android.material.R.attr.colorSurface)
} else {
ContextCompat.getColor(requireContext(), R.color.darkScrimOnLightSurface)
}
} else {
requireActivity().window.statusBarColor = MaterialColors.getColor(requireView(), com.google.android.material.R.attr.colorSurface)
}
}
showStatusBar()
aspectRatioFrameLayout.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
Expand Down Expand Up @@ -693,13 +666,6 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
it.visible()
}
}
if (slidingLayout.isMaximized && prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("DEPRECATION")
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
requireActivity().window.statusBarColor = Color.TRANSPARENT
}
slidingLayout.post {
if (slidingLayout.isMaximized) {
hideStatusBar()
Expand Down Expand Up @@ -768,16 +734,10 @@ abstract class BasePlayerFragment : BaseNetworkFragment(), LifecycleListener, Sl
}

private fun showStatusBar() {
if (!prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
WindowCompat.setDecorFitsSystemWindows(requireActivity().window, true)
}
WindowCompat.getInsetsController(requireActivity().window, requireActivity().window.decorView).show(WindowInsetsCompat.Type.systemBars())
}

private fun hideStatusBar() {
if (!prefs.getBoolean(C.UI_THEME_EDGE_TO_EDGE, true)) {
WindowCompat.setDecorFitsSystemWindows(requireActivity().window, false)
}
WindowCompat.getInsetsController(requireActivity().window, requireActivity().window.decorView).hide(WindowInsetsCompat.Type.systemBars())
}

Expand Down
Loading

0 comments on commit 231e069

Please sign in to comment.