From 1e5bd4d6fcb89a957bbbefe21fcf7252283009c2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 25 Aug 2022 22:39:55 +0200 Subject: [PATCH 1/3] remove testing code --- app/src/main/java/com/github/libretube/MyApp.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/MyApp.kt b/app/src/main/java/com/github/libretube/MyApp.kt index d267bc226..8f214834d 100644 --- a/app/src/main/java/com/github/libretube/MyApp.kt +++ b/app/src/main/java/com/github/libretube/MyApp.kt @@ -59,8 +59,6 @@ class MyApp : Application() { existingPeriodicWorkPolicy = ExistingPeriodicWorkPolicy.KEEP ) - NotificationHelper(this).checkForNewStreams() - /** * Handler for uncaught exceptions */ From 207fe64b58de23699430553b3d7b44185dd4f2cc Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 25 Aug 2022 22:48:12 +0200 Subject: [PATCH 2/3] add continous playback speed slider --- .../libretube/fragments/PlayerFragment.kt | 17 +++++++++-------- .../main/res/layout/dialog_playback_speed.xml | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/layout/dialog_playback_speed.xml diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 8de78a041..4bc39503d 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -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.DialogPlaybackSpeedBinding 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 = DialogPlaybackSpeedBinding.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() } diff --git a/app/src/main/res/layout/dialog_playback_speed.xml b/app/src/main/res/layout/dialog_playback_speed.xml new file mode 100644 index 000000000..7e190af0f --- /dev/null +++ b/app/src/main/res/layout/dialog_playback_speed.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file From fbc6a14c58ffb92f6b613ad4bf36e11d7b2f37cf Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 25 Aug 2022 23:05:04 +0200 Subject: [PATCH 3/3] add custom slider preference --- .../libretube/extensions/SliderPreference.kt | 44 +++++++++++++++++++ .../libretube/fragments/PlayerFragment.kt | 10 ++--- .../libretube/preferences/PreferenceHelper.kt | 2 +- ...g_playback_speed.xml => dialog_slider.xml} | 0 app/src/main/res/values/array.xml | 23 ---------- app/src/main/res/xml/player_settings.xml | 14 ++---- 6 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/extensions/SliderPreference.kt rename app/src/main/res/layout/{dialog_playback_speed.xml => dialog_slider.xml} (100%) diff --git a/app/src/main/java/com/github/libretube/extensions/SliderPreference.kt b/app/src/main/java/com/github/libretube/extensions/SliderPreference.kt new file mode 100644 index 000000000..0ff432fc0 --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/SliderPreference.kt @@ -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() + } +} diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 4bc39503d..16dd19e3b 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -43,7 +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.DialogPlaybackSpeedBinding +import com.github.libretube.databinding.DialogSliderBinding import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.FragmentPlayerBinding @@ -510,7 +510,7 @@ class PlayerFragment : BaseFragment() { } override fun onPlaybackSpeedClicked() { - val playbackSpeedBinding = DialogPlaybackSpeedBinding.inflate(layoutInflater) + val playbackSpeedBinding = DialogSliderBinding.inflate(layoutInflater) playbackSpeedBinding.slider.value = exoPlayer.playbackParameters.speed // change playback speed dialog MaterialAlertDialogBuilder(requireContext()) @@ -599,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 diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt index 63ca4b25f..2bdbc6af0 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt @@ -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 { diff --git a/app/src/main/res/layout/dialog_playback_speed.xml b/app/src/main/res/layout/dialog_slider.xml similarity index 100% rename from app/src/main/res/layout/dialog_playback_speed.xml rename to app/src/main/res/layout/dialog_slider.xml diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 9efa17ea4..634032d6c 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -641,29 +641,6 @@ .mkv - - 0.25x - 0.5x - 0.75x - 1x - 1.25x - 1.5x - 2x - 3x - 4x - - - 0.25 - 0.5 - 0.75 - 1.0 - 1.25 - 1.5 - 2.0 - 3.0 - 4.0 - - @string/downloads_directory @string/music_directory diff --git a/app/src/main/res/xml/player_settings.xml b/app/src/main/res/xml/player_settings.xml index f7f9439dd..64fa9f40f 100644 --- a/app/src/main/res/xml/player_settings.xml +++ b/app/src/main/res/xml/player_settings.xml @@ -44,14 +44,11 @@ - + app:title="@string/playback_speed" /> - + app:title="@string/playback_speed" />