Skip to content

Commit

Permalink
Insets fuckery again (#5)
Browse files Browse the repository at this point in the history
* remove edge to edge colors

* insets fuckery
  • Loading branch information
brahmkshatriya authored Feb 23, 2024
1 parent 3e48426 commit 66dda65
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/dev/brahmkshatriya/echo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,27 +58,30 @@ fun applyInsetsToPlayerUI(
) { view, insets ->
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())

view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
view.updateLayoutParams<MarginLayoutParams> {
topMargin = systemInsets.top
bottomMargin = systemInsets.bottom
leftMargin = systemInsets.left
}

playerBinding.collapsedContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
playerBinding.collapsedContainer.updateLayoutParams<MarginLayoutParams> {
leftMargin = systemInsets.left
rightMargin = systemInsets.right
}

playerBinding.collapsePlayer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
playerBinding.collapsePlayer.updateLayoutParams<MarginLayoutParams> {
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,
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/layout-land/bottom_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -151,10 +150,10 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:gravity="center"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingStart="12dp"
android:paddingEnd="12dp">

<com.google.android.material.button.MaterialButton
android:id="@+id/trackRepeat"
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/colorSurfaceContainerLowest"
app:itemActiveIndicatorStyle="@style/BottomNavbarActiveIndicator"
app:itemIconTint="@color/bottom_item_icon"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />

<FrameLayout
android:id="@+id/bottom_player_container"
android:layout_width="match_parent"
Expand All @@ -31,15 +42,4 @@

</FrameLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/colorSurfaceContainerLowest"
app:itemActiveIndicatorStyle="@style/BottomNavbarActiveIndicator"
app:itemIconTint="@color/bottom_item_icon"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
6 changes: 0 additions & 6 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
<style name="BottomNavbarActiveIndicator" parent="Widget.Material3.BottomNavigationView.ActiveIndicator">
<item name="android:color">?attr/colorPrimary</item>
</style>
<style name="ApplyInsets">
<item name="paddingTopSystemWindowInsets">true</item>
<item name="paddingBottomSystemWindowInsets">true</item>
<item name="paddingLeftSystemWindowInsets">true</item>
<item name="paddingRightSystemWindowInsets">true</item>
</style>
<style name="TopAppBarHeader">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down

0 comments on commit 66dda65

Please sign in to comment.