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 2f314dc7b..6475c5cb0 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 @@ -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(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 aa61d458e..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) } } @@ -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] 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/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 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" /> 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