Merge pull request #4005 from Bnyro/master

Fix various background player UI issues
This commit is contained in:
Bnyro 2023-06-14 09:48:35 +02:00 committed by GitHub
commit 82070c533a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 64 deletions

View File

@ -15,4 +15,5 @@ object IntentData {
const val openAudioPlayer = "openAudioPlayer" const val openAudioPlayer = "openAudioPlayer"
const val fragmentToOpen = "fragmentToOpen" const val fragmentToOpen = "fragmentToOpen"
const val comment = "comment" const val comment = "comment"
const val minimizeByDefault = "minimizeByDefault"
} }

View File

@ -2,7 +2,6 @@ package com.github.libretube.helpers
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.ContextWrapper
import android.content.Intent import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
@ -17,7 +16,6 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.enums.PlaylistType import com.github.libretube.enums.PlaylistType
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.activities.MainActivity
import com.github.libretube.ui.fragments.AudioPlayerFragment import com.github.libretube.ui.fragments.AudioPlayerFragment
import com.github.libretube.ui.fragments.PlayerFragment import com.github.libretube.ui.fragments.PlayerFragment
import com.github.libretube.ui.views.SingleViewTouchableMotionLayout import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
@ -108,10 +106,13 @@ object NavigationHelper {
/** /**
* Start the audio player fragment * Start the audio player fragment
*/ */
fun startAudioPlayer(context: Context) { fun startAudioPlayer(context: Context, minimizeByDefault: Boolean = false) {
val activity = ContextHelper.unwrapActivity(context) val activity = ContextHelper.unwrapActivity(context)
activity.supportFragmentManager.commitNow { activity.supportFragmentManager.commitNow {
replace<AudioPlayerFragment>(R.id.container) val audioPlayerFragment = AudioPlayerFragment().apply {
arguments = bundleOf(IntentData.minimizeByDefault to minimizeByDefault)
}
replace(R.id.container, audioPlayerFragment)
} }
} }

View File

@ -284,12 +284,6 @@ class MainActivity : BaseActivity() {
searchView.onActionViewCollapsed() searchView.onActionViewCollapsed()
} }
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
menu?.findItem(R.id.action_audio)?.isVisible =
BackgroundHelper.isBackgroundServiceRunning(this)
return super.onPrepareOptionsMenu(menu)
}
private fun isSearchInProgress(): Boolean { private fun isSearchInProgress(): Boolean {
if (!::navController.isInitialized) return false if (!::navController.isInitialized) return false
val id = navController.currentDestination?.id ?: return false val id = navController.currentDestination?.id ?: return false
@ -407,10 +401,6 @@ class MainActivity : BaseActivity() {
startActivity(helpIntent) startActivity(helpIntent)
true true
} }
R.id.action_audio -> {
NavigationHelper.startAudioPlayer(this)
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }
@ -481,17 +471,15 @@ class MainActivity : BaseActivity() {
(fragment as? PlayerFragment)?.binding?.apply { (fragment as? PlayerFragment)?.binding?.apply {
mainContainer.isClickable = false mainContainer.isClickable = false
linLayout.visibility = View.VISIBLE linLayout.visibility = View.VISIBLE
playerMotionLayout.setTransitionDuration(250)
playerMotionLayout.transitionToEnd()
playerMotionLayout.getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
playerMotionLayout.enableTransition(R.id.yt_transition, true)
} }
} (fragment as? AudioPlayerFragment)?.binding?.apply {
supportFragmentManager.fragments.forEach { fragment -> audioPlayerContainer.isClickable = false
(fragment as? PlayerFragment)?.binding?.playerMotionLayout?.apply { playerMotionLayout.transitionToEnd()
// set the animation duration
setTransitionDuration(250)
transitionToEnd()
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
enableTransition(R.id.yt_transition, true)
} }
(fragment as? AudioPlayerFragment)?.binding?.playerMotionLayout?.transitionToEnd()
} }
val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java] val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java]

View File

@ -20,6 +20,7 @@ import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit import androidx.fragment.app.commit
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.obj.StreamItem import com.github.libretube.api.obj.StreamItem
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentAudioPlayerBinding import com.github.libretube.databinding.FragmentAudioPlayerBinding
import com.github.libretube.enums.ShareObjectType import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.normalize import com.github.libretube.extensions.normalize
@ -220,8 +221,13 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
} }
}) })
binding.playerMotionLayout.progress = 1.toFloat() if (arguments?.getBoolean(IntentData.minimizeByDefault, false) != true) {
binding.playerMotionLayout.transitionToStart() binding.playerMotionLayout.progress = 1f
binding.playerMotionLayout.transitionToStart()
} else {
binding.playerMotionLayout.progress = 0f
binding.playerMotionLayout.transitionToEnd()
}
} }
/** /**

View File

@ -1,6 +1,8 @@
package com.github.libretube.ui.sheets package com.github.libretube.ui.sheets
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
@ -10,6 +12,7 @@ import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.WatchPosition import com.github.libretube.db.obj.WatchPosition
import com.github.libretube.enums.ShareObjectType import com.github.libretube.enums.ShareObjectType
import com.github.libretube.helpers.BackgroundHelper import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.helpers.PlayerHelper import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.obj.ShareData import com.github.libretube.obj.ShareData
@ -66,6 +69,7 @@ class VideoOptionsBottomSheet(
// Start the background mode // Start the background mode
getString(R.string.playOnBackground) -> { getString(R.string.playOnBackground) -> {
BackgroundHelper.playOnBackground(requireContext(), videoId) BackgroundHelper.playOnBackground(requireContext(), videoId)
NavigationHelper.startAudioPlayer(requireContext(), true)
} }
// Add Video to Playlist Dialog // Add Video to Playlist Dialog
getString(R.string.addToPlaylist) -> { getString(R.string.addToPlaylist) -> {

View File

@ -81,7 +81,9 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
override fun onTouchEvent(event: MotionEvent): Boolean { override fun onTouchEvent(event: MotionEvent): Boolean {
gestureDetector.onTouchEvent(event) gestureDetector.onTouchEvent(event)
// gestureDetector.onTouchEvent(event) // don't react when trying to minimize audio player with gestures
if (viewToDetectTouch.id == R.id.audio_player_container && progress != 1f) return true
when (event.actionMasked) { when (event.actionMasked) {
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
touchStarted = false touchStarted = false

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.github.libretube.ui.views.SingleViewTouchableMotionLayout <com.github.libretube.ui.views.SingleViewTouchableMotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/playerMotionLayout" android:id="@+id/playerMotionLayout"
@ -15,7 +14,7 @@
android:background="?android:attr/colorBackground" android:background="?android:attr/colorBackground"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent" />
<LinearLayout <LinearLayout
android:id="@+id/audio_player_main" android:id="@+id/audio_player_main"
@ -33,20 +32,22 @@
android:padding="20dp"> android:padding="20dp">
<ImageView <ImageView
android:layout_gravity="center|start"
android:id="@+id/minimize_player" android:id="@+id/minimize_player"
android:src="@drawable/ic_arrow_down"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:layout_gravity="center|start"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_arrow_down" />
<ImageView <ImageView
android:id="@+id/dropdown_menu" android:id="@+id/dropdown_menu"
android:src="@drawable/ic_three_dots" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|end" android:layout_gravity="center|end"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:layout_width="20dp" android:scaleX="0.8"
android:layout_height="20dp"/> android:scaleY="0.8"
android:src="@drawable/ic_three_dots" />
</FrameLayout> </FrameLayout>
@ -65,7 +66,7 @@
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Small" app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Small"
tools:src="@tools:sample/backgrounds/scenic"/> tools:src="@tools:sample/backgrounds/scenic" />
<LinearLayout <LinearLayout
android:id="@+id/volumeControls" android:id="@+id/volumeControls"
@ -81,7 +82,7 @@
android:id="@+id/volume_textView" android:id="@+id/volume_textView"
style="@style/SwipeControlString" style="@style/SwipeControlString"
android:layout_gravity="center" android:layout_gravity="center"
app:autoSizeTextType="uniform"/> app:autoSizeTextType="uniform" />
<ProgressBar <ProgressBar
android:id="@+id/volume_progressBar" android:id="@+id/volume_progressBar"
@ -90,7 +91,7 @@
android:layout_height="100dp" android:layout_height="100dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginVertical="4dp" android:layout_marginVertical="4dp"
android:progressDrawable="@drawable/vertical_progressbar"/> android:progressDrawable="@drawable/vertical_progressbar" />
<ImageView <ImageView
android:id="@+id/volume_imageView" android:id="@+id/volume_imageView"
@ -98,7 +99,7 @@
android:layout_height="24dp" android:layout_height="24dp"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/volume" android:contentDescription="@string/volume"
android:src="@drawable/ic_volume_up"/> android:src="@drawable/ic_volume_up" />
</LinearLayout> </LinearLayout>
@ -106,7 +107,7 @@
android:id="@+id/progress" android:id="@+id/progress"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/> android:layout_gravity="center" />
</FrameLayout> </FrameLayout>
@ -121,7 +122,7 @@
style="@style/TextViewMarquee" style="@style/TextViewMarquee"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="24sp"/> android:textSize="24sp" />
<TextView <TextView
android:id="@+id/uploader" android:id="@+id/uploader"
@ -129,7 +130,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:textSize="18sp"/> android:textSize="18sp" />
</LinearLayout> </LinearLayout>
@ -138,7 +139,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp" android:layout_marginHorizontal="20dp"
app:labelBehavior="gone"/> app:labelBehavior="gone" />
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -150,14 +151,14 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center" android:layout_gravity="start|center"
tools:text="00:00"/> tools:text="00:00" />
<TextView <TextView
android:id="@+id/duration" android:id="@+id/duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|center" android:layout_gravity="end|center"
tools:text="10:15"/> tools:text="10:15" />
</FrameLayout> </FrameLayout>
@ -175,7 +176,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginHorizontal="20dp" android:layout_marginHorizontal="20dp"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_prev"/> android:src="@drawable/ic_prev" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/play_pause" android:id="@+id/play_pause"
@ -187,7 +188,7 @@
android:insetBottom="0dp" android:insetBottom="0dp"
app:icon="@drawable/ic_pause" app:icon="@drawable/ic_pause"
app:iconSize="24dp" app:iconSize="24dp"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Full"/> app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Full" />
<ImageView <ImageView
android:id="@+id/next" android:id="@+id/next"
@ -196,7 +197,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginHorizontal="20dp" android:layout_marginHorizontal="20dp"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_next"/> android:src="@drawable/ic_next" />
</LinearLayout> </LinearLayout>
@ -217,29 +218,29 @@
<ImageView <ImageView
android:id="@+id/open_queue" android:id="@+id/open_queue"
style="@style/AudioPlayerButton" style="@style/AudioPlayerButton"
android:src="@drawable/ic_queue"/> android:src="@drawable/ic_queue" />
<ImageView <ImageView
android:id="@+id/playback_options" android:id="@+id/playback_options"
style="@style/AudioPlayerButton" style="@style/AudioPlayerButton"
android:layout_width="27dp" android:layout_width="27dp"
android:layout_height="27dp" android:layout_height="27dp"
android:src="@drawable/ic_speed"/> android:src="@drawable/ic_speed" />
<ImageView <ImageView
android:id="@+id/open_video" android:id="@+id/open_video"
style="@style/AudioPlayerButton" style="@style/AudioPlayerButton"
android:src="@drawable/ic_video"/> android:src="@drawable/ic_video" />
<ImageView <ImageView
android:id="@+id/share" android:id="@+id/share"
style="@style/AudioPlayerButton" style="@style/AudioPlayerButton"
android:src="@drawable/ic_share"/> android:src="@drawable/ic_share" />
<ImageView <ImageView
android:id="@+id/close" android:id="@+id/close"
style="@style/AudioPlayerButton" style="@style/AudioPlayerButton"
android:src="@drawable/ic_close"/> android:src="@drawable/ic_close" />
</LinearLayout> </LinearLayout>
@ -263,7 +264,7 @@
android:layout_width="96dp" android:layout_width="96dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="8dp"/> android:padding="8dp" />
<TextView <TextView
android:id="@+id/miniPlayerTitle" android:id="@+id/miniPlayerTitle"
@ -274,7 +275,7 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:paddingHorizontal="8dp" android:paddingHorizontal="8dp"
android:paddingVertical="15dp"/> android:paddingVertical="15dp" />
<ImageView <ImageView
android:id="@+id/miniPlayerPause" android:id="@+id/miniPlayerPause"
@ -283,7 +284,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/ic_pause"/> android:src="@drawable/ic_pause" />
<ImageView <ImageView
android:id="@+id/miniPlayerClose" android:id="@+id/miniPlayerClose"
@ -292,7 +293,7 @@
android:layout_gravity="center" android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/ic_close"/> android:src="@drawable/ic_close" />
</LinearLayout> </LinearLayout>

View File

@ -25,10 +25,4 @@
android:title="@string/about" android:title="@string/about"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:visible="false"
android:id="@+id/action_audio"
android:title="@string/audio_player"
app:showAsAction="never" />
</menu> </menu>