Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow user to set custom preloading amount #6504

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import kotlinx.coroutines.runBlocking
import java.util.Locale
import java.util.concurrent.Executors
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.roundToInt

object PlayerHelper {
Expand Down Expand Up @@ -543,7 +544,7 @@ object PlayerHelper {
.setBackBuffer(1000 * 60 * 3, true)
.setBufferDurationsMs(
MINIMUM_BUFFER_DURATION,
bufferingGoal,
max(bufferingGoal, MINIMUM_BUFFER_DURATION),
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.libretube.ui.base

import android.text.InputType
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
Expand All @@ -8,6 +10,7 @@ import androidx.preference.PreferenceFragmentCompat
import com.github.libretube.R
import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.ui.activities.SettingsActivity
import com.github.libretube.ui.preferences.EditNumberPreference
import com.google.android.material.dialog.MaterialAlertDialogBuilder

/**
Expand Down Expand Up @@ -76,11 +79,21 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
is EditTextPreference -> {
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
binding.input.setText(preference.text)

if (preference is EditNumberPreference) {
binding.input.inputType = InputType.TYPE_NUMBER_FLAG_SIGNED
}

MaterialAlertDialogBuilder(requireContext())
.setTitle(preference.title)
.setView(binding.root)
.setPositiveButton(android.R.string.ok) { _, _ ->
val newValue = binding.input.text.toString()
if (preference is EditNumberPreference && newValue.any { !it.isDigit() }) {
Toast.makeText(context, R.string.invalid_input, Toast.LENGTH_LONG).show()
return@setPositiveButton
}

if (preference.callChangeListener(newValue)) {
preference.text = newValue
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.libretube.ui.preferences

import android.content.Context
import android.util.AttributeSet
import androidx.preference.EditTextPreference
import com.github.libretube.ui.base.BasePreferenceFragment

/**
* [EditTextPreference] that only allows numeric input.
* The actual functionality is done in [BasePreferenceFragment].
*/
class EditNumberPreference(context: Context, attributeSet: AttributeSet?): EditTextPreference(context, attributeSet)
15 changes: 0 additions & 15 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,6 @@
<item>6</item>
</string-array>

<string-array name="bufferingGoal">
<item>50s</item>
<item>100s</item>
<item>200s</item>
<item>300s</item>
<item>450s</item>
</string-array>
<string-array name="bufferingGoalValues">
<item>50</item>
<item>100</item>
<item>200</item>
<item>300</item>
<item>450</item>
</string-array>

<string-array name="playerVideoFormat">
<item>WEBM</item>
<item>MPEG_4</item>
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/xml/player_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,9 @@

<PreferenceCategory app:title="@string/misc">

<ListPreference
<com.github.libretube.ui.preferences.EditNumberPreference
android:icon="@drawable/ic_time"
app:defaultValue="50"
app:entries="@array/bufferingGoal"
app:entryValues="@array/bufferingGoalValues"
app:key="buffering_goal"
app:summary="@string/buffering_goal_summary"
app:title="@string/buffering_goal" />
Expand Down
Loading