mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 14:50:30 +05:30
Merge pull request #1163 from Bnyro/master
continous playback speed slider
This commit is contained in:
commit
248de804e8
@ -59,8 +59,6 @@ class MyApp : Application() {
|
||||
existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP
|
||||
)
|
||||
|
||||
NotificationHelper(this).checkForNewStreams()
|
||||
|
||||
/**
|
||||
* Handler for uncaught exceptions
|
||||
*/
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.preference.Preference
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.DialogSliderBinding
|
||||
import com.github.libretube.preferences.PreferenceHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
/**
|
||||
* Preference that includes a slider
|
||||
*/
|
||||
class SliderPreference(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet
|
||||
) : Preference(
|
||||
context,
|
||||
attributeSet
|
||||
) {
|
||||
override fun onClick() {
|
||||
val sliderBinding = DialogSliderBinding.inflate(
|
||||
LayoutInflater.from(context)
|
||||
)
|
||||
sliderBinding.slider.value = PreferenceHelper.getString(
|
||||
key,
|
||||
"1.0"
|
||||
).toFloat()
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(title)
|
||||
.setView(sliderBinding.root)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
PreferenceHelper.putString(
|
||||
key,
|
||||
sliderBinding.slider.value.toString()
|
||||
)
|
||||
}
|
||||
.show()
|
||||
super.onClick()
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ import com.github.libretube.adapters.TrendingAdapter
|
||||
import com.github.libretube.api.CronetHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.SubscriptionHelper
|
||||
import com.github.libretube.databinding.DialogSliderBinding
|
||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.databinding.FragmentPlayerBinding
|
||||
@ -509,17 +510,17 @@ class PlayerFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
override fun onPlaybackSpeedClicked() {
|
||||
val playbackSpeeds = context?.resources?.getStringArray(R.array.playbackSpeed)!!
|
||||
val playbackSpeedValues =
|
||||
context?.resources?.getStringArray(R.array.playbackSpeedValues)!!
|
||||
|
||||
val playbackSpeedBinding = DialogSliderBinding.inflate(layoutInflater)
|
||||
playbackSpeedBinding.slider.value = exoPlayer.playbackParameters.speed
|
||||
// change playback speed dialog
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.change_playback_speed)
|
||||
.setItems(playbackSpeeds) { _, index ->
|
||||
// set the new playback speed
|
||||
val newPlaybackSpeed = playbackSpeedValues[index].toFloat()
|
||||
exoPlayer.setPlaybackSpeed(newPlaybackSpeed)
|
||||
.setView(playbackSpeedBinding.root)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
exoPlayer.setPlaybackSpeed(
|
||||
playbackSpeedBinding.slider.value
|
||||
)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
@ -598,11 +599,7 @@ class PlayerFragment : BaseFragment() {
|
||||
context.getString(R.string.none)
|
||||
}
|
||||
// set the playback speed
|
||||
val playbackSpeeds = context.resources.getStringArray(R.array.playbackSpeed)
|
||||
val playbackSpeedValues =
|
||||
context.resources.getStringArray(R.array.playbackSpeedValues)
|
||||
val playbackSpeed = exoPlayer.playbackParameters.speed.toString()
|
||||
currentPlaybackSpeed = playbackSpeeds[playbackSpeedValues.indexOf(playbackSpeed)]
|
||||
currentPlaybackSpeed = "${exoPlayer.playbackParameters.speed}x"
|
||||
// set the quality text
|
||||
val isAdaptive = exoPlayer.videoFormat?.codecs != null
|
||||
val quality = exoPlayer.videoSize.height
|
||||
|
@ -32,7 +32,7 @@ object PreferenceHelper {
|
||||
}
|
||||
|
||||
fun putString(key: String?, value: String) {
|
||||
editor.putString(key, value)
|
||||
editor.putString(key, value).commit()
|
||||
}
|
||||
|
||||
fun getString(key: String?, defValue: String?): String {
|
||||
|
16
app/src/main/res/layout/dialog_slider.xml
Normal file
16
app/src/main/res/layout/dialog_slider.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.slider.Slider
|
||||
android:id="@+id/slider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:value="1"
|
||||
android:valueFrom="0.25"
|
||||
android:valueTo="5" />
|
||||
|
||||
</LinearLayout>
|
@ -641,29 +641,6 @@
|
||||
<item>.mkv</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="playbackSpeed">
|
||||
<item>0.25x</item>
|
||||
<item>0.5x</item>
|
||||
<item>0.75x</item>
|
||||
<item>1x</item>
|
||||
<item>1.25x</item>
|
||||
<item>1.5x</item>
|
||||
<item>2x</item>
|
||||
<item>3x</item>
|
||||
<item>4x</item>
|
||||
</string-array>
|
||||
<string-array name="playbackSpeedValues">
|
||||
<item>0.25</item>
|
||||
<item>0.5</item>
|
||||
<item>0.75</item>
|
||||
<item>1.0</item>
|
||||
<item>1.25</item>
|
||||
<item>1.5</item>
|
||||
<item>2.0</item>
|
||||
<item>3.0</item>
|
||||
<item>4.0</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="downloadLocation">
|
||||
<item>@string/downloads_directory</item>
|
||||
<item>@string/music_directory</item>
|
||||
|
@ -44,14 +44,11 @@
|
||||
|
||||
<PreferenceCategory app:title="@string/player">
|
||||
|
||||
<ListPreference
|
||||
<com.github.libretube.extensions.SliderPreference
|
||||
android:icon="@drawable/ic_speed"
|
||||
app:defaultValue="1.0"
|
||||
app:entries="@array/playbackSpeed"
|
||||
app:entryValues="@array/playbackSpeedValues"
|
||||
app:key="playback_speed"
|
||||
app:title="@string/playback_speed"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
app:title="@string/playback_speed" />
|
||||
|
||||
<ListPreference
|
||||
android:icon="@drawable/ic_skip"
|
||||
@ -137,14 +134,11 @@
|
||||
|
||||
<PreferenceCategory app:title="@string/background_mode">
|
||||
|
||||
<ListPreference
|
||||
<com.github.libretube.extensions.SliderPreference
|
||||
android:icon="@drawable/ic_speed"
|
||||
app:defaultValue="1.0"
|
||||
app:entries="@array/playbackSpeed"
|
||||
app:entryValues="@array/playbackSpeedValues"
|
||||
app:key="background_playback_speed"
|
||||
app:title="@string/playback_speed"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
app:title="@string/playback_speed" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user