From 3d1d27b3d61ae2f7b36c5d6965414690479d2deb Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 8 Jul 2022 18:44:38 +0200 Subject: [PATCH 1/2] seekbar preview --- .../libretube/fragments/PlayerFragment.kt | 19 +++++++++++++++++++ 1 file changed, 19 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 6fb47e1fc..3656241bf 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -75,6 +75,7 @@ import com.google.android.exoplayer2.source.ProgressiveMediaSource import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.PlayerNotificationManager import com.google.android.exoplayer2.ui.StyledPlayerView +import com.google.android.exoplayer2.ui.TimeBar import com.google.android.exoplayer2.upstream.DataSource import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultHttpDataSource @@ -692,6 +693,7 @@ class PlayerFragment : Fragment() { playerBinding.exoTitle.text = response.title + enableSeekbarPreview() enableDoubleTapToSeek() // init the chapters recyclerview @@ -891,6 +893,23 @@ class PlayerFragment : Fragment() { ) } + // enable seek bar preview + private fun enableSeekbarPreview() { + playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener { + override fun onScrubStart(timeBar: TimeBar, position: Long) { + exoPlayer.pause() + } + + override fun onScrubMove(timeBar: TimeBar, position: Long) { + exoPlayer.seekTo(position) + } + + override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) { + exoPlayer.play() + } + }) + } + private fun initializeChapters(chapters: List) { if (chapters.isNotEmpty()) { binding.chaptersRecView.layoutManager = From 7dc99172f6b6e8ba26778e773c90e161dd20adc8 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 8 Jul 2022 18:50:11 +0200 Subject: [PATCH 2/2] small improvements --- .../github/libretube/activities/MainActivity.kt | 1 - .../github/libretube/fragments/HomeFragment.kt | 1 - .../github/libretube/fragments/PlayerFragment.kt | 15 +++++++++++---- .../libretube/fragments/PlaylistFragment.kt | 3 ++- .../main/java/com/github/libretube/obj/Streams.kt | 2 ++ .../com/github/libretube/util/LocaleHelper.kt | 6 ++++-- app/src/main/res/drawable/ic_discord.xml | 6 +++--- app/src/main/res/drawable/ic_matrix.xml | 6 +++--- app/src/main/res/drawable/ic_player.xml | 4 ++-- app/src/main/res/drawable/ic_reddit.xml | 6 +++--- app/src/main/res/layout/comments_row.xml | 2 +- app/src/main/res/layout/fragment_library.xml | 2 +- app/src/main/res/layout/fragment_player.xml | 2 +- app/src/main/res/layout/fragment_playlist.xml | 6 +++--- app/src/main/res/layout/replies_row.xml | 2 +- 15 files changed, 37 insertions(+), 27 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 f149862c1..d5618ef91 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -21,7 +21,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.os.bundleOf -import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.findNavController diff --git a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt index 09193e57f..832573fab 100644 --- a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt @@ -17,7 +17,6 @@ import com.github.libretube.util.LocaleHelper import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException -import java.util.* class HomeFragment : Fragment() { private val TAG = "HomeFragment" 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 3656241bf..ce1bf0581 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -865,8 +865,7 @@ class PlayerFragment : Fragment() { } override fun singleClicked() { - if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() - else exoPlayerView.showController() + toggleController() } } ) @@ -885,14 +884,19 @@ class PlayerFragment : Fragment() { } override fun singleClicked() { - if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() - else exoPlayerView.showController() + toggleController() } } ) ) } + // toggle the visibility of the player controller + private fun toggleController() { + if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController() + else exoPlayerView.showController() + } + // enable seek bar preview private fun enableSeekbarPreview() { playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener { @@ -906,6 +910,9 @@ class PlayerFragment : Fragment() { override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) { exoPlayer.play() + Handler(Looper.getMainLooper()).postDelayed({ + exoPlayerView.hideController() + }, 200) } }) } diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index 9cc6cede6..57ac348a5 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -81,7 +81,8 @@ class PlaylistFragment : Fragment() { // show playlist options binding.optionsMenu.setOnClickListener { - val optionsDialog = PlaylistOptionsDialog(playlistId!!, isOwner, requireContext()) + val optionsDialog = + PlaylistOptionsDialog(playlistId!!, isOwner, requireContext()) optionsDialog.show(childFragmentManager, "PlaylistOptionsDialog") } diff --git a/app/src/main/java/com/github/libretube/obj/Streams.kt b/app/src/main/java/com/github/libretube/obj/Streams.kt index 2ca1f50d5..34613b73e 100644 --- a/app/src/main/java/com/github/libretube/obj/Streams.kt +++ b/app/src/main/java/com/github/libretube/obj/Streams.kt @@ -1,5 +1,7 @@ package com.github.libretube.obj + import com.fasterxml.jackson.annotation.JsonIgnoreProperties + @JsonIgnoreProperties(ignoreUnknown = true) data class Streams( val title: String?, diff --git a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt index fc24e172d..8c087a1e5 100644 --- a/app/src/main/java/com/github/libretube/util/LocaleHelper.kt +++ b/app/src/main/java/com/github/libretube/util/LocaleHelper.kt @@ -57,7 +57,8 @@ object LocaleHelper { private fun detectSIMCountry(context: Context): String? { try { - val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager + val telephonyManager = + context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager return telephonyManager.simCountryIso } catch (e: Exception) { e.printStackTrace() @@ -67,7 +68,8 @@ object LocaleHelper { private fun detectNetworkCountry(context: Context): String? { try { - val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager + val telephonyManager = + context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager return telephonyManager.networkCountryIso } catch (e: Exception) { e.printStackTrace() diff --git a/app/src/main/res/drawable/ic_discord.xml b/app/src/main/res/drawable/ic_discord.xml index 1f9e2f420..4da87697f 100644 --- a/app/src/main/res/drawable/ic_discord.xml +++ b/app/src/main/res/drawable/ic_discord.xml @@ -4,7 +4,7 @@ android:tint="?android:attr/colorControlNormal" android:viewportWidth="24" android:viewportHeight="24"> - + diff --git a/app/src/main/res/drawable/ic_matrix.xml b/app/src/main/res/drawable/ic_matrix.xml index e06da1bef..f88d58ea5 100644 --- a/app/src/main/res/drawable/ic_matrix.xml +++ b/app/src/main/res/drawable/ic_matrix.xml @@ -4,7 +4,7 @@ android:tint="?android:attr/colorControlNormal" android:viewportWidth="24" android:viewportHeight="24"> - + diff --git a/app/src/main/res/drawable/ic_player.xml b/app/src/main/res/drawable/ic_player.xml index 2a9ce7870..07812f901 100644 --- a/app/src/main/res/drawable/ic_player.xml +++ b/app/src/main/res/drawable/ic_player.xml @@ -6,7 +6,7 @@ android:viewportHeight="244.86"> + android:strokeColor="#000000" /> diff --git a/app/src/main/res/drawable/ic_reddit.xml b/app/src/main/res/drawable/ic_reddit.xml index d7480cdb2..ab73945f7 100644 --- a/app/src/main/res/drawable/ic_reddit.xml +++ b/app/src/main/res/drawable/ic_reddit.xml @@ -4,7 +4,7 @@ android:tint="?android:attr/colorControlNormal" android:viewportWidth="24" android:viewportHeight="24"> - + diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml index 53523d9c1..73cdcc092 100644 --- a/app/src/main/res/layout/comments_row.xml +++ b/app/src/main/res/layout/comments_row.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?android:attr/selectableItemBackground" > + android:background="?android:attr/selectableItemBackground"> + app:show_buffering="when_playing"> + android:orientation="horizontal" + android:padding="8dp"> diff --git a/app/src/main/res/layout/replies_row.xml b/app/src/main/res/layout/replies_row.xml index 5eec53aa3..1e14c6c92 100644 --- a/app/src/main/res/layout/replies_row.xml +++ b/app/src/main/res/layout/replies_row.xml @@ -2,7 +2,7 @@ + android:layout_height="wrap_content">