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)
}
(fragment as? AudioPlayerFragment)?.binding?.apply {
audioPlayerContainer.isClickable = false
playerMotionLayout.transitionToEnd()
}
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?.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()
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"
@ -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>

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>