From 66dda65ef9a90cb7820bd64f88c7b292150918e0 Mon Sep 17 00:00:00 2001 From: Shivam <69040506+brahmkshatriya@users.noreply.github.com> Date: Fri, 23 Feb 2024 23:17:39 +0530 Subject: [PATCH] Insets fuckery again (#5) * remove edge to edge colors * insets fuckery --- .../dev/brahmkshatriya/echo/MainActivity.kt | 10 ++++++++- .../echo/player/ui/ApplyInsetsToPlayerUI.kt | 13 ++++++----- .../main/res/layout-land/bottom_player.xml | 9 ++++---- app/src/main/res/layout/activity_main.xml | 22 +++++++++---------- app/src/main/res/values/styles.xml | 6 ----- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/dev/brahmkshatriya/echo/MainActivity.kt b/app/src/main/java/dev/brahmkshatriya/echo/MainActivity.kt index 34bfba03..b9e5b033 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/MainActivity.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/MainActivity.kt @@ -3,6 +3,7 @@ package dev.brahmkshatriya.echo import android.annotation.SuppressLint import android.content.ComponentName import android.content.Intent +import android.content.res.Configuration import android.graphics.Color.TRANSPARENT import android.os.Bundle import androidx.activity.SystemBarStyle @@ -58,8 +59,12 @@ class MainActivity : AppCompatActivity() { enableEdgeToEdge( SystemBarStyle.auto(TRANSPARENT, TRANSPARENT), - SystemBarStyle.dark(TRANSPARENT) + if (isNightMode()) + SystemBarStyle.dark(TRANSPARENT) + else + SystemBarStyle.light(TRANSPARENT, TRANSPARENT) ) + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets -> insets } checkPermissions(this) @@ -83,6 +88,9 @@ class MainActivity : AppCompatActivity() { applyInsetsToPlayerUI(this) } + fun isNightMode() = + resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK != Configuration.UI_MODE_NIGHT_NO + override fun onNewIntent(intent: Intent?) { intent?.hasExtra("fromNotification")?.let { emit(playerViewModel.fromNotification) { it } diff --git a/app/src/main/java/dev/brahmkshatriya/echo/player/ui/ApplyInsetsToPlayerUI.kt b/app/src/main/java/dev/brahmkshatriya/echo/player/ui/ApplyInsetsToPlayerUI.kt index e03c40f4..aa75a319 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/player/ui/ApplyInsetsToPlayerUI.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/player/ui/ApplyInsetsToPlayerUI.kt @@ -2,7 +2,7 @@ package dev.brahmkshatriya.echo.player.ui import android.content.res.Configuration import android.view.View -import android.view.ViewGroup +import android.view.ViewGroup.MarginLayoutParams import androidx.activity.viewModels import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat @@ -58,27 +58,30 @@ fun applyInsetsToPlayerUI( ) { view, insets -> val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) - view.updateLayoutParams { + view.updateLayoutParams { topMargin = systemInsets.top bottomMargin = systemInsets.bottom leftMargin = systemInsets.left } - playerBinding.collapsedContainer.updateLayoutParams { + playerBinding.collapsedContainer.updateLayoutParams { leftMargin = systemInsets.left rightMargin = systemInsets.right } - playerBinding.collapsePlayer.updateLayoutParams { + playerBinding.collapsePlayer.updateLayoutParams { topMargin = systemInsets.top } playerBinding.expandedTrackInfoContainer.updatePadding( - right = systemInsets.right, top = systemInsets.top, bottom = systemInsets.bottom ) + playerBinding.coordinatorLayout.updatePadding( + right = systemInsets.right + ) + playerBinding.bottomPlaylistContainer.updatePadding( left = 0, right = 0, diff --git a/app/src/main/res/layout-land/bottom_player.xml b/app/src/main/res/layout-land/bottom_player.xml index 16c04736..3f92f8d7 100644 --- a/app/src/main/res/layout-land/bottom_player.xml +++ b/app/src/main/res/layout-land/bottom_player.xml @@ -55,9 +55,8 @@ android:id="@+id/coordinatorLayout" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_marginEnd="12dp" + android:layout_marginEnd="24dp" android:orientation="vertical" - android:padding="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/expandedTrackCoverContainer" @@ -151,10 +150,10 @@ + android:orientation="horizontal" + android:paddingStart="12dp" + android:paddingEnd="12dp"> + + - - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 521f12d5..9daf35d4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,12 +3,6 @@ -