From 6e3965c51ea41caa6549c93b3d3c3001123f9d88 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 17 Nov 2022 17:03:51 +0100 Subject: [PATCH] Option to open queue from background notification --- .../main/java/com/github/libretube/constants/IntentData.kt | 1 + .../java/com/github/libretube/constants/PreferenceKeys.kt | 1 + .../com/github/libretube/ui/activities/MainActivity.kt | 4 ++++ .../java/com/github/libretube/ui/sheets/BaseBottomSheet.kt | 6 ------ .../com/github/libretube/ui/sheets/ExpandedBottomSheet.kt | 6 ++++++ .../com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt | 6 ------ .../com/github/libretube/util/NowPlayingNotification.kt | 7 ++++++- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/audio_video_settings.xml | 6 ++++++ 9 files changed, 25 insertions(+), 13 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 82bef9e0b..9eaef14e4 100644 --- a/app/src/main/java/com/github/libretube/constants/IntentData.kt +++ b/app/src/main/java/com/github/libretube/constants/IntentData.kt @@ -8,4 +8,5 @@ object IntentData { const val timeStamp = "timeStamp" const val position = "position" const val fileName = "fileName" + const val openQueueOnce = "openQueue" } diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt index ac20cc559..0e2409470 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -86,6 +86,7 @@ object PreferenceKeys { * Background mode */ const val BACKGROUND_PLAYBACK_SPEED = "background_playback_speed" + const val NOTIFICATION_OPEN_QUEUE = "notification_open_queue" /** * Notifications 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 99ab6cf9f..f4849930d 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 @@ -319,6 +319,10 @@ class MainActivity : BaseActivity() { "library" -> navController.navigate(R.id.libraryFragment) } + if (intent?.getBooleanExtra(IntentData.openQueueOnce, false) == true) { + PlayingQueueSheet() + .show(supportFragmentManager) + } } private fun loadVideo(videoId: String, timeStamp: Long?) { diff --git a/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt index 2c432d355..635620be1 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.databinding.BottomSheetBinding import com.github.libretube.obj.BottomSheetItem @@ -47,11 +46,6 @@ open class BaseBottomSheet : ExpandedBottomSheet() { } } - fun show(fragmentManager: FragmentManager) = show( - fragmentManager, - null - ) - override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { super.onPictureInPictureModeChanged(isInPictureInPictureMode) dialog?.dismiss() diff --git a/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt index b17603004..f203460b1 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/ExpandedBottomSheet.kt @@ -5,6 +5,7 @@ import android.content.res.Configuration import android.os.Bundle import android.view.View import android.widget.FrameLayout +import androidx.fragment.app.FragmentManager import com.google.android.material.R import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog @@ -27,4 +28,9 @@ open class ExpandedBottomSheet : BottomSheetDialogFragment() { return dialog } + + fun show(fragmentManager: FragmentManager) = show( + fragmentManager, + null + ) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt index 0e5149316..dc0d670b3 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaybackSpeedSheet.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.FragmentManager import com.github.libretube.databinding.PlaybackBottomSheetBinding import com.github.libretube.extensions.round import com.google.android.exoplayer2.PlaybackParameters @@ -55,9 +54,4 @@ class PlaybackSpeedSheet( binding.pitch.value.round(2) ) } - - fun show(fragmentManager: FragmentManager) = show( - fragmentManager, - null - ) } diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index f6bf02eea..0ad4a29ee 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -20,6 +20,7 @@ import com.github.libretube.api.obj.Streams import com.github.libretube.constants.BACKGROUND_CHANNEL_ID import com.github.libretube.constants.IntentData import com.github.libretube.constants.PLAYER_NOTIFICATION_ID +import com.github.libretube.constants.PreferenceKeys import com.github.libretube.ui.activities.MainActivity import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.Player @@ -74,7 +75,11 @@ class NowPlayingNotification( // that's the only way to launch back into the previous activity (e.g. the player view val intent = Intent(context, MainActivity::class.java).apply { if (isBackgroundPlayerNotification) { - putExtra(IntentData.videoId, videoId) + if (PreferenceHelper.getBoolean(PreferenceKeys.NOTIFICATION_OPEN_QUEUE, true)) { + putExtra(IntentData.openQueueOnce, true) + } else { + putExtra(IntentData.videoId, videoId) + } addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 216c80716..aadea24d3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -377,6 +377,7 @@ Use HLS instead of DASH (will be slower, not recommended) Auto Limit to runtime + Open queue from notification Download Service diff --git a/app/src/main/res/xml/audio_video_settings.xml b/app/src/main/res/xml/audio_video_settings.xml index ee98f808f..abf852357 100644 --- a/app/src/main/res/xml/audio_video_settings.xml +++ b/app/src/main/res/xml/audio_video_settings.xml @@ -98,6 +98,12 @@ app:valueFrom="0.2" app:valueTo="4.0" /> + + \ No newline at end of file