tinting navigation bar when on landscape mode

This commit is contained in:
Tule Simon 2023-04-22 18:18:18 +01:00
parent fa40966eb3
commit 640b2ab19c
2 changed files with 107 additions and 26 deletions

View file

@ -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
}
}

View file

@ -12,15 +12,30 @@
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.Guideline
android:layout_width="1dp"
android:orientation="vertical"
android:id="@+id/middle_guideline"
app:layout_constraintGuide_percent="0.5"
android:layout_height="match_parent"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="1dp"
android:orientation="vertical"
android:id="@+id/start_guideline"
app:layout_constraintGuide_percent="0.1"
android:layout_height="match_parent"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/playerAlbumCoverFragment"
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.47"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintDimensionRatio="w,1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="@id/middle_guideline"
app:layout_constraintTop_toBottomOf="@+id/toolbarContainer"
tools:layout="@layout/fragment_album_cover" />
@ -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"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.card.MaterialCardView
android:id="@+id/playerQueueSheet"
style="@style/BottomSheetStyle"
android:layout_width="400dp"
android:layout_width="match_parent"
android:layout_gravity="end"
app:layout_anchorGravity="end"
android:layout_height="match_parent"
app:shapeAppearanceOverlay="@style/TopCornerCardView"
app:behavior_hideable="false"