From 30d8de4d08fae04b0e4ad9a95121945e2a5769b6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 21 Jun 2024 16:52:12 +0200 Subject: [PATCH] style: make audio player align with status bar color --- .../libretube/ui/activities/MainActivity.kt | 21 ++- .../ui/fragments/AudioPlayerFragment.kt | 8 +- .../main/res/layout/fragment_audio_player.xml | 123 ++++++++---------- app/src/main/res/values/style.xml | 8 -- 4 files changed, 75 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index e2cf59a61..c528628f1 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -3,6 +3,7 @@ package com.github.libretube.ui.activities import android.annotation.SuppressLint import android.content.Intent import android.content.res.Configuration +import android.graphics.Color import android.os.Build import android.os.Bundle import android.view.KeyEvent @@ -13,6 +14,7 @@ import android.view.ViewTreeObserver import android.widget.ScrollView import androidx.activity.addCallback import androidx.activity.viewModels +import androidx.annotation.ColorInt import androidx.appcompat.widget.SearchView import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.os.bundleOf @@ -112,13 +114,7 @@ class MainActivity : BaseActivity() { } // sets the color if the navigation bar is visible - val bottomNavColor = if (binding.bottomNav.menu.size() == 0) { - null - } else if (PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false)) { - SurfaceColors.getColorForElevation(this, binding.bottomNav.elevation) - } else { - ThemeHelper.getThemeColor(this, com.google.android.material.R.attr.colorSurfaceContainer) - } + val bottomNavColor = getBottomNavColor() ThemeHelper.setSystemBarColors(this, window, bottomNavColor) // set default tab as start fragment @@ -200,6 +196,17 @@ class MainActivity : BaseActivity() { loadIntentData() } + @ColorInt + fun getBottomNavColor(): Int? { + return if (binding.bottomNav.menu.size() == 0) { + null + } else if (PreferenceHelper.getBoolean(PreferenceKeys.PURE_THEME, false)) { + SurfaceColors.getColorForElevation(this, binding.bottomNav.elevation) + } else { + ThemeHelper.getThemeColor(this, com.google.android.material.R.attr.colorSurfaceContainer) + } + } + /** * Deselect all bottom bar items */ diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index 6849feca4..920f83cd4 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -52,7 +52,6 @@ import com.github.libretube.ui.sheets.SleepTimerSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.util.DataSaverMode import com.github.libretube.util.PlayingQueue -import com.google.android.material.elevation.SurfaceColors import kotlinx.coroutines.launch import kotlin.math.abs @@ -108,6 +107,10 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + (activity as? MainActivity)?.getBottomNavColor()?.let { color -> + binding.audioPlayerContainer.setBackgroundColor(color) + } + initializeTransitionLayout() // select the title TV in order for it to automatically scroll @@ -238,9 +241,6 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions { val mainMotionLayout = mainActivity.binding.mainMotionLayout mainMotionLayout.progress = 0F - val surfaceColor = SurfaceColors.getColorForElevation(requireContext(), 3f) - binding.audioPlayerContainer.setBackgroundColor(surfaceColor) - binding.playerMotionLayout.addTransitionListener(object : TransitionAdapter() { override fun onTransitionChange( motionLayout: MotionLayout?, diff --git a/app/src/main/res/layout/fragment_audio_player.xml b/app/src/main/res/layout/fragment_audio_player.xml index 0909662a7..717095555 100644 --- a/app/src/main/res/layout/fragment_audio_player.xml +++ b/app/src/main/res/layout/fragment_audio_player.xml @@ -11,7 +11,7 @@ android:id="@+id/audio_player_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="?android:attr/colorBackground" + android:background="?attr/colorSurfaceContainer" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -265,85 +265,76 @@ - + android:paddingVertical="15dp" + android:paddingHorizontal="30dp"> - - - - - - - - - - - - - - - - - + android:layout_gravity="start|center_vertical" + android:orientation="horizontal"> + android:src="@drawable/ic_speed" /> - + - + + + + + + + + + + + + + diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index c73479e91..4108849a9 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -189,14 +189,6 @@ ?android:attr/textColorPrimary - -