From 2651f0e95b32a942a4856fffb3f2f42272c61ba6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 9 Aug 2022 14:18:16 +0200 Subject: [PATCH 1/3] remove seekbar preview --- .../libretube/activities/MainActivity.kt | 6 ++- .../libretube/fragments/PlayerFragment.kt | 38 ++----------------- .../libretube/preferences/PreferenceKeys.kt | 1 - app/src/main/res/xml/player_settings.xml | 7 ---- 4 files changed, 8 insertions(+), 44 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 71459065f..0fa212023 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -66,7 +66,11 @@ class MainActivity : BaseActivity() { else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT // start service that gets called on closure - startService(Intent(this, ClosingService::class.java)) + try { + startService(Intent(this, ClosingService::class.java)) + } catch (e: Exception) { + e.printStackTrace() + } CronetHelper.initCronet(this.applicationContext) ConnectionHelper.imageLoader = ImageLoader.Builder(this.applicationContext) 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 40ce6833d..9d09776d2 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -161,7 +161,6 @@ class PlayerFragment : BaseFragment() { private var videoFormatPreference = "webm" private var defRes = "" private var bufferingGoal = 50000 - private var seekBarPreview = false private var defaultSubtitleCode = "" private var sponsorBlockEnabled = true private var sponsorBlockNotifications = true @@ -310,11 +309,6 @@ class PlayerFragment : BaseFragment() { "50" ).toInt() * 1000 - seekBarPreview = PreferenceHelper.getBoolean( - PreferenceKeys.SEEKBAR_PREVIEW, - false - ) - sponsorBlockEnabled = PreferenceHelper.getBoolean( "sb_enabled_key", true @@ -599,12 +593,12 @@ class PlayerFragment : BaseFragment() { // probably a youtube shorts video if (videoSize.height > videoSize.width) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT // a video with normal aspect ratio - else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + else ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE } "auto" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR - "landscape" -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + "landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE "portrait" -> ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT - else -> ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + else -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE } mainActivity.requestedOrientation = orientation } @@ -915,7 +909,6 @@ class PlayerFragment : BaseFragment() { playerBinding.exoTitle.text = response.title - if (seekBarPreview) enableSeekbarPreview() enableDoubleTapToSeek() // init the chapters recyclerview @@ -1173,31 +1166,6 @@ class PlayerFragment : BaseFragment() { } } - // 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) { - val minTimeDiff = 10 * 1000 // 10s - // get the difference between the new and the old position - val diff = abs(exoPlayer.currentPosition - position) - // seek only when the difference is greater than 10 seconds - if (diff >= minTimeDiff) exoPlayer.seekTo(position) - } - - override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) { - exoPlayer.seekTo(position) - exoPlayer.play() - Handler(Looper.getMainLooper()).postDelayed({ - exoPlayerView.hideController() - }, 200) - } - }) - } - private fun initializeChapters() { if (chapters.isNotEmpty()) { // enable chapters in the video description diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index 1c0b8af8f..15ec07613 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -54,7 +54,6 @@ object PreferenceKeys { const val PLAYER_VIDEO_FORMAT = "player_video_format" const val DEFAULT_RESOLUTION = "default_res" const val BUFFERING_GOAL = "buffering_goal" - const val SEEKBAR_PREVIEW = "seekbar_preview" const val PLAYER_AUDIO_FORMAT = "player_audio_format" const val PLAYER_AUDIO_QUALITY = "player_audio_quality" const val DEFAULT_SUBTITLE = "default_subtitle" diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index c5cc0e11e..9e72d25dc 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -102,13 +102,6 @@ app:key="pause_screen_off" app:title="@string/pauseOnScreenOff" /> - - Date: Tue, 9 Aug 2022 14:37:40 +0200 Subject: [PATCH 2/3] minor player UI improvements --- .../github/libretube/fragments/PlayerFragment.kt | 1 - app/src/main/res/drawable/ic_pause.xml | 6 +++--- .../layout/exo_styled_player_control_view.xml | 16 +++++++++++----- app/src/main/res/values/style.xml | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) 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 9d09776d2..d29c500e4 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -82,7 +82,6 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.CaptionStyleCompat 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 diff --git a/app/src/main/res/drawable/ic_pause.xml b/app/src/main/res/drawable/ic_pause.xml index 645e31d2c..b92538943 100644 --- a/app/src/main/res/drawable/ic_pause.xml +++ b/app/src/main/res/drawable/ic_pause.xml @@ -4,7 +4,7 @@ android:tint="?attr/colorControlNormal" android:viewportWidth="24" android:viewportHeight="24"> - + 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 94e317f32..4cebb2abc 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 @@ -70,7 +70,8 @@ + android:text="1x" + tools:ignore="HardcodedText" /> @@ -165,7 +166,7 @@ android:layout_height="wrap_content" android:baselineAligned="false" android:paddingStart="10dp" - android:paddingEnd="15dp"> + android:paddingEnd="20dp"> + style="@style/TimeString" + tools:text="05:20" /> + style="@style/TimeString" + android:textColor="#B3FFFFFF" + tools:text="12:15" /> @@ -264,6 +269,7 @@ android:layout_height="15dp" android:layout_gravity="bottom" android:layout_marginLeft="10dp" + android:layout_marginTop="5dp" android:layout_marginRight="10dp" android:layout_marginBottom="10dp"> diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index d7d85f1d4..911da05bb 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -141,8 +141,8 @@ center_vertical wrap_content wrap_content - 4dp - 4dp + 5dp + 5dp 14sp bold @android:color/white From a859ae101df607764bd723b1e3f47cb63a51b38a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 9 Aug 2022 14:49:34 +0200 Subject: [PATCH 3/3] max history size --- .../libretube/preferences/PreferenceHelper.kt | 6 ++++++ .../libretube/preferences/PreferenceKeys.kt | 5 +++++ app/src/main/res/values/array.xml | 20 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/history_settings.xml | 9 +++++++++ 5 files changed, 42 insertions(+) diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt index 4403eba5a..3b7c69c27 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt @@ -142,6 +142,12 @@ object PreferenceHelper { watchHistory += watchHistoryItem + // remove oldest item when the watch history is longer than the pref + val maxWatchHistorySize = getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited") + if (maxWatchHistorySize != "unlimited" && watchHistory.size > maxWatchHistorySize.toInt()) { + watchHistory.removeAt(0) + } + val json = mapper.writeValueAsString(watchHistory) editor.putString("watch_history", json).apply() } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index 15ec07613..74f110a6d 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -83,6 +83,11 @@ object PreferenceKeys { const val CLEAR_WATCH_POSITIONS = "clear_watch_positions" const val SHARE_WITH_TIME_CODE = "share_with_time_code" + /** + * History + */ + const val WATCH_HISTORY_SIZE = "watch_history_size" + /** * Error logs */ diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index e399c1838..b5b54c098 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -649,6 +649,7 @@ 1.25x 1.5x 2x + 3x 4x @@ -659,6 +660,7 @@ 1.25 1.5 2 + 3 4 @@ -808,4 +810,22 @@ metered + + 20 + 50 + 100 + 150 + 200 + @string/unlimited + + + + 20 + 50 + 100 + 150 + 200 + unlimited + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ffccc20d..25d950e58 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -294,4 +294,6 @@ Export Subscriptions Skip buttons Show buttons to skip to the next or previous video. + Maximum history size + Unlimited diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml index ec13f6005..642b227d3 100644 --- a/app/src/main/res/xml/history_settings.xml +++ b/app/src/main/res/xml/history_settings.xml @@ -27,6 +27,15 @@ app:key="watch_history_toggle" app:title="@string/watch_history" /> + +