Merge pull request #1004 from Bnyro/master

maximum watch history size
This commit is contained in:
Bnyro 2022-08-09 14:52:11 +02:00 committed by GitHub
commit 0fc1cbe8cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 55 deletions

View File

@ -66,7 +66,11 @@ class MainActivity : BaseActivity() {
else ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
// start service that gets called on closure
try {
startService(Intent(this, ClosingService::class.java))
} catch (e: Exception) {
e.printStackTrace()
}
CronetHelper.initCronet(this.applicationContext)
ConnectionHelper.imageLoader = ImageLoader.Builder(this.applicationContext)

View File

@ -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
@ -161,7 +160,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 +308,6 @@ class PlayerFragment : BaseFragment() {
"50"
).toInt() * 1000
seekBarPreview = PreferenceHelper.getBoolean(
PreferenceKeys.SEEKBAR_PREVIEW,
false
)
sponsorBlockEnabled = PreferenceHelper.getBoolean(
"sb_enabled_key",
true
@ -599,12 +592,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 +908,6 @@ class PlayerFragment : BaseFragment() {
playerBinding.exoTitle.text = response.title
if (seekBarPreview) enableSeekbarPreview()
enableDoubleTapToSeek()
// init the chapters recyclerview
@ -1173,31 +1165,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

View File

@ -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()
}

View File

@ -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"
@ -84,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
*/

View File

@ -5,6 +5,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z" />
android:pathData="M6.719,19H10.24V5H6.719ZM13.76,5v14h3.521V5Z"
android:fillColor="@android:color/white"/>
</vector>

View File

@ -70,7 +70,8 @@
<TextView
android:id="@+id/speed_text"
style="@style/PlayerControlTop"
android:text="1x" />
android:text="1x"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/quality_text"
@ -80,7 +81,7 @@
<ImageButton
android:id="@+id/toggle_options"
style="@style/PlayerControlTop"
android:layout_marginTop="-.5dp"
android:layout_marginTop="-1dp"
android:src="@drawable/ic_arrow_down"
app:tint="@android:color/white" />
@ -165,7 +166,7 @@
android:layout_height="wrap_content"
android:baselineAligned="false"
android:paddingStart="10dp"
android:paddingEnd="15dp">
android:paddingEnd="20dp">
<LinearLayout
android:id="@id/exo_time"
@ -176,16 +177,20 @@
<TextView
android:id="@id/exo_position"
style="@style/TimeString" />
style="@style/TimeString"
tools:text="05:20" />
<TextView
style="@style/TimeString"
android:text=" • "
android:textColor="#B3FFFFFF"
tools:ignore="HardcodedText" />
<TextView
android:id="@id/exo_duration"
style="@style/TimeString" />
style="@style/TimeString"
android:textColor="#B3FFFFFF"
tools:text="12:15" />
</LinearLayout>
@ -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">

View File

@ -649,6 +649,7 @@
<item>1.25x</item>
<item>1.5x</item>
<item>2x</item>
<item>3x</item>
<item>4x</item>
</string-array>
<string-array name="playbackSpeedValues">
@ -659,6 +660,7 @@
<item>1.25</item>
<item>1.5</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
@ -808,4 +810,22 @@
<item>metered</item>
</string-array>
<string-array name="historySize">
<item>20</item>
<item>50</item>
<item>100</item>
<item>150</item>
<item>200</item>
<item>@string/unlimited</item>
</string-array>
<string-array name="historySizeValues">
<item>20</item>
<item>50</item>
<item>100</item>
<item>150</item>
<item>200</item>
<item>unlimited</item>
</string-array>
</resources>

View File

@ -294,4 +294,6 @@
<string name="export_subscriptions">Export Subscriptions</string>
<string name="skip_buttons">Skip buttons</string>
<string name="skip_buttons_summary">Show buttons to skip to the next or previous video.</string>
<string name="history_size">Maximum history size</string>
<string name="unlimited">Unlimited</string>
</resources>

View File

@ -141,8 +141,8 @@
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="paddingStart">4dp</item>
<item name="paddingEnd">4dp</item>
<item name="paddingStart">5dp</item>
<item name="paddingEnd">5dp</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@android:color/white</item>

View File

@ -27,6 +27,15 @@
app:key="watch_history_toggle"
app:title="@string/watch_history" />
<ListPreference
android:defaultValue="unlimited"
android:entries="@array/historySize"
android:entryValues="@array/historySizeValues"
android:icon="@drawable/ic_list"
app:key="watch_history_size"
app:title="@string/history_size"
app:useSimpleSummaryProvider="true" />
<Preference
android:icon="@drawable/ic_trash"
app:key="clear_watch_history"

View File

@ -102,13 +102,6 @@
app:key="pause_screen_off"
app:title="@string/pauseOnScreenOff" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_visibility"
android:summary="@string/seekbar_preview_summary"
android:title="@string/seekbar_preview"
app:key="seekbar_preview" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_rotating_circle"
android:summary="@string/autoRotatePlayer_summary"