From 640b2ab19cf6e00d6f40079b0a19d71417e0eb70 Mon Sep 17 00:00:00 2001 From: Tule Simon <58936865+TuleSimon@users.noreply.github.com> Date: Sat, 22 Apr 2023 18:18:18 +0100 Subject: [PATCH] tinting navigation bar when on landscape mode --- .../player/classic/ClassicPlayerFragment.kt | 97 ++++++++++++++++--- .../layout-land/fragment_classic_player.xml | 36 +++++-- 2 files changed, 107 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt index 2f18ee1bf..bc605b546 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/classic/ClassicPlayerFragment.kt @@ -28,6 +28,7 @@ import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.content.ContextCompat import androidx.fragment.app.commit import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -66,6 +67,7 @@ import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeMana import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils + class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player), View.OnLayoutChangeListener, MusicProgressViewUpdateHelper.Callback { @@ -133,14 +135,9 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player hideVolumeIfAvailable() setupRecyclerView() - val config = resources.configuration; - // Check if the device is in landscape mode - if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { - val layoutParams = - binding.playerQueueSheet.layoutParams as CoordinatorLayout.LayoutParams - layoutParams.width = (resources.displayMetrics.widthPixels * 0.53).toInt() - binding.playerQueueSheet.layoutParams = layoutParams + if (isLandscapeMode()) { + resizePlayingQueue() } val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment) @@ -185,6 +182,15 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player }) } + + private fun resizePlayingQueue() { + val layoutParams = + binding.playerQueueSheet.layoutParams as CoordinatorLayout.LayoutParams + layoutParams.width = (resources.displayMetrics.widthPixels * 0.5).toInt() + layoutParams.height = resources.displayMetrics.heightPixels + binding.playerQueueSheet.layoutParams = layoutParams + } + private fun hideVolumeIfAvailable() { if (PreferenceUtil.isVolumeVisibilityMode) { childFragmentManager.commit { @@ -298,6 +304,11 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player binding.playerControlsContainer.songCurrentProgress.setTextColor(lastPlaybackControlsColor) binding.playerControlsContainer.songTotalTime.setTextColor(lastPlaybackControlsColor) + if (isLandscapeMode()) { + val window = requireActivity().window + window?.navigationBarColor = color.backgroundColor + } + ViewUtil.setProgressDrawable( binding.playerControlsContainer.progressSlider, color.primaryTextColor, @@ -380,11 +391,36 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player binding.playerContainer.addOnLayoutChangeListener(this) return } - val height = binding.playerContainer.height - val width = binding.playerContainer.width - val finalHeight = height - width + + // Check if the device is in landscape mode + if (isLandscapeMode()) { + calculateLandScapePeekHeight() + } else { + val height = binding.playerContainer.height + val width = binding.playerContainer.width + val finalHeight = height - width + val panel = getQueuePanel() + panel.peekHeight = finalHeight + } + } + + + /** + * What am doing here is getting the controls height, and adding the toolbar and statusbar height to itm + * then i subtract it from the screen height to get a peek height + */ + private fun calculateLandScapePeekHeight() { + val height = binding.playerControlsContainer.root.height + val appbarHeight = binding.playerToolbar.height + val statusBarHeight = binding.statusBar.height + val screenHeight = resources.displayMetrics.heightPixels + val peekHeight = screenHeight - (height + appbarHeight + statusBarHeight) val panel = getQueuePanel() - panel.peekHeight = finalHeight + if (peekHeight > 10) { + panel.peekHeight = peekHeight + } else { + panel.peekHeight = 10 + } } private fun setUpPlayerToolbar() { @@ -554,10 +590,39 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player oldRight: Int, oldBottom: Int ) { - val height = binding.playerContainer.height - val width = binding.playerContainer.width - val finalHeight = height - (binding.playerControlsContainer.root.height + width) - val panel = getQueuePanel() - panel.peekHeight = finalHeight + + // Check if the device is in landscape mode + if (isLandscapeMode()) { + calculateLandScapePeekHeight() + + //get background color from viewModel + val backgroundColor = libraryViewModel.paletteColor.value + + //check if color is already applied, if not applied then update navigationBarColor + backgroundColor?.let { color -> + if (isLandscapeMode()) { + val window = requireActivity().window + window?.navigationBarColor.let { navBarColor -> + if (navBarColor == null || navBarColor != color) { + window?.navigationBarColor = color + } + } + } + } + } else { + + val height = binding.playerContainer.height + val width = binding.playerContainer.width + val finalHeight = height - (binding.playerControlsContainer.root.height + width) + val panel = getQueuePanel() + panel.peekHeight = finalHeight + } + } + + private fun isLandscapeMode(): Boolean { + val config = resources.configuration; + + // Check if the device is in landscape mode + return config.orientation == Configuration.ORIENTATION_LANDSCAPE } } diff --git a/app/src/main/res/layout-land/fragment_classic_player.xml b/app/src/main/res/layout-land/fragment_classic_player.xml index 766106d36..9d239f030 100644 --- a/app/src/main/res/layout-land/fragment_classic_player.xml +++ b/app/src/main/res/layout-land/fragment_classic_player.xml @@ -12,15 +12,30 @@ android:layout_height="match_parent" android:orientation="vertical"> + + + + + @@ -54,19 +69,20 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:elevation="24dp" - app:layout_constraintEnd_toEndOf="@+id/playerAlbumCoverFragment" - app:layout_constraintWidth_percent="0.41" - app:layout_constraintStart_toStartOf="parent" - android:layout_marginBottom="20dp" - app:layout_constraintBottom_toBottomOf="@id/playerAlbumCoverFragment" - /> + android:layout_marginTop="10dp" + app:layout_constraintEnd_toEndOf="parent" + android:layout_margin="10dp" + app:layout_constraintStart_toStartOf="@+id/middle_guideline" + app:layout_constraintTop_toBottomOf="@+id/toolbarContainer" + />