From b38cb661d0cc6544b89ab9b36f9962339c909791 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 9 Jul 2022 18:51:09 +0200 Subject: [PATCH] add chapters for full screen mode --- .../libretube/adapters/ChaptersAdapter.kt | 2 +- .../libretube/fragments/PlayerFragment.kt | 25 ++++++++++++++++++- .../github/libretube/obj/ChapterSegment.kt | 2 +- .../layout/exo_styled_player_control_view.xml | 15 +++++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt index 22b055a1e..6a28be080 100644 --- a/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/ChaptersAdapter.kt @@ -27,7 +27,7 @@ class ChaptersAdapter( chapterTitle.text = chapter.title root.setOnClickListener { - val chapterStart = chapter.start!!.toLong() * 1000 // s -> ms + val chapterStart = chapter.start!! * 1000 // s -> ms exoPlayer.seekTo(chapterStart) } } 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 c1b2665bc..dfc90e585 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -335,6 +335,7 @@ class PlayerFragment : Fragment() { binding.linLayout.visibility = View.GONE playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) playerBinding.exoTitle.visibility = View.VISIBLE + playerBinding.chapterName.visibility = View.VISIBLE val mainActivity = activity as MainActivity val fullscreenOrientationPref = PreferenceHelper @@ -372,6 +373,7 @@ class PlayerFragment : Fragment() { binding.linLayout.visibility = View.VISIBLE playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen) playerBinding.exoTitle.visibility = View.INVISIBLE + playerBinding.chapterName.visibility = View.INVISIBLE scaleControls(1F) @@ -938,10 +940,31 @@ class PlayerFragment : Fragment() { private fun initializeChapters(chapters: List) { if (chapters.isNotEmpty()) { + // enable chapters in the video description binding.chaptersRecView.layoutManager = - LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false) + LinearLayoutManager( + context, + LinearLayoutManager.HORIZONTAL, + false + ) binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer) binding.chaptersRecView.visibility = View.VISIBLE + + // enable chapters in the player + val titles = mutableListOf() + chapters.forEach { + titles += it.title!! + } + playerBinding.chapterName.text = chapters[0].title + playerBinding.chapterName.setOnClickListener{ + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.chapters) + .setItems(titles.toTypedArray()) { _, index -> + val position = chapters[index].start!! * 1000 + exoPlayer.seekTo(position) + } + .show() + } } } diff --git a/app/src/main/java/com/github/libretube/obj/ChapterSegment.kt b/app/src/main/java/com/github/libretube/obj/ChapterSegment.kt index 517b6d342..eb47218b3 100644 --- a/app/src/main/java/com/github/libretube/obj/ChapterSegment.kt +++ b/app/src/main/java/com/github/libretube/obj/ChapterSegment.kt @@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties data class ChapterSegment( var title: String?, var image: String?, - var start: Int? + var start: Long? ) { constructor() : this("", "", -1) } diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index d50a3cebf..c5f9540f5 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -136,6 +136,21 @@ android:id="@id/exo_duration" style="@style/ExoStyledControls.TimeText.Duration" /> + + + + + + Twitter Please connect to the internet by turning on WiFi or mobile data. Open … + Chapters \ No newline at end of file