From 5034d461aea06f1676db892c6fb50b3f17df3c2a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 17 Sep 2022 18:47:46 +0200 Subject: [PATCH 01/10] add option for manually skipping sponsorblock segments --- .../libretube/constants/PreferenceKeys.kt | 1 + .../libretube/fragments/PlayerFragment.kt | 33 +++++++++++++++---- app/src/main/res/layout/fragment_player.xml | 28 +++++++++++++++- app/src/main/res/values/strings.xml | 3 ++ .../main/res/xml/sponsorblock_settings.xml | 6 ++++ 5 files changed, 64 insertions(+), 7 deletions(-) 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 747346c5a..56eec35ea 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -75,6 +75,7 @@ object PreferenceKeys { const val SKIP_BUTTONS = "skip_buttons" const val PICTURE_IN_PICTURE = "picture_in_picture" const val PLAYER_RESIZE_MODE = "player_resize_mode" + const val SB_SKIP_MANUALLY = "sb_skip_manually" /** * Background mode diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index a60ea1b94..b5bda5e3b 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -169,6 +169,7 @@ class PlayerFragment : BaseFragment() { private var sponsorBlockNotifications = true private var skipButtonsEnabled = false private var pipEnabled = true + private var skipSegmentsManually = false /** * for autoplay @@ -336,6 +337,11 @@ class PlayerFragment : BaseFragment() { PreferenceKeys.PICTURE_IN_PICTURE, true ) + + skipSegmentsManually = PreferenceHelper.getBoolean( + PreferenceKeys.SB_SKIP_MANUALLY, + false + ) } @SuppressLint("ClickableViewAccessibility") @@ -709,21 +715,36 @@ class PlayerFragment : BaseFragment() { Handler(Looper.getMainLooper()).postDelayed(this::checkForSegments, 100) - if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) { - return - } + if (!::segmentData.isInitialized || segmentData.segments.isEmpty()) return + val currentPosition = exoPlayer.currentPosition segmentData.segments.forEach { segment: Segment -> val segmentStart = (segment.segment!![0] * 1000f).toLong() val segmentEnd = (segment.segment[1] * 1000f).toLong() - val currentPosition = exoPlayer.currentPosition + if (currentPosition in segmentStart until segmentEnd) { - if (sponsorBlockNotifications) { - Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT).show() + if (skipSegmentsManually) { + binding.sbSkipBtn.visibility = View.VISIBLE + binding.sbSkipBtn.setOnClickListener { + exoPlayer.seekTo(segmentEnd) + } } + + if (sponsorBlockNotifications) { + Toast + .makeText( + context, + R.string.segment_skipped, + Toast.LENGTH_SHORT + ).show() + } + exoPlayer.seekTo(segmentEnd) + return } } + + if (skipSegmentsManually) binding.sbSkipBtn.visibility = View.GONE } private fun playVideo() { diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index baf56d2b0..f7eb9c695 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -378,8 +378,34 @@ android:layout_gravity="center" android:gravity="center" /> - + + + + + + + + Mobile data Indicator for new videos Show a badge with the amount of new videos if there are some. + Skip segment + Skip manually + Don\'t skip segments automatically, always prompt before. diff --git a/app/src/main/res/xml/sponsorblock_settings.xml b/app/src/main/res/xml/sponsorblock_settings.xml index 5a0f6a077..8e7291d2c 100644 --- a/app/src/main/res/xml/sponsorblock_settings.xml +++ b/app/src/main/res/xml/sponsorblock_settings.xml @@ -16,6 +16,12 @@ app:key="sb_notifications_key" app:title="@string/sponsorblock_notifications" /> + + Date: Sat, 17 Sep 2022 18:49:32 +0200 Subject: [PATCH 02/10] fix key --- .../main/java/com/github/libretube/constants/PreferenceKeys.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 56eec35ea..66a335d62 100644 --- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt @@ -75,7 +75,7 @@ object PreferenceKeys { const val SKIP_BUTTONS = "skip_buttons" const val PICTURE_IN_PICTURE = "picture_in_picture" const val PLAYER_RESIZE_MODE = "player_resize_mode" - const val SB_SKIP_MANUALLY = "sb_skip_manually" + const val SB_SKIP_MANUALLY = "sb_skip_manually_key" /** * Background mode From 2deee95fb417e7c114a4d463cfbd4db1b1fa9789 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 17 Sep 2022 18:51:09 +0200 Subject: [PATCH 03/10] bug fixes --- .../main/java/com/github/libretube/fragments/PlayerFragment.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index b5bda5e3b..4f28378c3 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -722,12 +722,14 @@ class PlayerFragment : BaseFragment() { val segmentStart = (segment.segment!![0] * 1000f).toLong() val segmentEnd = (segment.segment[1] * 1000f).toLong() + // show the button to manually skip the segment if (currentPosition in segmentStart until segmentEnd) { if (skipSegmentsManually) { binding.sbSkipBtn.visibility = View.VISIBLE binding.sbSkipBtn.setOnClickListener { exoPlayer.seekTo(segmentEnd) } + return } if (sponsorBlockNotifications) { @@ -739,6 +741,7 @@ class PlayerFragment : BaseFragment() { ).show() } + // skip the segment automatically exoPlayer.seekTo(segmentEnd) return } From 7b1b54aa73f5bac841e48d9c1ec8b530c62cc654 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 17 Sep 2022 18:52:31 +0200 Subject: [PATCH 04/10] fix remaining button when playing next video --- .../main/java/com/github/libretube/fragments/PlayerFragment.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 4f28378c3..f3637c1eb 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -767,6 +767,9 @@ class PlayerFragment : BaseFragment() { } runOnUiThread { + // hide the button to skip SponsorBlock segments manually + binding.sbSkipBtn.visibility = View.GONE + // set media sources for the player setResolutionAndSubtitles() prepareExoPlayerView() From 471c828964d8d583768b81e76f6aaa2f8b461540 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 17 Sep 2022 18:55:14 +0200 Subject: [PATCH 05/10] skip btn transparency --- app/src/main/res/layout/fragment_player.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index f7eb9c695..5003638db 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -384,9 +384,9 @@ android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_marginBottom="60dp" - android:background="@android:color/black" + android:background="#88000000" android:padding="10dp" - android:visibility="gone"> + android:visibility="visible"> Date: Sat, 17 Sep 2022 19:09:11 +0200 Subject: [PATCH 06/10] UI improvements --- app/src/main/res/layout/fragment_player.xml | 44 +++++++++++++-------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 5003638db..9b4ff02b8 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -378,32 +378,42 @@ android:layout_gravity="center" android:gravity="center" /> - + android:paddingEnd="10dp" + app:strokeWidth="1dp" + app:cardBackgroundColor="#88000000" + tools:ignore="RtlSymmetry"> - + android:padding="10dp" + android:visibility="gone"> - + - + + + + + From ad9f975b5fd719b340d75195eb324cb1e1a87380 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 17 Sep 2022 15:57:24 +0530 Subject: [PATCH 07/10] Use NotificationChannelCompat. --- app/src/main/AndroidManifest.xml | 2 +- .../libretube/{MyApp.kt => LibreTubeApp.kt} | 68 +++++++------------ app/src/main/res/values/strings.xml | 8 +++ 3 files changed, 32 insertions(+), 46 deletions(-) rename app/src/main/java/com/github/libretube/{MyApp.kt => LibreTubeApp.kt} (53%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b2d5fd716..4491ea9e2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ = Build.VERSION_CODES.O) { - val channel = NotificationChannel(id, name, importance) - channel.description = descriptionText - // Register the channel in the system - val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager - notificationManager.createNotificationChannel(channel) - } + val notificationManager = NotificationManagerCompat.from(this) + notificationManager.createNotificationChannelsCompat(listOf(downloadChannel, + backgroundChannel, pushChannel)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 62009f659..10d021479 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -324,4 +324,12 @@ Skip segment Skip manually Don\'t skip segments automatically, always prompt before. + + + Download Service + Shows a notification when downloading media. + Background Mode + Shows a notification with buttons to control the audio player. + Notification Worker + Shows a notification when new streams are available. From b867df053bcd55b37f96c2305d78209cd0f32d4a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 18 Sep 2022 10:44:37 +0200 Subject: [PATCH 08/10] fix linter --- .../java/com/github/libretube/LibreTubeApp.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/LibreTubeApp.kt b/app/src/main/java/com/github/libretube/LibreTubeApp.kt index 795eb8024..281de0cec 100644 --- a/app/src/main/java/com/github/libretube/LibreTubeApp.kt +++ b/app/src/main/java/com/github/libretube/LibreTubeApp.kt @@ -68,24 +68,35 @@ class LibreTubeApp : Application() { * Initializes the required notification channels for the app. */ private fun initializeNotificationChannels() { - val downloadChannel = NotificationChannelCompat.Builder(DOWNLOAD_CHANNEL_ID, - NotificationManagerCompat.IMPORTANCE_NONE) + val downloadChannel = NotificationChannelCompat.Builder( + DOWNLOAD_CHANNEL_ID, + NotificationManagerCompat.IMPORTANCE_NONE + ) .setName(getString(R.string.download_channel_name)) .setDescription(getString(R.string.download_channel_description)) .build() - val backgroundChannel = NotificationChannelCompat.Builder(BACKGROUND_CHANNEL_ID, - NotificationManagerCompat.IMPORTANCE_LOW) + val backgroundChannel = NotificationChannelCompat.Builder( + BACKGROUND_CHANNEL_ID, + NotificationManagerCompat.IMPORTANCE_LOW + ) .setName(getString(R.string.background_channel_name)) .setDescription(getString(R.string.background_channel_description)) .build() - val pushChannel = NotificationChannelCompat.Builder(PUSH_CHANNEL_ID, - NotificationManagerCompat.IMPORTANCE_DEFAULT) + val pushChannel = NotificationChannelCompat.Builder( + PUSH_CHANNEL_ID, + NotificationManagerCompat.IMPORTANCE_DEFAULT + ) .setName(getString(R.string.push_channel_name)) .setDescription(getString(R.string.push_channel_description)) .build() val notificationManager = NotificationManagerCompat.from(this) - notificationManager.createNotificationChannelsCompat(listOf(downloadChannel, - backgroundChannel, pushChannel)) + notificationManager.createNotificationChannelsCompat( + listOf( + downloadChannel, + backgroundChannel, + pushChannel + ) + ) } } From 2490cc50b4a86c1e92c20f6112bf0035b0db6aa1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 18 Sep 2022 10:59:47 +0200 Subject: [PATCH 09/10] fix back behavior --- .../java/com/github/libretube/activities/MainActivity.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 1d09692b9..45986e5b6 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -289,6 +289,13 @@ class MainActivity : BaseActivity() { } override fun onQueryTextChange(newText: String?): Boolean { + // prevent malicious navigation when the search view is getting collapsed + if (navController.currentDestination?.id == R.id.searchResultFragment && + (newText == null || newText == "") + ) { + return false + } + if (navController.currentDestination?.id != R.id.searchFragment) { val bundle = Bundle() bundle.putString("query", newText) @@ -296,6 +303,7 @@ class MainActivity : BaseActivity() { } else { searchViewModel.setQuery(newText) } + return true } }) From 4f27dfc7b770006f1558df94e05d84b16c7bd22c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 18 Sep 2022 11:02:08 +0200 Subject: [PATCH 10/10] small fix --- .../main/java/com/github/libretube/activities/MainActivity.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 45986e5b6..58751d4d4 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -165,8 +165,6 @@ class MainActivity : BaseActivity() { // new way of handling back presses onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - navController.popBackStack(R.id.searchFragment, false) - if (binding.mainMotionLayout.progress == 0F) { try { minimizePlayer()