creating landscape variant

This commit is contained in:
Tule Simon 2023-04-22 16:48:44 +01:00
parent b08d80b181
commit 77f462be9d
2 changed files with 147 additions and 1 deletions

View file

@ -17,6 +17,7 @@ package code.name.monkey.retromusic.fragments.player.classic
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color import android.graphics.Color
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.os.Bundle import android.os.Bundle
@ -26,6 +27,7 @@ import android.widget.SeekBar
import androidx.activity.OnBackPressedCallback 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.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
@ -131,6 +133,16 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
hideVolumeIfAvailable() hideVolumeIfAvailable()
setupRecyclerView() 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
}
val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment) val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment)
coverFragment.setCallbacks(this) coverFragment.setCallbacks(this)
@ -164,7 +176,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
binding.text.setOnClickListener { binding.text.setOnClickListener {
goToArtist(requireActivity()) goToArtist(requireActivity())
} }
requireActivity().onBackPressedDispatcher.addCallback(object: OnBackPressedCallback(true) { requireActivity().onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
if (getQueuePanel().state == BottomSheetBehavior.STATE_EXPANDED) { if (getQueuePanel().state == BottomSheetBehavior.STATE_EXPANDED) {
getQueuePanel().state = BottomSheetBehavior.STATE_COLLAPSED getQueuePanel().state = BottomSheetBehavior.STATE_COLLAPSED

View file

@ -0,0 +1,134 @@
<?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.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_constraintBottom_toBottomOf="parent"
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"
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"
app:layout_constraintTop_toTopf="@id/playerAlbumCoverFragment" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.card.MaterialCardView
android:id="@+id/playerQueueSheet"
style="@style/BottomSheetStyle"
android:layout_width="400dp"
android:layout_gravity="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>