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: Add playback speed slider dialog #489

Merged
merged 4 commits into from
Aug 8, 2023
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
5 changes: 5 additions & 0 deletions core/ui/src/main/res/drawable/ic_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,13h-5v5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-5H6c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h5V6c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v5h5c0.55,0 1,0.45 1,1s-0.45,1 -1,1z"/>
</vector>
5 changes: 5 additions & 0 deletions core/ui/src/main/res/drawable/ic_remove.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,13H6c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1h12c0.55,0 1,0.45 1,1s-0.45,1 -1,1z"/>
</vector>
5 changes: 5 additions & 0 deletions core/ui/src/main/res/drawable/ic_reset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M13.26,3C8.17,2.86 4,6.95 4,12L2.21,12c-0.45,0 -0.67,0.54 -0.35,0.85l2.79,2.8c0.2,0.2 0.51,0.2 0.71,0l2.79,-2.8c0.31,-0.31 0.09,-0.85 -0.36,-0.85L6,12c0,-3.9 3.18,-7.05 7.1,-7 3.72,0.05 6.85,3.18 6.9,6.9 0.05,3.91 -3.1,7.1 -7,7.1 -1.61,0 -3.1,-0.55 -4.28,-1.48 -0.4,-0.31 -0.96,-0.28 -1.32,0.08 -0.42,0.42 -0.39,1.13 0.08,1.49C9,20.29 10.91,21 13,21c5.05,0 9.14,-4.17 9,-9.26 -0.13,-4.69 -4.05,-8.61 -8.74,-8.74zM12.75,8c-0.41,0 -0.75,0.34 -0.75,0.75v3.68c0,0.35 0.19,0.68 0.49,0.86l3.12,1.85c0.36,0.21 0.82,0.09 1.03,-0.26 0.21,-0.36 0.09,-0.82 -0.26,-1.03l-2.88,-1.71v-3.4c0,-0.4 -0.34,-0.74 -0.75,-0.74z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import dev.anilbeesetti.nextplayer.core.model.ScreenOrientation
import dev.anilbeesetti.nextplayer.core.model.ThemeConfig
import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR
import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding
import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedSelectionDialogFragment
import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment
import dev.anilbeesetti.nextplayer.feature.player.dialogs.TrackSelectionDialogFragment
import dev.anilbeesetti.nextplayer.feature.player.dialogs.getCurrentTrackIndex
import dev.anilbeesetti.nextplayer.feature.player.extensions.getLocalSubtitles
Expand Down Expand Up @@ -306,7 +306,7 @@ class PlayerActivity : AppCompatActivity() {
}

playbackSpeedButton.setOnClickListener {
PlaybackSpeedSelectionDialogFragment(
PlaybackSpeedControlsDialogFragment(
currentSpeed = player.playbackParameters.speed,
onChange = {
viewModel.isPlaybackSpeedChanged = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dev.anilbeesetti.nextplayer.feature.player.dialogs

import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR
import dev.anilbeesetti.nextplayer.feature.player.databinding.PlaybackSpeedBinding

class PlaybackSpeedControlsDialogFragment(
private val currentSpeed: Float,
private val onChange: (Float) -> Unit
) : DialogFragment() {

private lateinit var binding: PlaybackSpeedBinding

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = PlaybackSpeedBinding.inflate(layoutInflater)

return activity?.let { activity ->
binding.apply {
speedText.text = currentSpeed.toString()
speed.value = currentSpeed
speed.addOnChangeListener { _, _, _ ->
val newSpeed = String.format("%.1f", speed.value).toFloat()
onChange(newSpeed)
speedText.text = newSpeed.toString()
}
resetSpeed.setOnClickListener {
speed.value = 1.0f
}
incSpeed.setOnClickListener {
if (speed.value < 4.0f) {
speed.value += 0.1f
}
}
decSpeed.setOnClickListener {
if (speed.value > 0.2f) {
speed.value -= 0.1f
}
}
}

val builder = MaterialAlertDialogBuilder(activity)
builder.setTitle(getString(coreUiR.string.select_playback_speed))
.setView(binding.root)
.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}

This file was deleted.

69 changes: 69 additions & 0 deletions feature/player/src/main/res/layout/playback_speed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="16dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<com.google.android.material.button.MaterialButton
android:id="@+id/dec_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
app:icon="@drawable/ic_remove" />

<TextView
android:id="@+id/speed_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
android:gravity="center"
android:layout_weight="1"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/inc_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
app:icon="@drawable/ic_add"/>


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="20dp">

<com.google.android.material.slider.Slider
android:id="@+id/speed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stepSize="0.1"
android:value="1.0"
android:valueFrom="0.2"
android:valueTo="4.0"
android:layout_gravity="center"
android:theme="@style/Widget.Material3.Slider"
app:labelBehavior="gone" />

<com.google.android.material.button.MaterialButton
android:id="@+id/reset_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
style="@style/Widget.Material3.Button.IconButton"
app:icon="@drawable/ic_reset" />
</LinearLayout>

</LinearLayout>