mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
commit
c10b0b55ef
@ -1,22 +0,0 @@
|
|||||||
package com.github.libretube.constants
|
|
||||||
|
|
||||||
import com.github.libretube.obj.SliderRange
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the ranges for the [SliderPreference]
|
|
||||||
*/
|
|
||||||
object PreferenceRanges {
|
|
||||||
val playbackSpeed = SliderRange(
|
|
||||||
0.25f,
|
|
||||||
6.0f,
|
|
||||||
0.25f,
|
|
||||||
1.0f
|
|
||||||
)
|
|
||||||
|
|
||||||
val seekIncrement = SliderRange(
|
|
||||||
5f,
|
|
||||||
60f,
|
|
||||||
5f,
|
|
||||||
10f
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.github.libretube.extensions
|
|
||||||
|
|
||||||
import com.github.libretube.obj.SliderRange
|
|
||||||
import com.google.android.material.slider.Slider
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the range of the slider preference
|
|
||||||
*/
|
|
||||||
fun Slider.setSliderRangeAndValue(range: SliderRange) {
|
|
||||||
this.valueFrom = range.valueFrom
|
|
||||||
this.valueTo = range.valueTo
|
|
||||||
this.stepSize = range.stepSize
|
|
||||||
this.value = range.defaultValue
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.github.libretube.obj
|
|
||||||
|
|
||||||
data class SliderRange(
|
|
||||||
val valueFrom: Float,
|
|
||||||
val valueTo: Float,
|
|
||||||
val stepSize: Float,
|
|
||||||
val defaultValue: Float
|
|
||||||
)
|
|
@ -11,11 +11,9 @@ import android.view.View
|
|||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.constants.PreferenceRanges
|
|
||||||
import com.github.libretube.databinding.DialogSliderBinding
|
import com.github.libretube.databinding.DialogSliderBinding
|
||||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.github.libretube.extensions.setSliderRangeAndValue
|
|
||||||
import com.github.libretube.models.interfaces.DoubleTapInterface
|
import com.github.libretube.models.interfaces.DoubleTapInterface
|
||||||
import com.github.libretube.models.interfaces.PlayerOptionsInterface
|
import com.github.libretube.models.interfaces.PlayerOptionsInterface
|
||||||
import com.github.libretube.obj.BottomSheetItem
|
import com.github.libretube.obj.BottomSheetItem
|
||||||
@ -337,10 +335,12 @@ internal class CustomExoPlayerView(
|
|||||||
val playbackSpeedBinding = DialogSliderBinding.inflate(
|
val playbackSpeedBinding = DialogSliderBinding.inflate(
|
||||||
LayoutInflater.from(context)
|
LayoutInflater.from(context)
|
||||||
)
|
)
|
||||||
playbackSpeedBinding.slider.setSliderRangeAndValue(
|
playbackSpeedBinding.slider.apply {
|
||||||
PreferenceRanges.playbackSpeed
|
valueFrom = 0.25f
|
||||||
)
|
valueTo = 4.0f
|
||||||
playbackSpeedBinding.slider.value = player?.playbackParameters?.speed ?: 1f
|
stepSize = 0.25f
|
||||||
|
value = player?.playbackParameters?.speed ?: 1f
|
||||||
|
}
|
||||||
// change playback speed dialog
|
// change playback speed dialog
|
||||||
MaterialAlertDialogBuilder(context)
|
MaterialAlertDialogBuilder(context)
|
||||||
.setTitle(R.string.change_playback_speed)
|
.setTitle(R.string.change_playback_speed)
|
||||||
|
@ -5,10 +5,7 @@ import android.util.AttributeSet
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
|
||||||
import com.github.libretube.constants.PreferenceRanges
|
|
||||||
import com.github.libretube.databinding.DialogSliderBinding
|
import com.github.libretube.databinding.DialogSliderBinding
|
||||||
import com.github.libretube.extensions.setSliderRangeAndValue
|
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
@ -24,25 +21,27 @@ class SliderPreference(
|
|||||||
) {
|
) {
|
||||||
private lateinit var sliderBinding: DialogSliderBinding
|
private lateinit var sliderBinding: DialogSliderBinding
|
||||||
|
|
||||||
|
val typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.SliderPreference)
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
|
val defValue = typedArray.getFloat(R.styleable.SliderPreference_defValue, 1.0f)
|
||||||
|
val valueFrom = typedArray.getFloat(R.styleable.SliderPreference_valueFrom, 1.0f)
|
||||||
|
val valueTo = typedArray.getFloat(R.styleable.SliderPreference_valueTo, 10.0f)
|
||||||
|
val stepSize = typedArray.getFloat(R.styleable.SliderPreference_stepSize, 1.0f)
|
||||||
|
|
||||||
sliderBinding = DialogSliderBinding.inflate(
|
sliderBinding = DialogSliderBinding.inflate(
|
||||||
LayoutInflater.from(context)
|
LayoutInflater.from(context)
|
||||||
)
|
)
|
||||||
val range = when (key) {
|
|
||||||
PreferenceKeys.PLAYBACK_SPEED -> PreferenceRanges.playbackSpeed
|
|
||||||
PreferenceKeys.BACKGROUND_PLAYBACK_SPEED -> PreferenceRanges.playbackSpeed
|
|
||||||
PreferenceKeys.SEEK_INCREMENT -> PreferenceRanges.seekIncrement
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (range == null) return
|
sliderBinding.slider.apply {
|
||||||
|
value = PreferenceHelper.getString(
|
||||||
sliderBinding.slider.setSliderRangeAndValue(range)
|
|
||||||
|
|
||||||
sliderBinding.slider.value = PreferenceHelper.getString(
|
|
||||||
key,
|
key,
|
||||||
range.defaultValue.toString()
|
defValue.toString()
|
||||||
).toFloat()
|
).toFloat()
|
||||||
|
this.valueFrom = valueFrom
|
||||||
|
this.valueTo = valueTo
|
||||||
|
this.stepSize = stepSize
|
||||||
|
}
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(context)
|
MaterialAlertDialogBuilder(context)
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
|
11
app/src/main/res/values/attrs.xml
Normal file
11
app/src/main/res/values/attrs.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<declare-styleable name="SliderPreference">
|
||||||
|
<attr name="valueFrom" format="float" />
|
||||||
|
<attr name="valueTo" format="float" />
|
||||||
|
<attr name="stepSize" format="float" />
|
||||||
|
<attr name="defValue" format="float" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
|
</resources>
|
@ -78,9 +78,12 @@
|
|||||||
|
|
||||||
<com.github.libretube.ui.views.SliderPreference
|
<com.github.libretube.ui.views.SliderPreference
|
||||||
android:icon="@drawable/ic_speed"
|
android:icon="@drawable/ic_speed"
|
||||||
app:defaultValue="1.0"
|
app:defValue="1.0"
|
||||||
app:key="background_playback_speed"
|
app:key="background_playback_speed"
|
||||||
app:title="@string/playback_speed" />
|
app:stepSize="0.25"
|
||||||
|
app:title="@string/playback_speed"
|
||||||
|
app:valueFrom="0.25"
|
||||||
|
app:valueTo="4.0" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
@ -6,15 +6,21 @@
|
|||||||
|
|
||||||
<com.github.libretube.ui.views.SliderPreference
|
<com.github.libretube.ui.views.SliderPreference
|
||||||
android:icon="@drawable/ic_speed"
|
android:icon="@drawable/ic_speed"
|
||||||
app:defaultValue="1.0"
|
app:defValue="1.0"
|
||||||
app:key="playback_speed"
|
app:key="playback_speed"
|
||||||
app:title="@string/playback_speed" />
|
app:stepSize="0.25"
|
||||||
|
app:title="@string/playback_speed"
|
||||||
|
app:valueFrom="0.25"
|
||||||
|
app:valueTo="4.0" />
|
||||||
|
|
||||||
<com.github.libretube.ui.views.SliderPreference
|
<com.github.libretube.ui.views.SliderPreference
|
||||||
android:icon="@drawable/ic_skip"
|
android:icon="@drawable/ic_skip"
|
||||||
app:defaultValue="5"
|
app:defValue="10.0"
|
||||||
app:key="seek_increment"
|
app:key="seek_increment"
|
||||||
app:title="@string/seek_increment" />
|
app:stepSize="5.0"
|
||||||
|
app:title="@string/seek_increment"
|
||||||
|
app:valueFrom="5.0"
|
||||||
|
app:valueTo="60.0" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:icon="@drawable/ic_time"
|
android:icon="@drawable/ic_time"
|
||||||
|
Loading…
Reference in New Issue
Block a user