Merge pull request #1500 from TuleSimon/feat/classicplayer_landscape

Feat/classicplayer landscape
This commit is contained in:
Prathamesh More 2023-04-28 22:10:49 +05:30 committed by GitHub
commit ac2454ab6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 233 additions and 10 deletions

View file

@ -17,6 +17,7 @@ package code.name.monkey.retromusic.fragments.player.classic
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
@ -26,7 +27,10 @@ import android.widget.SeekBar
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.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.util.ColorUtil
@ -64,6 +68,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 {
@ -131,6 +136,11 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
hideVolumeIfAvailable()
setupRecyclerView()
// Check if the device is in landscape mode
if (isLandscapeMode()) {
resizePlayingQueue()
}
val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment)
coverFragment.setCallbacks(this)
@ -164,15 +174,27 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
binding.text.setOnClickListener {
goToArtist(requireActivity())
}
requireActivity().onBackPressedDispatcher.addCallback(object: OnBackPressedCallback(true) {
requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (getQueuePanel().state == BottomSheetBehavior.STATE_EXPANDED) {
getQueuePanel().state = BottomSheetBehavior.STATE_COLLAPSED
}
else{
mainActivity.getBottomSheetBehavior().state=BottomSheetBehavior.STATE_COLLAPSED
}
}
})
}
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 {
@ -286,6 +308,10 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
binding.playerControlsContainer.songCurrentProgress.setTextColor(lastPlaybackControlsColor)
binding.playerControlsContainer.songTotalTime.setTextColor(lastPlaybackControlsColor)
if (isLandscapeMode()) {
mainActivity.setNavigationBarColor(color.backgroundColor)
}
ViewUtil.setProgressDrawable(
binding.playerControlsContainer.progressSlider,
color.primaryTextColor,
@ -368,12 +394,37 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
binding.playerContainer.addOnLayoutChangeListener(this)
return
}
// 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()
if (peekHeight > 10) {
panel.peekHeight = peekHeight
} else {
panel.peekHeight = 10
}
}
private fun setUpPlayerToolbar() {
binding.playerToolbar.inflateMenu(R.menu.menu_player)
@ -542,10 +593,39 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
oldRight: Int,
oldBottom: Int
) {
// 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) {
mainActivity.setNavigationBarColor(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

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/playerContainer"
android:layout_width="match_parent"
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.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_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" />
<LinearLayout
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shadow_down_strong"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<code.name.monkey.retromusic.views.StatusBarView
android:id="@+id/status_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/status_bar_padding" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/playerToolbar"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:navigationIcon="@drawable/ic_keyboard_arrow_down" />
</LinearLayout>
<include
android:id="@+id/playerControlsContainer"
layout="@layout/fragment_classic_controls"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="24dp"
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="match_parent"
android:layout_gravity="end"
app:layout_anchorGravity="end"
android:layout_height="match_parent"
app:shapeAppearanceOverlay="@style/TopCornerCardView"
app:behavior_hideable="false"
app:cardElevation="24dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
tools:peekHeight="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:clickable="true"
android:ellipsize="marquee"
android:focusable="true"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="@style/TextViewHeadline6"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
tools:text="@tools:sample/lorem[5]" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:clickable="true"
android:ellipsize="end"
android:focusable="true"
android:maxLines="1"
android:textAppearance="@style/TextViewBody1"
android:textColor="?android:attr/textColorSecondary"
tools:text="@tools:sample/full_names[0]" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/player_queue_sub_header"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/up_next"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="?android:attr/textColorSecondary" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="@integer/overScrollMode"
tools:listitem="@layout/item_list" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>