From 1dc1fc8f89180a24c7872f84547889c0b5d4a0ee Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Thu, 21 Nov 2024 16:47:13 +0000 Subject: [PATCH 01/11] Initial dev work, todo: tests and translations --- ...SpeedSelectionCustomSpeedDialogFragment.kt | 48 +++++++++++++++++++ .../dialogs/SpeedSelectionDialogFragment.kt | 30 +++++++++--- player/video/src/main/res/values/strings.xml | 3 ++ 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt new file mode 100644 index 0000000000..63b48b7dd9 --- /dev/null +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -0,0 +1,48 @@ +package dev.jdtech.jellyfin.dialogs + +import android.app.Dialog +import android.os.Bundle +import android.view.KeyEvent +import android.view.WindowManager +import android.view.inputmethod.EditorInfo +import androidx.fragment.app.DialogFragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout +import dev.jdtech.jellyfin.player.video.R + +class SpeedSelectionCustomSpeedDialogFragment( + private val speedSelectionDialog: SpeedSelectionDialogFragment +): DialogFragment() { + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + + return activity?.let { activity -> + val textInputLayout = TextInputLayout(activity) + val editText = TextInputEditText(textInputLayout.context) + // Bitwise OR creates the input type for a decimal number. + editText.inputType = android.text.InputType.TYPE_CLASS_NUMBER.or(android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL) + + val builtDialog = MaterialAlertDialogBuilder(activity) + .setTitle(getString(R.string.custom_playback_speed)) + .setView(editText).create() + + editText.setOnEditorActionListener { textView, actionId, keyEvent -> + if (actionId == EditorInfo.IME_ACTION_DONE || keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) { + val newSpeed = textView.text.toString().toFloatOrNull() + if (newSpeed != null && newSpeed <= 3f && newSpeed >= 0.25f) { + speedSelectionDialog.setCustomSpeed(newSpeed) + } + builtDialog.dismiss() + } + + true + } + + builtDialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) + builtDialog.setOnShowListener {_ -> editText.requestFocus()} + + builtDialog + } ?: throw IllegalStateException("Activity cannot be null"); + } +} \ No newline at end of file diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index 47240638e6..5810017c50 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -9,14 +9,24 @@ import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder import dev.jdtech.jellyfin.player.video.R import dev.jdtech.jellyfin.viewmodels.PlayerActivityViewModel -import java.lang.IllegalStateException class SpeedSelectionDialogFragment( private val viewModel: PlayerActivityViewModel, ) : DialogFragment() { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val speedTexts = listOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x") - val speedNumbers = listOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) + val customLabel = getString(R.string.custom_playback_speed_label) + val currentSpeed = viewModel.playbackSpeed + val speedTexts = mutableListOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x") + val speedNumbers = mutableListOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) + + if (currentSpeed !in speedNumbers) { + speedTexts.add(customLabel + ": " + currentSpeed + "x") + speedNumbers.add(currentSpeed) + } + else { + speedTexts.add(customLabel) + } return activity?.let { activity -> val builder = MaterialAlertDialogBuilder(activity) @@ -25,9 +35,13 @@ class SpeedSelectionDialogFragment( speedTexts.toTypedArray(), speedNumbers.indexOf(viewModel.playbackSpeed), ) { dialog, which -> - viewModel.selectSpeed( - speedNumbers[which], - ) + if (speedTexts[which].startsWith(customLabel)) { + SpeedSelectionCustomSpeedDialogFragment(this) + .show(activity.supportFragmentManager, "customSpeedSelection") + } + else { + viewModel.selectSpeed(speedNumbers[which]) + } dialog.dismiss() } builder.create() @@ -44,4 +58,8 @@ class SpeedSelectionDialogFragment( } } } + + fun setCustomSpeed(speed: Float) { + viewModel.selectSpeed(speed) + } } diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index 124455aa86..3243ff1344 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -2,6 +2,9 @@ Select audio track Select subtitle track Select playback speed + + Enter custom playback speed + Custom "Select a version" External None From b85fc341e792c7a806e2d3abb9513d3bacad6a56 Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Thu, 21 Nov 2024 18:33:34 +0000 Subject: [PATCH 02/11] Add tranlsations --- player/video/src/main/res/values-b+es+419/strings.xml | 2 ++ player/video/src/main/res/values-bg/strings.xml | 2 ++ player/video/src/main/res/values-cs-rCZ/strings.xml | 2 ++ player/video/src/main/res/values-da/strings.xml | 2 ++ player/video/src/main/res/values-de/strings.xml | 2 ++ player/video/src/main/res/values-es-rMX/strings.xml | 2 ++ player/video/src/main/res/values-es/strings.xml | 2 ++ player/video/src/main/res/values-fr/strings.xml | 2 ++ player/video/src/main/res/values-hu/strings.xml | 2 ++ player/video/src/main/res/values-it/strings.xml | 2 ++ player/video/src/main/res/values-iw/strings.xml | 2 ++ player/video/src/main/res/values-ko/strings.xml | 2 ++ player/video/src/main/res/values-nl/strings.xml | 2 ++ player/video/src/main/res/values-pl/strings.xml | 2 ++ player/video/src/main/res/values-pt-rBR/strings.xml | 2 ++ player/video/src/main/res/values-pt/strings.xml | 2 ++ player/video/src/main/res/values-ru/strings.xml | 2 ++ player/video/src/main/res/values-sk/strings.xml | 2 ++ player/video/src/main/res/values-sl/strings.xml | 2 ++ player/video/src/main/res/values-sv/strings.xml | 2 ++ player/video/src/main/res/values-tr/strings.xml | 2 ++ player/video/src/main/res/values-uk/strings.xml | 2 ++ player/video/src/main/res/values-vi/strings.xml | 2 ++ player/video/src/main/res/values-zh-rCN/strings.xml | 2 ++ player/video/src/main/res/values-zh-rTW/strings.xml | 2 ++ player/video/src/main/res/values/strings.xml | 3 +-- 26 files changed, 51 insertions(+), 2 deletions(-) diff --git a/player/video/src/main/res/values-b+es+419/strings.xml b/player/video/src/main/res/values-b+es+419/strings.xml index d9eeac303a..1fae9b0a2e 100644 --- a/player/video/src/main/res/values-b+es+419/strings.xml +++ b/player/video/src/main/res/values-b+es+419/strings.xml @@ -1,5 +1,6 @@ + hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtitulo @@ -18,4 +19,5 @@ Entrar en modo PIP Ninguno Saltar créditos + velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-bg/strings.xml b/player/video/src/main/res/values-bg/strings.xml index 762283466a..72a95182da 100644 --- a/player/video/src/main/res/values-bg/strings.xml +++ b/player/video/src/main/res/values-bg/strings.xml @@ -3,6 +3,7 @@ Изберете аудиопът Изберете писта за субтитри Изберете скорост на възпроизвеждане + да поръчам Изберете версия Външно Пусни предишен @@ -17,4 +18,5 @@ Пропусни интро Влез в режим картина-в-картина Нищо + скорост \ No newline at end of file diff --git a/player/video/src/main/res/values-cs-rCZ/strings.xml b/player/video/src/main/res/values-cs-rCZ/strings.xml index daae75ddd7..c57bf3d490 100644 --- a/player/video/src/main/res/values-cs-rCZ/strings.xml +++ b/player/video/src/main/res/values-cs-rCZ/strings.xml @@ -3,6 +3,7 @@ Vyberte zvukovou stopu Vyberte titulky Zvolte rychlost přehrávání + na zakázku Vybrat verzi Externí Uzamkne přehrávač @@ -15,4 +16,5 @@ Přeskočit vpřed Vstoupit do režimu obraz v obraze Ukazatel průběhu + Rychlost \ No newline at end of file diff --git a/player/video/src/main/res/values-da/strings.xml b/player/video/src/main/res/values-da/strings.xml index b022c4a07d..3e129edfa6 100644 --- a/player/video/src/main/res/values-da/strings.xml +++ b/player/video/src/main/res/values-da/strings.xml @@ -4,6 +4,7 @@ Afspilnings pause Vælg undertekster Vælg afspilnings hastighed + skræddersyet Vælg en version Ekstern Start billed i billed @@ -17,4 +18,5 @@ Ingen Process indikator Spol tilbage + Hastighed \ No newline at end of file diff --git a/player/video/src/main/res/values-de/strings.xml b/player/video/src/main/res/values-de/strings.xml index ab3eebc0ac..2e0da3ed1c 100644 --- a/player/video/src/main/res/values-de/strings.xml +++ b/player/video/src/main/res/values-de/strings.xml @@ -1,5 +1,6 @@ + maßgeschneidert Wähle eine Version Wähle eine Audiospur Wähle eine Untertitelspur @@ -18,4 +19,5 @@ Bild-in-Bild öffnen Abspann überspringen Pseudovideo + Geschwindigkeit \ No newline at end of file diff --git a/player/video/src/main/res/values-es-rMX/strings.xml b/player/video/src/main/res/values-es-rMX/strings.xml index d6aeedfc89..a067161d2f 100644 --- a/player/video/src/main/res/values-es-rMX/strings.xml +++ b/player/video/src/main/res/values-es-rMX/strings.xml @@ -1,5 +1,6 @@ + hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtitulo @@ -18,4 +19,5 @@ Ninguno Entrar en pantalla en pantalla Saltar créditos + velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-es/strings.xml b/player/video/src/main/res/values-es/strings.xml index 1117cf993e..520b065b5c 100644 --- a/player/video/src/main/res/values-es/strings.xml +++ b/player/video/src/main/res/values-es/strings.xml @@ -1,5 +1,6 @@ + hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtítulo @@ -18,4 +19,5 @@ Ninguno Saltar créditos Entrar en pantalla en pantalla + velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-fr/strings.xml b/player/video/src/main/res/values-fr/strings.xml index d53c93ac0d..eef2131f11 100644 --- a/player/video/src/main/res/values-fr/strings.xml +++ b/player/video/src/main/res/values-fr/strings.xml @@ -1,5 +1,6 @@ + sur mesure Choisissez une version Choix de la piste audio Choix de la piste des sous-titres @@ -17,4 +18,5 @@ Barre de progression Détacher la fenêtre flottante Aucun + Vitesse \ No newline at end of file diff --git a/player/video/src/main/res/values-hu/strings.xml b/player/video/src/main/res/values-hu/strings.xml index bdc485b743..942932c6ed 100644 --- a/player/video/src/main/res/values-hu/strings.xml +++ b/player/video/src/main/res/values-hu/strings.xml @@ -1,5 +1,6 @@ + mérték utáni Verzió kiválasztása Hangsáv kiválasztása Felirat kiválasztása @@ -18,4 +19,5 @@ Belépés kép a képben Nincs Stáblista kihagyása + Sebesség \ No newline at end of file diff --git a/player/video/src/main/res/values-it/strings.xml b/player/video/src/main/res/values-it/strings.xml index 2660714cdb..82227bf50a 100644 --- a/player/video/src/main/res/values-it/strings.xml +++ b/player/video/src/main/res/values-it/strings.xml @@ -1,5 +1,6 @@ + su misura Seleziona una versione Traccia audio Traccia dei sottotitoli @@ -18,4 +19,5 @@ Attiva picture in picture Nessuno Salta crediti + Velocità \ No newline at end of file diff --git a/player/video/src/main/res/values-iw/strings.xml b/player/video/src/main/res/values-iw/strings.xml index c2fa91a430..5b9845fcbc 100644 --- a/player/video/src/main/res/values-iw/strings.xml +++ b/player/video/src/main/res/values-iw/strings.xml @@ -3,6 +3,7 @@ בחר רצועת שמע בחר מהירות הפעלה חיצוני + בהזמנה אישית בחר גרסה בחר רצועת כתוביות צא מהנגן @@ -16,4 +17,5 @@ סרגל התקדמות Trickplay הפעל תמונה-בתוך-תמונה + מְהִירוּת \ No newline at end of file diff --git a/player/video/src/main/res/values-ko/strings.xml b/player/video/src/main/res/values-ko/strings.xml index 81e8113734..d31eff07c1 100644 --- a/player/video/src/main/res/values-ko/strings.xml +++ b/player/video/src/main/res/values-ko/strings.xml @@ -1,5 +1,6 @@ + 맞춤형 버전 선택 오디오 트랙 선택 자막 트랙 선택 @@ -18,4 +19,5 @@ picture-in-picture 전환 없음 엔딩 스킵 + 속도 \ No newline at end of file diff --git a/player/video/src/main/res/values-nl/strings.xml b/player/video/src/main/res/values-nl/strings.xml index 2f6920a0d6..eb9617294f 100644 --- a/player/video/src/main/res/values-nl/strings.xml +++ b/player/video/src/main/res/values-nl/strings.xml @@ -1,5 +1,6 @@ + op maat Kies een versie Selecteer audiotrack Selecteer ondertiteling @@ -17,4 +18,5 @@ Speel pauze Vooruit springen Trickplay + Snelheid \ No newline at end of file diff --git a/player/video/src/main/res/values-pl/strings.xml b/player/video/src/main/res/values-pl/strings.xml index 939043211e..734d97067d 100644 --- a/player/video/src/main/res/values-pl/strings.xml +++ b/player/video/src/main/res/values-pl/strings.xml @@ -1,5 +1,6 @@ + obstalunkowy Wybierz wersję Wybierz ścieżkę audio Wybierz ścieżkę napisów @@ -18,4 +19,5 @@ Wejdź w tryb obrazu w obrazie Brak Pomiń napisy końcowe + Prędkość \ No newline at end of file diff --git a/player/video/src/main/res/values-pt-rBR/strings.xml b/player/video/src/main/res/values-pt-rBR/strings.xml index 4ec61c9b05..e3292ea290 100644 --- a/player/video/src/main/res/values-pt-rBR/strings.xml +++ b/player/video/src/main/res/values-pt-rBR/strings.xml @@ -1,5 +1,6 @@ + personalizada Selecione uma versão Selecione uma faixa de áudio Selecione uma legenda @@ -18,4 +19,5 @@ Entrar no picture-in-picture Nenhum Pular créditos + Velocidade \ No newline at end of file diff --git a/player/video/src/main/res/values-pt/strings.xml b/player/video/src/main/res/values-pt/strings.xml index eeb511509a..5a563c772b 100644 --- a/player/video/src/main/res/values-pt/strings.xml +++ b/player/video/src/main/res/values-pt/strings.xml @@ -1,5 +1,6 @@ + personalizada Selecionar a versão Seleccione a faixa de áudio Seleccione as legendas @@ -17,4 +18,5 @@ Pular introdução Insira imagem em imagem Nenhum + Velocidade \ No newline at end of file diff --git a/player/video/src/main/res/values-ru/strings.xml b/player/video/src/main/res/values-ru/strings.xml index d281897e03..35f1035765 100644 --- a/player/video/src/main/res/values-ru/strings.xml +++ b/player/video/src/main/res/values-ru/strings.xml @@ -2,6 +2,7 @@ Выбрать субтитры Выбрать скорость воспроизведения + сделанный на заказ Выбрать версию Выбрать аудиодорожку Внешнее @@ -18,4 +19,5 @@ Отключить Картинка в картинке Пропустить титры + Скорость \ No newline at end of file diff --git a/player/video/src/main/res/values-sk/strings.xml b/player/video/src/main/res/values-sk/strings.xml index 86e624fab5..13fb4685c5 100644 --- a/player/video/src/main/res/values-sk/strings.xml +++ b/player/video/src/main/res/values-sk/strings.xml @@ -3,6 +3,7 @@ Vybrať zvukovú stopu Vybrať titulky Vybrať rýchlosť prehrávania + zákazkový Vybrať verziu Externé Zavrieť prehrávač @@ -18,4 +19,5 @@ Zapnúť obraz v obraze Žiadne Preskočiť kredity + Rýchlosť \ No newline at end of file diff --git a/player/video/src/main/res/values-sl/strings.xml b/player/video/src/main/res/values-sl/strings.xml index 72b604efe1..a5f96e097a 100644 --- a/player/video/src/main/res/values-sl/strings.xml +++ b/player/video/src/main/res/values-sl/strings.xml @@ -3,6 +3,7 @@ Izberite zvočno sled Izberite podnapise Izberite hitrost predvajanja + po meri Izberite različico Zunanjo Izhod iz predvajalnika @@ -14,4 +15,5 @@ Predvajaj ustavi Vrstica napredka Preskoči naprej + Hitrost \ No newline at end of file diff --git a/player/video/src/main/res/values-sv/strings.xml b/player/video/src/main/res/values-sv/strings.xml index 3e9998a133..ffbafa15a3 100644 --- a/player/video/src/main/res/values-sv/strings.xml +++ b/player/video/src/main/res/values-sv/strings.xml @@ -2,6 +2,7 @@ Välj textningsspår Välj uppspelningshastighet + skräddarsydda Välj en version Extern Välj ljudspår @@ -9,4 +10,5 @@ Spola tillbaka Spola framåt Hoppa över intro + hastighet \ No newline at end of file diff --git a/player/video/src/main/res/values-tr/strings.xml b/player/video/src/main/res/values-tr/strings.xml index e5d31a6651..1cdf4e5037 100644 --- a/player/video/src/main/res/values-tr/strings.xml +++ b/player/video/src/main/res/values-tr/strings.xml @@ -3,6 +3,8 @@ Ses parçasını seç Altyazı parçasını seç Oynatma hızını seç + ısmarlama Bir sürüm seç Hiçbiri + hız \ No newline at end of file diff --git a/player/video/src/main/res/values-uk/strings.xml b/player/video/src/main/res/values-uk/strings.xml index 8b54d3f582..f548d12d07 100644 --- a/player/video/src/main/res/values-uk/strings.xml +++ b/player/video/src/main/res/values-uk/strings.xml @@ -3,10 +3,12 @@ Вибрати звукову доріжку Вибрати доріжку субтитрів Вибрати швидкість перегляду + на замовлення Вибрати версію Зовнішнє Відмотка Швидке перемотування Вийти з плеєра Пропустити вступ + швидкість \ No newline at end of file diff --git a/player/video/src/main/res/values-vi/strings.xml b/player/video/src/main/res/values-vi/strings.xml index f3061da1e0..ef98e3177c 100644 --- a/player/video/src/main/res/values-vi/strings.xml +++ b/player/video/src/main/res/values-vi/strings.xml @@ -2,6 +2,7 @@ Chọn dòng phụ đề Chọn tốc độ phát + đặt làm riêng Chọn phiên bản Ngoại Chọn dòng âm thanh @@ -16,4 +17,5 @@ Tiến tới Tua mượt mà Thanh tiến trình + tốc độ \ No newline at end of file diff --git a/player/video/src/main/res/values-zh-rCN/strings.xml b/player/video/src/main/res/values-zh-rCN/strings.xml index 8ed94e7038..c64bbd0e7f 100644 --- a/player/video/src/main/res/values-zh-rCN/strings.xml +++ b/player/video/src/main/res/values-zh-rCN/strings.xml @@ -1,5 +1,6 @@ + 定制的 选择版本 选择音轨 选择字幕轨 @@ -18,4 +19,5 @@ 进入画中画 跳过片尾 + 速度 \ No newline at end of file diff --git a/player/video/src/main/res/values-zh-rTW/strings.xml b/player/video/src/main/res/values-zh-rTW/strings.xml index 44f3e4bb77..3ed8911186 100644 --- a/player/video/src/main/res/values-zh-rTW/strings.xml +++ b/player/video/src/main/res/values-zh-rTW/strings.xml @@ -1,5 +1,6 @@ + 定制的 選擇版本 選擇音軌 選擇字幕軌道 @@ -18,4 +19,5 @@ 進度條 跳過片尾 + 速度 \ No newline at end of file diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index 3243ff1344..4e988c4b42 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -2,8 +2,7 @@ Select audio track Select subtitle track Select playback speed - - Enter custom playback speed + Speed Custom "Select a version" External From f91a306855ddafe1ad7996b5406fbfae14a54a49 Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Thu, 21 Nov 2024 18:47:48 +0000 Subject: [PATCH 03/11] minor tweaks --- .../dialogs/SpeedSelectionCustomSpeedDialogFragment.kt | 5 +++-- .../jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index 63b48b7dd9..7cad6b20ef 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -25,9 +25,11 @@ class SpeedSelectionCustomSpeedDialogFragment( val builtDialog = MaterialAlertDialogBuilder(activity) .setTitle(getString(R.string.custom_playback_speed)) - .setView(editText).create() + .setView(editText) + .create() editText.setOnEditorActionListener { textView, actionId, keyEvent -> + // Accepting ENTER KeyEvents should provide better support for physical keyboards. if (actionId == EditorInfo.IME_ACTION_DONE || keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) { val newSpeed = textView.text.toString().toFloatOrNull() if (newSpeed != null && newSpeed <= 3f && newSpeed >= 0.25f) { @@ -35,7 +37,6 @@ class SpeedSelectionCustomSpeedDialogFragment( } builtDialog.dismiss() } - true } diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index 5810017c50..fc68af21b7 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -17,6 +17,7 @@ class SpeedSelectionDialogFragment( override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val customLabel = getString(R.string.custom_playback_speed_label) val currentSpeed = viewModel.playbackSpeed + val speedTexts = mutableListOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x") val speedNumbers = mutableListOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) @@ -36,11 +37,12 @@ class SpeedSelectionDialogFragment( speedNumbers.indexOf(viewModel.playbackSpeed), ) { dialog, which -> if (speedTexts[which].startsWith(customLabel)) { + // Use a secondary dialog to determine the speed to set. SpeedSelectionCustomSpeedDialogFragment(this) .show(activity.supportFragmentManager, "customSpeedSelection") } else { - viewModel.selectSpeed(speedNumbers[which]) + setCustomSpeed(speedNumbers[which]) } dialog.dismiss() } From 2144a9cd3606c9158e921b7d0bb1223451cfab1a Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Thu, 21 Nov 2024 21:34:05 +0000 Subject: [PATCH 04/11] Revert "Add tranlsations" This reverts commit b85fc341e792c7a806e2d3abb9513d3bacad6a56. --- player/video/src/main/res/values-b+es+419/strings.xml | 2 -- player/video/src/main/res/values-bg/strings.xml | 2 -- player/video/src/main/res/values-cs-rCZ/strings.xml | 2 -- player/video/src/main/res/values-da/strings.xml | 2 -- player/video/src/main/res/values-de/strings.xml | 2 -- player/video/src/main/res/values-es-rMX/strings.xml | 2 -- player/video/src/main/res/values-es/strings.xml | 2 -- player/video/src/main/res/values-fr/strings.xml | 2 -- player/video/src/main/res/values-hu/strings.xml | 2 -- player/video/src/main/res/values-it/strings.xml | 2 -- player/video/src/main/res/values-iw/strings.xml | 2 -- player/video/src/main/res/values-ko/strings.xml | 2 -- player/video/src/main/res/values-nl/strings.xml | 2 -- player/video/src/main/res/values-pl/strings.xml | 2 -- player/video/src/main/res/values-pt-rBR/strings.xml | 2 -- player/video/src/main/res/values-pt/strings.xml | 2 -- player/video/src/main/res/values-ru/strings.xml | 2 -- player/video/src/main/res/values-sk/strings.xml | 2 -- player/video/src/main/res/values-sl/strings.xml | 2 -- player/video/src/main/res/values-sv/strings.xml | 2 -- player/video/src/main/res/values-tr/strings.xml | 2 -- player/video/src/main/res/values-uk/strings.xml | 2 -- player/video/src/main/res/values-vi/strings.xml | 2 -- player/video/src/main/res/values-zh-rCN/strings.xml | 2 -- player/video/src/main/res/values-zh-rTW/strings.xml | 2 -- player/video/src/main/res/values/strings.xml | 3 ++- 26 files changed, 2 insertions(+), 51 deletions(-) diff --git a/player/video/src/main/res/values-b+es+419/strings.xml b/player/video/src/main/res/values-b+es+419/strings.xml index 1fae9b0a2e..d9eeac303a 100644 --- a/player/video/src/main/res/values-b+es+419/strings.xml +++ b/player/video/src/main/res/values-b+es+419/strings.xml @@ -1,6 +1,5 @@ - hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtitulo @@ -19,5 +18,4 @@ Entrar en modo PIP Ninguno Saltar créditos - velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-bg/strings.xml b/player/video/src/main/res/values-bg/strings.xml index 72a95182da..762283466a 100644 --- a/player/video/src/main/res/values-bg/strings.xml +++ b/player/video/src/main/res/values-bg/strings.xml @@ -3,7 +3,6 @@ Изберете аудиопът Изберете писта за субтитри Изберете скорост на възпроизвеждане - да поръчам Изберете версия Външно Пусни предишен @@ -18,5 +17,4 @@ Пропусни интро Влез в режим картина-в-картина Нищо - скорост \ No newline at end of file diff --git a/player/video/src/main/res/values-cs-rCZ/strings.xml b/player/video/src/main/res/values-cs-rCZ/strings.xml index c57bf3d490..daae75ddd7 100644 --- a/player/video/src/main/res/values-cs-rCZ/strings.xml +++ b/player/video/src/main/res/values-cs-rCZ/strings.xml @@ -3,7 +3,6 @@ Vyberte zvukovou stopu Vyberte titulky Zvolte rychlost přehrávání - na zakázku Vybrat verzi Externí Uzamkne přehrávač @@ -16,5 +15,4 @@ Přeskočit vpřed Vstoupit do režimu obraz v obraze Ukazatel průběhu - Rychlost \ No newline at end of file diff --git a/player/video/src/main/res/values-da/strings.xml b/player/video/src/main/res/values-da/strings.xml index 3e129edfa6..b022c4a07d 100644 --- a/player/video/src/main/res/values-da/strings.xml +++ b/player/video/src/main/res/values-da/strings.xml @@ -4,7 +4,6 @@ Afspilnings pause Vælg undertekster Vælg afspilnings hastighed - skræddersyet Vælg en version Ekstern Start billed i billed @@ -18,5 +17,4 @@ Ingen Process indikator Spol tilbage - Hastighed \ No newline at end of file diff --git a/player/video/src/main/res/values-de/strings.xml b/player/video/src/main/res/values-de/strings.xml index 2e0da3ed1c..ab3eebc0ac 100644 --- a/player/video/src/main/res/values-de/strings.xml +++ b/player/video/src/main/res/values-de/strings.xml @@ -1,6 +1,5 @@ - maßgeschneidert Wähle eine Version Wähle eine Audiospur Wähle eine Untertitelspur @@ -19,5 +18,4 @@ Bild-in-Bild öffnen Abspann überspringen Pseudovideo - Geschwindigkeit \ No newline at end of file diff --git a/player/video/src/main/res/values-es-rMX/strings.xml b/player/video/src/main/res/values-es-rMX/strings.xml index a067161d2f..d6aeedfc89 100644 --- a/player/video/src/main/res/values-es-rMX/strings.xml +++ b/player/video/src/main/res/values-es-rMX/strings.xml @@ -1,6 +1,5 @@ - hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtitulo @@ -19,5 +18,4 @@ Ninguno Entrar en pantalla en pantalla Saltar créditos - velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-es/strings.xml b/player/video/src/main/res/values-es/strings.xml index 520b065b5c..1117cf993e 100644 --- a/player/video/src/main/res/values-es/strings.xml +++ b/player/video/src/main/res/values-es/strings.xml @@ -1,6 +1,5 @@ - hecho a la medida Selecciona una versión Selecciona la pista de audio Selecciona la pista de subtítulo @@ -19,5 +18,4 @@ Ninguno Saltar créditos Entrar en pantalla en pantalla - velocidad \ No newline at end of file diff --git a/player/video/src/main/res/values-fr/strings.xml b/player/video/src/main/res/values-fr/strings.xml index eef2131f11..d53c93ac0d 100644 --- a/player/video/src/main/res/values-fr/strings.xml +++ b/player/video/src/main/res/values-fr/strings.xml @@ -1,6 +1,5 @@ - sur mesure Choisissez une version Choix de la piste audio Choix de la piste des sous-titres @@ -18,5 +17,4 @@ Barre de progression Détacher la fenêtre flottante Aucun - Vitesse \ No newline at end of file diff --git a/player/video/src/main/res/values-hu/strings.xml b/player/video/src/main/res/values-hu/strings.xml index 942932c6ed..bdc485b743 100644 --- a/player/video/src/main/res/values-hu/strings.xml +++ b/player/video/src/main/res/values-hu/strings.xml @@ -1,6 +1,5 @@ - mérték utáni Verzió kiválasztása Hangsáv kiválasztása Felirat kiválasztása @@ -19,5 +18,4 @@ Belépés kép a képben Nincs Stáblista kihagyása - Sebesség \ No newline at end of file diff --git a/player/video/src/main/res/values-it/strings.xml b/player/video/src/main/res/values-it/strings.xml index 82227bf50a..2660714cdb 100644 --- a/player/video/src/main/res/values-it/strings.xml +++ b/player/video/src/main/res/values-it/strings.xml @@ -1,6 +1,5 @@ - su misura Seleziona una versione Traccia audio Traccia dei sottotitoli @@ -19,5 +18,4 @@ Attiva picture in picture Nessuno Salta crediti - Velocità \ No newline at end of file diff --git a/player/video/src/main/res/values-iw/strings.xml b/player/video/src/main/res/values-iw/strings.xml index 5b9845fcbc..c2fa91a430 100644 --- a/player/video/src/main/res/values-iw/strings.xml +++ b/player/video/src/main/res/values-iw/strings.xml @@ -3,7 +3,6 @@ בחר רצועת שמע בחר מהירות הפעלה חיצוני - בהזמנה אישית בחר גרסה בחר רצועת כתוביות צא מהנגן @@ -17,5 +16,4 @@ סרגל התקדמות Trickplay הפעל תמונה-בתוך-תמונה - מְהִירוּת \ No newline at end of file diff --git a/player/video/src/main/res/values-ko/strings.xml b/player/video/src/main/res/values-ko/strings.xml index d31eff07c1..81e8113734 100644 --- a/player/video/src/main/res/values-ko/strings.xml +++ b/player/video/src/main/res/values-ko/strings.xml @@ -1,6 +1,5 @@ - 맞춤형 버전 선택 오디오 트랙 선택 자막 트랙 선택 @@ -19,5 +18,4 @@ picture-in-picture 전환 없음 엔딩 스킵 - 속도 \ No newline at end of file diff --git a/player/video/src/main/res/values-nl/strings.xml b/player/video/src/main/res/values-nl/strings.xml index eb9617294f..2f6920a0d6 100644 --- a/player/video/src/main/res/values-nl/strings.xml +++ b/player/video/src/main/res/values-nl/strings.xml @@ -1,6 +1,5 @@ - op maat Kies een versie Selecteer audiotrack Selecteer ondertiteling @@ -18,5 +17,4 @@ Speel pauze Vooruit springen Trickplay - Snelheid \ No newline at end of file diff --git a/player/video/src/main/res/values-pl/strings.xml b/player/video/src/main/res/values-pl/strings.xml index 734d97067d..939043211e 100644 --- a/player/video/src/main/res/values-pl/strings.xml +++ b/player/video/src/main/res/values-pl/strings.xml @@ -1,6 +1,5 @@ - obstalunkowy Wybierz wersję Wybierz ścieżkę audio Wybierz ścieżkę napisów @@ -19,5 +18,4 @@ Wejdź w tryb obrazu w obrazie Brak Pomiń napisy końcowe - Prędkość \ No newline at end of file diff --git a/player/video/src/main/res/values-pt-rBR/strings.xml b/player/video/src/main/res/values-pt-rBR/strings.xml index e3292ea290..4ec61c9b05 100644 --- a/player/video/src/main/res/values-pt-rBR/strings.xml +++ b/player/video/src/main/res/values-pt-rBR/strings.xml @@ -1,6 +1,5 @@ - personalizada Selecione uma versão Selecione uma faixa de áudio Selecione uma legenda @@ -19,5 +18,4 @@ Entrar no picture-in-picture Nenhum Pular créditos - Velocidade \ No newline at end of file diff --git a/player/video/src/main/res/values-pt/strings.xml b/player/video/src/main/res/values-pt/strings.xml index 5a563c772b..eeb511509a 100644 --- a/player/video/src/main/res/values-pt/strings.xml +++ b/player/video/src/main/res/values-pt/strings.xml @@ -1,6 +1,5 @@ - personalizada Selecionar a versão Seleccione a faixa de áudio Seleccione as legendas @@ -18,5 +17,4 @@ Pular introdução Insira imagem em imagem Nenhum - Velocidade \ No newline at end of file diff --git a/player/video/src/main/res/values-ru/strings.xml b/player/video/src/main/res/values-ru/strings.xml index 35f1035765..d281897e03 100644 --- a/player/video/src/main/res/values-ru/strings.xml +++ b/player/video/src/main/res/values-ru/strings.xml @@ -2,7 +2,6 @@ Выбрать субтитры Выбрать скорость воспроизведения - сделанный на заказ Выбрать версию Выбрать аудиодорожку Внешнее @@ -19,5 +18,4 @@ Отключить Картинка в картинке Пропустить титры - Скорость \ No newline at end of file diff --git a/player/video/src/main/res/values-sk/strings.xml b/player/video/src/main/res/values-sk/strings.xml index 13fb4685c5..86e624fab5 100644 --- a/player/video/src/main/res/values-sk/strings.xml +++ b/player/video/src/main/res/values-sk/strings.xml @@ -3,7 +3,6 @@ Vybrať zvukovú stopu Vybrať titulky Vybrať rýchlosť prehrávania - zákazkový Vybrať verziu Externé Zavrieť prehrávač @@ -19,5 +18,4 @@ Zapnúť obraz v obraze Žiadne Preskočiť kredity - Rýchlosť \ No newline at end of file diff --git a/player/video/src/main/res/values-sl/strings.xml b/player/video/src/main/res/values-sl/strings.xml index a5f96e097a..72b604efe1 100644 --- a/player/video/src/main/res/values-sl/strings.xml +++ b/player/video/src/main/res/values-sl/strings.xml @@ -3,7 +3,6 @@ Izberite zvočno sled Izberite podnapise Izberite hitrost predvajanja - po meri Izberite različico Zunanjo Izhod iz predvajalnika @@ -15,5 +14,4 @@ Predvajaj ustavi Vrstica napredka Preskoči naprej - Hitrost \ No newline at end of file diff --git a/player/video/src/main/res/values-sv/strings.xml b/player/video/src/main/res/values-sv/strings.xml index ffbafa15a3..3e9998a133 100644 --- a/player/video/src/main/res/values-sv/strings.xml +++ b/player/video/src/main/res/values-sv/strings.xml @@ -2,7 +2,6 @@ Välj textningsspår Välj uppspelningshastighet - skräddarsydda Välj en version Extern Välj ljudspår @@ -10,5 +9,4 @@ Spola tillbaka Spola framåt Hoppa över intro - hastighet \ No newline at end of file diff --git a/player/video/src/main/res/values-tr/strings.xml b/player/video/src/main/res/values-tr/strings.xml index 1cdf4e5037..e5d31a6651 100644 --- a/player/video/src/main/res/values-tr/strings.xml +++ b/player/video/src/main/res/values-tr/strings.xml @@ -3,8 +3,6 @@ Ses parçasını seç Altyazı parçasını seç Oynatma hızını seç - ısmarlama Bir sürüm seç Hiçbiri - hız \ No newline at end of file diff --git a/player/video/src/main/res/values-uk/strings.xml b/player/video/src/main/res/values-uk/strings.xml index f548d12d07..8b54d3f582 100644 --- a/player/video/src/main/res/values-uk/strings.xml +++ b/player/video/src/main/res/values-uk/strings.xml @@ -3,12 +3,10 @@ Вибрати звукову доріжку Вибрати доріжку субтитрів Вибрати швидкість перегляду - на замовлення Вибрати версію Зовнішнє Відмотка Швидке перемотування Вийти з плеєра Пропустити вступ - швидкість \ No newline at end of file diff --git a/player/video/src/main/res/values-vi/strings.xml b/player/video/src/main/res/values-vi/strings.xml index ef98e3177c..f3061da1e0 100644 --- a/player/video/src/main/res/values-vi/strings.xml +++ b/player/video/src/main/res/values-vi/strings.xml @@ -2,7 +2,6 @@ Chọn dòng phụ đề Chọn tốc độ phát - đặt làm riêng Chọn phiên bản Ngoại Chọn dòng âm thanh @@ -17,5 +16,4 @@ Tiến tới Tua mượt mà Thanh tiến trình - tốc độ \ No newline at end of file diff --git a/player/video/src/main/res/values-zh-rCN/strings.xml b/player/video/src/main/res/values-zh-rCN/strings.xml index c64bbd0e7f..8ed94e7038 100644 --- a/player/video/src/main/res/values-zh-rCN/strings.xml +++ b/player/video/src/main/res/values-zh-rCN/strings.xml @@ -1,6 +1,5 @@ - 定制的 选择版本 选择音轨 选择字幕轨 @@ -19,5 +18,4 @@ 进入画中画 跳过片尾 - 速度 \ No newline at end of file diff --git a/player/video/src/main/res/values-zh-rTW/strings.xml b/player/video/src/main/res/values-zh-rTW/strings.xml index 3ed8911186..44f3e4bb77 100644 --- a/player/video/src/main/res/values-zh-rTW/strings.xml +++ b/player/video/src/main/res/values-zh-rTW/strings.xml @@ -1,6 +1,5 @@ - 定制的 選擇版本 選擇音軌 選擇字幕軌道 @@ -19,5 +18,4 @@ 進度條 跳過片尾 - 速度 \ No newline at end of file diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index 4e988c4b42..3243ff1344 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -2,7 +2,8 @@ Select audio track Select subtitle track Select playback speed - Speed + + Enter custom playback speed Custom "Select a version" External From 35f09f7483b2f66fbaf610536b7b61bece3585a9 Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Thu, 21 Nov 2024 21:39:02 +0000 Subject: [PATCH 05/11] reword a label --- player/video/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index 3243ff1344..7b435c41d9 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ Select subtitle track Select playback speed - Enter custom playback speed + Speed Custom "Select a version" External From dc282b57f8dcedf708f04d1affe5080fa5522ab9 Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Tue, 26 Nov 2024 16:39:49 +0000 Subject: [PATCH 06/11] Use a SeekBar instead of a typed input for custom playback speed selection --- ...SpeedSelectionCustomSpeedDialogFragment.kt | 93 +++++++++++++------ .../dialogs/SpeedSelectionDialogFragment.kt | 2 +- player/video/src/main/res/values/strings.xml | 1 + 3 files changed, 69 insertions(+), 27 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index 7cad6b20ef..59f8c08487 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -2,48 +2,89 @@ package dev.jdtech.jellyfin.dialogs import android.app.Dialog import android.os.Bundle -import android.view.KeyEvent -import android.view.WindowManager -import android.view.inputmethod.EditorInfo +import android.view.Gravity +import android.widget.LinearLayout +import android.widget.SeekBar +import android.widget.TextView import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.google.android.material.textfield.TextInputEditText -import com.google.android.material.textfield.TextInputLayout import dev.jdtech.jellyfin.player.video.R +import java.util.Locale class SpeedSelectionCustomSpeedDialogFragment( - private val speedSelectionDialog: SpeedSelectionDialogFragment + private val speedSelectionDialog: SpeedSelectionDialogFragment, + private val currentSpeed: Float ): DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { activity -> - val textInputLayout = TextInputLayout(activity) - val editText = TextInputEditText(textInputLayout.context) - // Bitwise OR creates the input type for a decimal number. - editText.inputType = android.text.InputType.TYPE_CLASS_NUMBER.or(android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL) - val builtDialog = MaterialAlertDialogBuilder(activity) - .setTitle(getString(R.string.custom_playback_speed)) - .setView(editText) - .create() + val speedText = TextView(activity.baseContext) + speedText.text = createLabel(currentSpeed) + speedText.gravity = Gravity.CENTER + + // Use a SeekBar with a range scaled 100x from the intended playback speed multiplier. + val seekBar = SeekBar(activity.baseContext) + seekBar.min = 25 + seekBar.max = 400 + seekBar.progress = speedToSeekBarValue(currentSpeed) + + val listener = object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged( + seekBar: SeekBar?, + progress: Int, + fromUser: Boolean + ) { + speedText.text = createLabel(seekBarValueToSpeed(seekBar?.progress ?: 100)) + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + // NO-OP + } - editText.setOnEditorActionListener { textView, actionId, keyEvent -> - // Accepting ENTER KeyEvents should provide better support for physical keyboards. - if (actionId == EditorInfo.IME_ACTION_DONE || keyEvent.keyCode == KeyEvent.KEYCODE_ENTER) { - val newSpeed = textView.text.toString().toFloatOrNull() - if (newSpeed != null && newSpeed <= 3f && newSpeed >= 0.25f) { - speedSelectionDialog.setCustomSpeed(newSpeed) - } - builtDialog.dismiss() + override fun onStopTrackingTouch(seekBar: SeekBar?) { + // NO-OP } - true } + seekBar.setOnSeekBarChangeListener(listener) - builtDialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) - builtDialog.setOnShowListener {_ -> editText.requestFocus()} + val container = LinearLayout(activity.baseContext) + container.orientation = LinearLayout.VERTICAL + container.addView(speedText) + container.addView(seekBar) - builtDialog + MaterialAlertDialogBuilder(activity) + .setTitle(getString(R.string.custom_playback_speed)) + .setView(container) + .setPositiveButton(R.string.custom_playback_speed_confirm_button_label) { dialog, _ -> + speedSelectionDialog.setCustomSpeed(seekBarValueToSpeed(seekBar.progress)) + dialog.dismiss() + } + .create() } ?: throw IllegalStateException("Activity cannot be null"); } + + /** + * Scale the integer value from the SeekBar to the associated playback speed multiplier. + * Inverted by [speedToSeekBarValue]. + */ + private fun seekBarValueToSpeed(int: Int): Float { + return int.toFloat() / 100 + } + + /** + * Scale a float playback speed multiplier to the associated progress value for the SeekBar. + * Inverted by [seekBarValueToSpeed]. + */ + private fun speedToSeekBarValue(float: Float): Int { + return (float * 100).toInt() + } + + /** + * Create a formatted string for a label describing the selected playback speed multiplier. + */ + private fun createLabel(float: Float): String { + return String.format(Locale.getDefault(), "%.2f x", float) + } } \ No newline at end of file diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index fc68af21b7..c004d97c3f 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -38,7 +38,7 @@ class SpeedSelectionDialogFragment( ) { dialog, which -> if (speedTexts[which].startsWith(customLabel)) { // Use a secondary dialog to determine the speed to set. - SpeedSelectionCustomSpeedDialogFragment(this) + SpeedSelectionCustomSpeedDialogFragment(this, currentSpeed) .show(activity.supportFragmentManager, "customSpeedSelection") } else { diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index 7b435c41d9..fd52a94474 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Speed Custom + Set "Select a version" External None From 916c5c61424fa037dd41c9fc7ba5160e577c85cd Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Tue, 26 Nov 2024 19:02:33 +0000 Subject: [PATCH 07/11] Switch to a logarithmic scale on the SeekBar, tidy up some string formatting --- ...SpeedSelectionCustomSpeedDialogFragment.kt | 44 +++++++++++-------- .../dialogs/SpeedSelectionDialogFragment.kt | 3 +- player/video/src/main/res/values/strings.xml | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index 59f8c08487..bf401a73bf 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -9,13 +9,25 @@ import android.widget.TextView import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder import dev.jdtech.jellyfin.player.video.R -import java.util.Locale +import kotlin.math.exp +import kotlin.math.ln class SpeedSelectionCustomSpeedDialogFragment( private val speedSelectionDialog: SpeedSelectionDialogFragment, private val currentSpeed: Float ): DialogFragment() { + /** + * Define the key values for the speed selection slide bar. Chosen for the logarithmic scaling. + */ + private object SeekBarConstants { + private const val MAX_SPEED = 4.01f + private const val MIN_SPEED = 1/4f + const val NORMALIZATION = 1000 + val MAX = (NORMALIZATION * ln(MAX_SPEED)).toInt() + val MIN = (NORMALIZATION * ln(MIN_SPEED)).toInt() + } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { activity -> @@ -24,28 +36,20 @@ class SpeedSelectionCustomSpeedDialogFragment( speedText.text = createLabel(currentSpeed) speedText.gravity = Gravity.CENTER - // Use a SeekBar with a range scaled 100x from the intended playback speed multiplier. val seekBar = SeekBar(activity.baseContext) - seekBar.min = 25 - seekBar.max = 400 + seekBar.min = SeekBarConstants.MIN + seekBar.max = SeekBarConstants.MAX seekBar.progress = speedToSeekBarValue(currentSpeed) val listener = object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged( - seekBar: SeekBar?, - progress: Int, - fromUser: Boolean - ) { + + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { speedText.text = createLabel(seekBarValueToSpeed(seekBar?.progress ?: 100)) } - override fun onStartTrackingTouch(seekBar: SeekBar?) { - // NO-OP - } + override fun onStartTrackingTouch(seekBar: SeekBar?) {} // NO-OP - override fun onStopTrackingTouch(seekBar: SeekBar?) { - // NO-OP - } + override fun onStopTrackingTouch(seekBar: SeekBar?) {} // NO-OP } seekBar.setOnSeekBarChangeListener(listener) @@ -67,24 +71,28 @@ class SpeedSelectionCustomSpeedDialogFragment( /** * Scale the integer value from the SeekBar to the associated playback speed multiplier. + * Uses a logarithmic scale so that X speed and 1/X speed are equidistant from 1x speed. + * Discards precision beyond 2 decimal places. * Inverted by [speedToSeekBarValue]. */ private fun seekBarValueToSpeed(int: Int): Float { - return int.toFloat() / 100 + val preciseSpeed = exp((int.toFloat()/SeekBarConstants.NORMALIZATION)) + return ((100 * preciseSpeed).toInt()/ 100f) } /** * Scale a float playback speed multiplier to the associated progress value for the SeekBar. + * Uses a logarithmic scale so that X speed and 1/X speed are equidistant from 1x speed. * Inverted by [seekBarValueToSpeed]. */ private fun speedToSeekBarValue(float: Float): Int { - return (float * 100).toInt() + return (SeekBarConstants.NORMALIZATION * ln(float)).toInt() } /** * Create a formatted string for a label describing the selected playback speed multiplier. */ private fun createLabel(float: Float): String { - return String.format(Locale.getDefault(), "%.2f x", float) + return "%.2fx".format(float) } } \ No newline at end of file diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index c004d97c3f..e099aeb812 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder import dev.jdtech.jellyfin.player.video.R import dev.jdtech.jellyfin.viewmodels.PlayerActivityViewModel +import java.util.Locale class SpeedSelectionDialogFragment( private val viewModel: PlayerActivityViewModel, @@ -22,7 +23,7 @@ class SpeedSelectionDialogFragment( val speedNumbers = mutableListOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) if (currentSpeed !in speedNumbers) { - speedTexts.add(customLabel + ": " + currentSpeed + "x") + speedTexts.add("%s: %.2fx".format(Locale.getDefault(), customLabel, currentSpeed)) speedNumbers.add(currentSpeed) } else { diff --git a/player/video/src/main/res/values/strings.xml b/player/video/src/main/res/values/strings.xml index fd52a94474..20a645dcd9 100644 --- a/player/video/src/main/res/values/strings.xml +++ b/player/video/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ Select subtitle track Select playback speed - Speed + Playback speed Custom Set "Select a version" From ddd78bbb2d2f761848231ecad83ee5165e32881d Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Tue, 26 Nov 2024 19:13:17 +0000 Subject: [PATCH 08/11] Support localization of existing playback speed labels. Useful for places that swap uses for '.' and ',' compared to English representation. --- .../dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index e099aeb812..5b1e01d9ae 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -19,8 +19,8 @@ class SpeedSelectionDialogFragment( val customLabel = getString(R.string.custom_playback_speed_label) val currentSpeed = viewModel.playbackSpeed - val speedTexts = mutableListOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x") val speedNumbers = mutableListOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) + val speedTexts = speedNumbers.map { speed -> "%.2fx".format(speed) }.toMutableList() if (currentSpeed !in speedNumbers) { speedTexts.add("%s: %.2fx".format(Locale.getDefault(), customLabel, currentSpeed)) From 4d4bd29443ff1e6195184433af3aeb8d1c53f13e Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Tue, 26 Nov 2024 19:28:03 +0000 Subject: [PATCH 09/11] fix linting issues --- .../SpeedSelectionCustomSpeedDialogFragment.kt | 15 +++++++-------- .../dialogs/SpeedSelectionDialogFragment.kt | 6 ++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index bf401a73bf..912a8dffff 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -14,22 +14,21 @@ import kotlin.math.ln class SpeedSelectionCustomSpeedDialogFragment( private val speedSelectionDialog: SpeedSelectionDialogFragment, - private val currentSpeed: Float -): DialogFragment() { + private val currentSpeed: Float, +) : DialogFragment() { /** * Define the key values for the speed selection slide bar. Chosen for the logarithmic scaling. */ private object SeekBarConstants { private const val MAX_SPEED = 4.01f - private const val MIN_SPEED = 1/4f + private const val MIN_SPEED = 1 / 4f const val NORMALIZATION = 1000 val MAX = (NORMALIZATION * ln(MAX_SPEED)).toInt() val MIN = (NORMALIZATION * ln(MIN_SPEED)).toInt() } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - return activity?.let { activity -> val speedText = TextView(activity.baseContext) @@ -66,7 +65,7 @@ class SpeedSelectionCustomSpeedDialogFragment( dialog.dismiss() } .create() - } ?: throw IllegalStateException("Activity cannot be null"); + } ?: throw IllegalStateException("Activity cannot be null") } /** @@ -76,8 +75,8 @@ class SpeedSelectionCustomSpeedDialogFragment( * Inverted by [speedToSeekBarValue]. */ private fun seekBarValueToSpeed(int: Int): Float { - val preciseSpeed = exp((int.toFloat()/SeekBarConstants.NORMALIZATION)) - return ((100 * preciseSpeed).toInt()/ 100f) + val preciseSpeed = exp((int.toFloat() / SeekBarConstants.NORMALIZATION)) + return ((100 * preciseSpeed).toInt() / 100f) } /** @@ -95,4 +94,4 @@ class SpeedSelectionCustomSpeedDialogFragment( private fun createLabel(float: Float): String { return "%.2fx".format(float) } -} \ No newline at end of file +} diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index 5b1e01d9ae..5c43c7f967 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -25,8 +25,7 @@ class SpeedSelectionDialogFragment( if (currentSpeed !in speedNumbers) { speedTexts.add("%s: %.2fx".format(Locale.getDefault(), customLabel, currentSpeed)) speedNumbers.add(currentSpeed) - } - else { + } else { speedTexts.add(customLabel) } @@ -41,8 +40,7 @@ class SpeedSelectionDialogFragment( // Use a secondary dialog to determine the speed to set. SpeedSelectionCustomSpeedDialogFragment(this, currentSpeed) .show(activity.supportFragmentManager, "customSpeedSelection") - } - else { + } else { setCustomSpeed(speedNumbers[which]) } dialog.dismiss() From ff32fc18a169713b3f474e2e900d93401358f04d Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Tue, 26 Nov 2024 21:37:45 +0000 Subject: [PATCH 10/11] Use correct replacement value in case of a null SeekBar, use string attributes consistently. --- .../dialogs/SpeedSelectionCustomSpeedDialogFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index 912a8dffff..2c90d809c8 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -43,7 +43,7 @@ class SpeedSelectionCustomSpeedDialogFragment( val listener = object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - speedText.text = createLabel(seekBarValueToSpeed(seekBar?.progress ?: 100)) + speedText.text = createLabel(seekBarValueToSpeed(seekBar?.progress ?: 0)) } override fun onStartTrackingTouch(seekBar: SeekBar?) {} // NO-OP @@ -58,7 +58,7 @@ class SpeedSelectionCustomSpeedDialogFragment( container.addView(seekBar) MaterialAlertDialogBuilder(activity) - .setTitle(getString(R.string.custom_playback_speed)) + .setTitle(R.string.custom_playback_speed) .setView(container) .setPositiveButton(R.string.custom_playback_speed_confirm_button_label) { dialog, _ -> speedSelectionDialog.setCustomSpeed(seekBarValueToSpeed(seekBar.progress)) From 92cd1713cda150a552f0d9901bea10226da2b216 Mon Sep 17 00:00:00 2001 From: Ryan Foulds Date: Fri, 29 Nov 2024 23:21:17 +0000 Subject: [PATCH 11/11] remove trailing zeroes from playback speed labels, tweak custom speed slider precision --- .../dialogs/SpeedSelectionCustomSpeedDialogFragment.kt | 2 +- .../jellyfin/dialogs/SpeedSelectionDialogFragment.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt index 2c90d809c8..9288549f57 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionCustomSpeedDialogFragment.kt @@ -23,7 +23,7 @@ class SpeedSelectionCustomSpeedDialogFragment( private object SeekBarConstants { private const val MAX_SPEED = 4.01f private const val MIN_SPEED = 1 / 4f - const val NORMALIZATION = 1000 + const val NORMALIZATION = 2000 val MAX = (NORMALIZATION * ln(MAX_SPEED)).toInt() val MIN = (NORMALIZATION * ln(MIN_SPEED)).toInt() } diff --git a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt index 5c43c7f967..8817b41463 100644 --- a/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt +++ b/player/video/src/main/java/dev/jdtech/jellyfin/dialogs/SpeedSelectionDialogFragment.kt @@ -1,6 +1,7 @@ package dev.jdtech.jellyfin.dialogs import android.app.Dialog +import android.icu.text.DecimalFormat import android.os.Bundle import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat @@ -9,21 +10,24 @@ import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder import dev.jdtech.jellyfin.player.video.R import dev.jdtech.jellyfin.viewmodels.PlayerActivityViewModel -import java.util.Locale class SpeedSelectionDialogFragment( private val viewModel: PlayerActivityViewModel, ) : DialogFragment() { + private companion object { + val PLAYBACK_SPEED_FORMAT = DecimalFormat("0.##x") + } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val customLabel = getString(R.string.custom_playback_speed_label) val currentSpeed = viewModel.playbackSpeed val speedNumbers = mutableListOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) - val speedTexts = speedNumbers.map { speed -> "%.2fx".format(speed) }.toMutableList() + val speedTexts = speedNumbers.map(PLAYBACK_SPEED_FORMAT::format).toMutableList() if (currentSpeed !in speedNumbers) { - speedTexts.add("%s: %.2fx".format(Locale.getDefault(), customLabel, currentSpeed)) + speedTexts.add("$customLabel: ${PLAYBACK_SPEED_FORMAT.format(currentSpeed)}") speedNumbers.add(currentSpeed) } else { speedTexts.add(customLabel)