Skip to content

Commit d4d6d71

Browse files
committed
feat(playback-options): set speed steps to 0.25
Changes the step size of the playback speed slider to `0.25`. This makes it easier to select an appropriate speed as well as following established standard in most other video players (e.g. the official one). Existing users are migrated to the nearest .25 playback speed to avoid crashes when upgrading. Closes: libre-tube#8243
1 parent 01ac1ac commit d4d6d71

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import com.github.libretube.R
1010
import com.github.libretube.api.TrendingCategory
1111
import com.github.libretube.constants.PreferenceKeys
1212
import com.github.libretube.enums.SbSkipOptions
13+
import com.github.libretube.extensions.round
1314
import com.github.libretube.helpers.LocaleHelper.getDetectedCountry
15+
import kotlin.math.roundToInt
1416

1517
object PreferenceHelper {
1618
private val TAG = PreferenceHelper::class.simpleName
@@ -135,6 +137,13 @@ object PreferenceHelper {
135137
PreferenceMigration(4, 5) {
136138
remove("remember_playback_speed")
137139
},
140+
PreferenceMigration(5, 6) {
141+
val currentSpeed = (settings.getString(PreferenceKeys.PLAYBACK_SPEED, null)
142+
?: return@PreferenceMigration).replace("F", "").toFloat()
143+
// round to the nearest .25 playback speed
144+
val speed = (currentSpeed * 4f).roundToInt() / 4f
145+
putString(PreferenceKeys.PLAYBACK_SPEED, speed.toString())
146+
},
138147
)
139148

140149
/**

app/src/main/res/layout/playback_bottom_sheet.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
android:id="@+id/speed"
6060
android:layout_width="match_parent"
6161
android:layout_height="wrap_content"
62-
android:stepSize="0.05"
62+
android:stepSize="0.25"
6363
android:value="1.0"
64-
android:valueFrom="0.2"
64+
android:valueFrom="0.25"
6565
android:valueTo="4.0"
6666
android:layout_marginTop="5dp"
6767
android:layout_marginHorizontal="10dp" />

0 commit comments

Comments
 (0)