-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add playback speed slider dialog (#489)
* add playback speed dialog * replace correct icons to playbackSpeed dialog * rename playback speed dialog class name * lint: run KtlintFormat
- Loading branch information
1 parent
e134ab9
commit c77d723
Showing
7 changed files
with
136 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...dev/anilbeesetti/nextplayer/feature/player/dialogs/PlaybackSpeedControlsDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
...ev/anilbeesetti/nextplayer/feature/player/dialogs/PlaybackSpeedSelectionDialogFragment.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |