From a3f103ab107c96fe23db82663b1a4f53e13a2075 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 14 Jun 2023 09:26:48 +0200 Subject: [PATCH 1/4] Fix mini player appearance from audio player --- .../libretube/helpers/NavigationHelper.kt | 2 - .../main/res/layout/fragment_audio_player.xml | 65 ++++++++++--------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt index 2f314dc7b..d4df5e2fb 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -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 diff --git a/app/src/main/res/layout/fragment_audio_player.xml b/app/src/main/res/layout/fragment_audio_player.xml index 7846bb7f5..c6acee271 100644 --- a/app/src/main/res/layout/fragment_audio_player.xml +++ b/app/src/main/res/layout/fragment_audio_player.xml @@ -1,6 +1,5 @@ - + app:layout_constraintTop_toTopOf="parent" /> + android:layout_height="wrap_content" + android:layout_gravity="center|start" + android:background="?selectableItemBackgroundBorderless" + android:src="@drawable/ic_arrow_down" /> + android:scaleX="0.8" + android:scaleY="0.8" + android:src="@drawable/ic_three_dots" /> @@ -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" /> + app:autoSizeTextType="uniform" /> + android:progressDrawable="@drawable/vertical_progressbar" /> + android:src="@drawable/ic_volume_up" /> @@ -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" /> @@ -121,7 +122,7 @@ style="@style/TextViewMarquee" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textSize="24sp"/> + android:textSize="24sp" /> + android:textSize="18sp" /> @@ -138,7 +139,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="20dp" - app:labelBehavior="gone"/> + app:labelBehavior="gone" /> + tools:text="00:00" /> + tools:text="10:15" /> @@ -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" /> + app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Full" /> + android:src="@drawable/ic_next" /> @@ -217,29 +218,29 @@ + android:src="@drawable/ic_queue" /> + android:src="@drawable/ic_speed" /> + android:src="@drawable/ic_video" /> + android:src="@drawable/ic_share" /> + android:src="@drawable/ic_close" /> @@ -263,7 +264,7 @@ android:layout_width="96dp" android:layout_height="match_parent" android:background="?attr/selectableItemBackgroundBorderless" - android:padding="8dp"/> + android:padding="8dp" /> + android:paddingVertical="15dp" /> + android:src="@drawable/ic_pause" /> + android:src="@drawable/ic_close" /> From 1c1520efde245ce956eb36f5566f93858b40d4c4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 14 Jun 2023 09:31:06 +0200 Subject: [PATCH 2/4] Prevent audio miniplayer from being minimized with gestures --- .../libretube/ui/views/SingleViewTouchableMotionLayout.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt index 31cfff8e9..98e8e526d 100644 --- a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt +++ b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt @@ -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 From be491f8a27c1f7b4b0cb5ad67d40d1a763b0af2e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 14 Jun 2023 09:37:09 +0200 Subject: [PATCH 3/4] Simplify logic to minimize mini player --- .../libretube/ui/activities/MainActivity.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index aa61d458e..1f02f6d3c 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -481,17 +481,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] From 76da6c2fc1c21ed3c3c58f1b42a129e9fd7035bd Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 14 Jun 2023 09:46:39 +0200 Subject: [PATCH 4/4] Show minimized audio player when starting backround mode --- .../java/com/github/libretube/constants/IntentData.kt | 1 + .../com/github/libretube/helpers/NavigationHelper.kt | 7 +++++-- .../com/github/libretube/ui/activities/MainActivity.kt | 10 ---------- .../libretube/ui/fragments/AudioPlayerFragment.kt | 10 ++++++++-- .../libretube/ui/sheets/VideoOptionsBottomSheet.kt | 4 ++++ app/src/main/res/menu/action_bar.xml | 6 ------ 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/libretube/constants/IntentData.kt b/app/src/main/java/com/github/libretube/constants/IntentData.kt index a257df47d..cbce36a21 100644 --- a/app/src/main/java/com/github/libretube/constants/IntentData.kt +++ b/app/src/main/java/com/github/libretube/constants/IntentData.kt @@ -15,4 +15,5 @@ object IntentData { const val openAudioPlayer = "openAudioPlayer" const val fragmentToOpen = "fragmentToOpen" const val comment = "comment" + const val minimizeByDefault = "minimizeByDefault" } diff --git a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt index d4df5e2fb..6475c5cb0 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -106,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(R.id.container) + val audioPlayerFragment = AudioPlayerFragment().apply { + arguments = bundleOf(IntentData.minimizeByDefault to minimizeByDefault) + } + replace(R.id.container, audioPlayerFragment) } } diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index 1f02f6d3c..b68735f07 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -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) } } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index f13a13ddd..197ab7ef7 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -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() + } } /** diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index 07e4e86d3..b098a3807 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -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) -> { diff --git a/app/src/main/res/menu/action_bar.xml b/app/src/main/res/menu/action_bar.xml index 5318e5424..d92659756 100644 --- a/app/src/main/res/menu/action_bar.xml +++ b/app/src/main/res/menu/action_bar.xml @@ -25,10 +25,4 @@ android:title="@string/about" app:showAsAction="never" /> - - \ No newline at end of file