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 aea79de24..4a79e0ae7 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -907,7 +907,7 @@ class PlayerFragment : BaseFragment() { if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId) // search for the next videoId in the playlist lifecycleScope.launchWhenCreated { - nextStreamId = autoPlayHelper.getNextVideoId(videoId!!, streams.relatedStreams!!) + nextStreamId = autoPlayHelper.getNextVideoId(videoId!!, streams.relatedStreams) } } @@ -1294,42 +1294,44 @@ class PlayerFragment : BaseFragment() { } private fun initializeChapters() { - if (chapters.isNotEmpty()) { - // enable chapters in the video description - binding.chaptersRecView.layoutManager = - LinearLayoutManager( - context, - LinearLayoutManager.HORIZONTAL, - false - ) - binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer) - binding.chaptersRecView.visibility = View.VISIBLE + if (chapters.isEmpty()) return + // enable chapters in the video description + binding.chaptersRecView.layoutManager = + LinearLayoutManager( + context, + LinearLayoutManager.HORIZONTAL, + false + ) + binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer) + binding.chaptersRecView.visibility = View.VISIBLE - // enable the chapters dialog in the player - val titles = mutableListOf() - chapters.forEach { - titles += it.title!! - } - playerBinding.chapterLL.visibility = View.VISIBLE - playerBinding.chapterLL.setOnClickListener { - if (viewModel.isFullscreen.value!!) { - MaterialAlertDialogBuilder(requireContext()) - .setTitle(R.string.chapters) - .setItems(titles.toTypedArray()) { _, index -> - val position = chapters[index].start!! * 1000 - exoPlayer.seekTo(position) - } - .show() - } else { - toggleDescription() - } - } - setCurrentChapterName() + // enable the chapters dialog in the player + val titles = mutableListOf() + chapters.forEach { + titles += it.title!! } + playerBinding.chapterLL.visibility = View.VISIBLE + playerBinding.chapterLL.setOnClickListener { + if (viewModel.isFullscreen.value!!) { + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.chapters) + .setItems(titles.toTypedArray()) { _, index -> + val position = chapters[index].start!! * 1000 + exoPlayer.seekTo(position) + } + .show() + } else { + toggleDescription() + } + } + setCurrentChapterName() } // set the name of the video chapter in the exoPlayerView private fun setCurrentChapterName() { + // return if chapters are ampty to avoid crashes + if (chapters.isEmpty()) return + // call the function again in 100ms exoPlayerView.postDelayed(this::setCurrentChapterName, 100) diff --git a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt index d096f5f78..a60567725 100644 --- a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt +++ b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt @@ -13,9 +13,12 @@ class AutoPlayHelper( private val playlistStreamIds = mutableListOf() private var playlistNextPage: String? = null + /** + * get the id of the next video to be played + */ suspend fun getNextVideoId( currentVideoId: String, - relatedStreams: List + relatedStreams: List? ): String? { return if (Globals.playingQueue.last() != currentVideoId) { val currentVideoIndex = Globals.playingQueue.indexOf(currentVideoId) @@ -28,8 +31,15 @@ class AutoPlayHelper( ) } - private fun getNextTrendingVideoId(videoId: String, relatedStreams: List): String? { + /** + * get the id of the next related video + */ + private fun getNextTrendingVideoId( + videoId: String, + relatedStreams: List? + ): String? { // don't play a video if it got played before already + if (relatedStreams == null || relatedStreams.isEmpty()) return null var index = 0 var nextStreamId: String? = null while (nextStreamId == null || @@ -47,6 +57,9 @@ class AutoPlayHelper( return nextStreamId } + /** + * get the videoId of the next video in a playlist + */ private suspend fun getNextPlaylistVideoId(currentVideoId: String): String? { // if the playlists contain the video, then save the next video as next stream if (playlistStreamIds.contains(currentVideoId)) { @@ -76,6 +89,9 @@ class AutoPlayHelper( return null } + /** + * get the videoId of the next video in the playing queue + */ fun getNextPlayingQueueVideoId( currentVideoId: String ): String? { diff --git a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt index 890e4f8b8..c11f76d49 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt @@ -165,7 +165,7 @@ object NotificationHelper { val builder = NotificationCompat.Builder(context, PUSH_CHANNEL_ID) .setContentTitle(title) - .setSmallIcon(R.drawable.ic_bell) + .setSmallIcon(R.drawable.ic_notification) .setContentText(description) .setPriority(NotificationCompat.PRIORITY_DEFAULT) // Set the intent that will fire when the user taps the notification diff --git a/app/src/main/res/drawable/ic_bell.xml b/app/src/main/res/drawable/ic_bell.xml deleted file mode 100644 index 458ed83e0..000000000 --- a/app/src/main/res/drawable/ic_bell.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_bell_small.xml b/app/src/main/res/drawable/ic_bell_small.xml deleted file mode 100644 index 2df32bee1..000000000 --- a/app/src/main/res/drawable/ic_bell_small.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_notification.xml b/app/src/main/res/drawable/ic_notification.xml index 7ffabd030..a43737954 100644 --- a/app/src/main/res/drawable/ic_notification.xml +++ b/app/src/main/res/drawable/ic_notification.xml @@ -1,14 +1,10 @@ + android:viewportWidth="48" + android:viewportHeight="48"> + android:fillColor="#FF000000" + android:pathData="M6.2,19.65q0,-4.05 1.7,-7.675T12.75,5.8l2.05,2.25q-2.65,2.15 -4.125,5.175T9.2,19.65ZM38.85,19.65q0,-3.4 -1.4,-6.425T33.4,8.05l2.05,-2.25q3.1,2.6 4.75,6.2t1.65,7.65ZM8,38v-3h4.2L12.2,19.7q0,-4.1 2.475,-7.425T21.2,8.1L21.2,6.65q0,-1.15 0.825,-1.9T24,4q1.15,0 1.975,0.75 0.825,0.75 0.825,1.9L26.8,8.1q4.05,0.85 6.55,4.175 2.5,3.325 2.5,7.425L35.85,35L40,35v3ZM24,44q-1.6,0 -2.8,-1.175Q20,41.65 20,40h8q0,1.65 -1.175,2.825Q25.65,44 24,44Z" /> diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 14a75275a..9090cfcd8 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -78,7 +78,6 @@ style="@style/Widget.Material3.Button.ElevatedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:drawableStart="@drawable/ic_bell_small" android:drawableTint="?android:attr/textColorPrimary" android:stateListAnimator="@null" android:text="@string/subscribe" diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index a58fff9e5..36de5c3d0 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -274,8 +274,6 @@ android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_centerVertical="true" - android:drawableStart="@drawable/ic_bell" - android:drawableTint="?android:attr/textColorPrimary" android:text="@string/subscribe" android:textColor="?android:attr/textColorPrimary" android:textSize="12sp" diff --git a/app/src/main/res/menu/action_bar.xml b/app/src/main/res/menu/action_bar.xml index 9d47ac612..f80b6ffca 100644 --- a/app/src/main/res/menu/action_bar.xml +++ b/app/src/main/res/menu/action_bar.xml @@ -1,5 +1,6 @@ - + app:showAsAction="always|collapseActionView" + tools:ignore="AlwaysShowAction" />