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 ed51772bd..7c76add86 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 @@ -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,11 +394,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() { @@ -542,10 +593,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) { + 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 } } diff --git a/app/src/main/res/layout-land/fragment_classic_player.xml b/app/src/main/res/layout-land/fragment_classic_player.xml new file mode 100644 index 000000000..e44519c53 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_classic_player.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file