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 fragmentToOpen = "fragmentToOpen"
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.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.os.Handler
import android.os.Looper
@ -17,7 +16,6 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.enums.PlaylistType
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.PlayerFragment
import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
@ -108,10 +106,13 @@ object NavigationHelper {
/**
* Start the audio player fragment
*/
fun startAudioPlayer(context: Context) {
fun startAudioPlayer(context: Context, minimizeByDefault: Boolean = false) {
val activity = ContextHelper.unwrapActivity(context)
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()
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
menu?.findItem(R.id.action_audio)?.isVisible =
BackgroundHelper.isBackgroundServiceRunning(this)
return super.onPrepareOptionsMenu(menu)
}
private fun isSearchInProgress(): Boolean {
if (!::navController.isInitialized) return false
val id = navController.currentDestination?.id ?: return false
@ -407,10 +401,6 @@ class MainActivity : BaseActivity() {
startActivity(helpIntent)
true
}
R.id.action_audio -> {
NavigationHelper.startAudioPlayer(this)
true
}
else -> super.onOptionsItemSelected(item)
}
}
@ -481,17 +471,15 @@ class MainActivity : BaseActivity() {
(fragment as? PlayerFragment)?.binding?.apply {
mainContainer.isClickable = false
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)
}
}
supportFragmentManager.fragments.forEach { fragment ->
(fragment as? PlayerFragment)?.binding?.playerMotionLayout?.apply {
// 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?.apply {
audioPlayerContainer.isClickable = false
playerMotionLayout.transitionToEnd()
}
(fragment as? AudioPlayerFragment)?.binding?.playerMotionLayout?.transitionToEnd()
}
val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java]

View File

@ -20,6 +20,7 @@ import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import com.github.libretube.R
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentAudioPlayerBinding
import com.github.libretube.enums.ShareObjectType
import com.github.libretube.extensions.normalize
@ -220,8 +221,13 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
}
})
binding.playerMotionLayout.progress = 1.toFloat()
binding.playerMotionLayout.transitionToStart()
if (arguments?.getBoolean(IntentData.minimizeByDefault, false) != true) {
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
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.navigation.fragment.NavHostFragment
import com.github.libretube.R
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.enums.ShareObjectType
import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.obj.ShareData
@ -66,6 +69,7 @@ class VideoOptionsBottomSheet(
// Start the background mode
getString(R.string.playOnBackground) -> {
BackgroundHelper.playOnBackground(requireContext(), videoId)
NavigationHelper.startAudioPlayer(requireContext(), true)
}
// Add Video to Playlist Dialog
getString(R.string.addToPlaylist) -> {

View File

@ -81,7 +81,9 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
override fun onTouchEvent(event: MotionEvent): Boolean {
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) {
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
touchStarted = false

View File

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

View File

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