mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 23:55:21 +01:00
tinting navigation bar when on landscape mode
This commit is contained in:
parent
fa40966eb3
commit
640b2ab19c
2 changed files with 107 additions and 26 deletions
|
@ -28,6 +28,7 @@ import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
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.touchguard.RecyclerViewTouchActionGuardManager
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
||||||
|
|
||||||
|
|
||||||
class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player),
|
class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player),
|
||||||
View.OnLayoutChangeListener,
|
View.OnLayoutChangeListener,
|
||||||
MusicProgressViewUpdateHelper.Callback {
|
MusicProgressViewUpdateHelper.Callback {
|
||||||
|
@ -133,14 +135,9 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
|
||||||
hideVolumeIfAvailable()
|
hideVolumeIfAvailable()
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
|
|
||||||
val config = resources.configuration;
|
|
||||||
|
|
||||||
// Check if the device is in landscape mode
|
// Check if the device is in landscape mode
|
||||||
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (isLandscapeMode()) {
|
||||||
val layoutParams =
|
resizePlayingQueue()
|
||||||
binding.playerQueueSheet.layoutParams as CoordinatorLayout.LayoutParams
|
|
||||||
layoutParams.width = (resources.displayMetrics.widthPixels * 0.53).toInt()
|
|
||||||
binding.playerQueueSheet.layoutParams = layoutParams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment)
|
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() {
|
private fun hideVolumeIfAvailable() {
|
||||||
if (PreferenceUtil.isVolumeVisibilityMode) {
|
if (PreferenceUtil.isVolumeVisibilityMode) {
|
||||||
childFragmentManager.commit {
|
childFragmentManager.commit {
|
||||||
|
@ -298,6 +304,11 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
|
||||||
binding.playerControlsContainer.songCurrentProgress.setTextColor(lastPlaybackControlsColor)
|
binding.playerControlsContainer.songCurrentProgress.setTextColor(lastPlaybackControlsColor)
|
||||||
binding.playerControlsContainer.songTotalTime.setTextColor(lastPlaybackControlsColor)
|
binding.playerControlsContainer.songTotalTime.setTextColor(lastPlaybackControlsColor)
|
||||||
|
|
||||||
|
if (isLandscapeMode()) {
|
||||||
|
val window = requireActivity().window
|
||||||
|
window?.navigationBarColor = color.backgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
ViewUtil.setProgressDrawable(
|
ViewUtil.setProgressDrawable(
|
||||||
binding.playerControlsContainer.progressSlider,
|
binding.playerControlsContainer.progressSlider,
|
||||||
color.primaryTextColor,
|
color.primaryTextColor,
|
||||||
|
@ -380,11 +391,36 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
|
||||||
binding.playerContainer.addOnLayoutChangeListener(this)
|
binding.playerContainer.addOnLayoutChangeListener(this)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val height = binding.playerContainer.height
|
|
||||||
val width = binding.playerContainer.width
|
// Check if the device is in landscape mode
|
||||||
val finalHeight = height - width
|
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()
|
val panel = getQueuePanel()
|
||||||
panel.peekHeight = finalHeight
|
if (peekHeight > 10) {
|
||||||
|
panel.peekHeight = peekHeight
|
||||||
|
} else {
|
||||||
|
panel.peekHeight = 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUpPlayerToolbar() {
|
private fun setUpPlayerToolbar() {
|
||||||
|
@ -554,10 +590,39 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
|
||||||
oldRight: Int,
|
oldRight: Int,
|
||||||
oldBottom: Int
|
oldBottom: Int
|
||||||
) {
|
) {
|
||||||
val height = binding.playerContainer.height
|
|
||||||
val width = binding.playerContainer.width
|
// Check if the device is in landscape mode
|
||||||
val finalHeight = height - (binding.playerControlsContainer.root.height + width)
|
if (isLandscapeMode()) {
|
||||||
val panel = getQueuePanel()
|
calculateLandScapePeekHeight()
|
||||||
panel.peekHeight = finalHeight
|
|
||||||
|
//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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,30 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
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
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/playerAlbumCoverFragment"
|
android:id="@+id/playerAlbumCoverFragment"
|
||||||
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
|
android:name="code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintWidth_percent="0.47"
|
app:layout_constraintDimensionRatio="w,1:1"
|
||||||
app:layout_constraintDimensionRatio="h,1:1"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/middle_guideline"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toolbarContainer"
|
app:layout_constraintTop_toBottomOf="@+id/toolbarContainer"
|
||||||
tools:layout="@layout/fragment_album_cover" />
|
tools:layout="@layout/fragment_album_cover" />
|
||||||
|
|
||||||
|
@ -54,19 +69,20 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:elevation="24dp"
|
android:elevation="24dp"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/playerAlbumCoverFragment"
|
android:layout_marginTop="10dp"
|
||||||
app:layout_constraintWidth_percent="0.41"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_margin="10dp"
|
||||||
android:layout_marginBottom="20dp"
|
app:layout_constraintStart_toStartOf="@+id/middle_guideline"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/playerAlbumCoverFragment"
|
app:layout_constraintTop_toBottomOf="@+id/toolbarContainer"
|
||||||
/>
|
/>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:id="@+id/playerQueueSheet"
|
android:id="@+id/playerQueueSheet"
|
||||||
style="@style/BottomSheetStyle"
|
style="@style/BottomSheetStyle"
|
||||||
android:layout_width="400dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
|
app:layout_anchorGravity="end"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:shapeAppearanceOverlay="@style/TopCornerCardView"
|
app:shapeAppearanceOverlay="@style/TopCornerCardView"
|
||||||
app:behavior_hideable="false"
|
app:behavior_hideable="false"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue