Merge pull request #8066 from TacoTheDank/simpleSeekbarChange

Create stub implementation for OnSeekBarChangeListener
This commit is contained in:
litetex 2022-03-19 14:37:10 +01:00 committed by GitHub
commit 57231382a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 61 deletions

View File

@ -61,6 +61,7 @@ import org.schabi.newpipe.util.FilenameUtils;
import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.SecondaryStreamHelper; import org.schabi.newpipe.util.SecondaryStreamHelper;
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
import org.schabi.newpipe.util.StreamItemAdapter; import org.schabi.newpipe.util.StreamItemAdapter;
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper; import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
@ -321,21 +322,15 @@ public class DownloadDialog extends DialogFragment
final int threads = prefs.getInt(getString(R.string.default_download_threads), 3); final int threads = prefs.getInt(getString(R.string.default_download_threads), 3);
dialogBinding.threadsCount.setText(String.valueOf(threads)); dialogBinding.threadsCount.setText(String.valueOf(threads));
dialogBinding.threads.setProgress(threads - 1); dialogBinding.threads.setProgress(threads - 1);
dialogBinding.threads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { dialogBinding.threads.setOnSeekBarChangeListener(new SimpleOnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(final SeekBar seekbar, final int progress, public void onProgressChanged(@NonNull final SeekBar seekbar, final int progress,
final boolean fromUser) { final boolean fromUser) {
final int newProgress = progress + 1; final int newProgress = progress + 1;
prefs.edit().putInt(getString(R.string.default_download_threads), newProgress) prefs.edit().putInt(getString(R.string.default_download_threads), newProgress)
.apply(); .apply();
dialogBinding.threadsCount.setText(String.valueOf(newProgress)); dialogBinding.threadsCount.setText(String.valueOf(newProgress));
} }
@Override
public void onStartTrackingTouch(final SeekBar p1) { }
@Override
public void onStopTrackingTouch(final SeekBar p1) { }
}); });
fetchStreamsSize(); fetchStreamsSize();

View File

@ -20,6 +20,7 @@ import androidx.fragment.app.DialogFragment;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
import org.schabi.newpipe.util.SliderStrategy; import org.schabi.newpipe.util.SliderStrategy;
public class PlaybackParameterDialog extends DialogFragment { public class PlaybackParameterDialog extends DialogFragment {
@ -495,10 +496,10 @@ public class PlaybackParameterDialog extends DialogFragment {
// Sliders // Sliders
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
private SeekBar.OnSeekBarChangeListener getOnTempoChangedListener() { private SimpleOnSeekBarChangeListener getOnTempoChangedListener() {
return new SeekBar.OnSeekBarChangeListener() { return new SimpleOnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(final SeekBar seekBar, final int progress, public void onProgressChanged(@NonNull final SeekBar seekBar, final int progress,
final boolean fromUser) { final boolean fromUser) {
final double currentTempo = strategy.valueOf(progress); final double currentTempo = strategy.valueOf(progress);
if (fromUser) { if (fromUser) {
@ -506,23 +507,13 @@ public class PlaybackParameterDialog extends DialogFragment {
setCurrentPlaybackParameters(); setCurrentPlaybackParameters();
} }
} }
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
}; };
} }
private SeekBar.OnSeekBarChangeListener getOnPitchChangedListener() { private SimpleOnSeekBarChangeListener getOnPitchChangedListener() {
return new SeekBar.OnSeekBarChangeListener() { return new SimpleOnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(final SeekBar seekBar, final int progress, public void onProgressChanged(@NonNull final SeekBar seekBar, final int progress,
final boolean fromUser) { final boolean fromUser) {
final double currentPitch = strategy.valueOf(progress); final double currentPitch = strategy.valueOf(progress);
if (fromUser) { // this change is first in chain if (fromUser) { // this change is first in chain
@ -530,23 +521,13 @@ public class PlaybackParameterDialog extends DialogFragment {
setCurrentPlaybackParameters(); setCurrentPlaybackParameters();
} }
} }
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
}; };
} }
private SeekBar.OnSeekBarChangeListener getOnSemitoneChangedListener() { private SimpleOnSeekBarChangeListener getOnSemitoneChangedListener() {
return new SeekBar.OnSeekBarChangeListener() { return new SimpleOnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(final SeekBar seekBar, final int progress, public void onProgressChanged(@NonNull final SeekBar seekBar, final int progress,
final boolean fromUser) { final boolean fromUser) {
// semitone slider supplies values 0 to 24, subtraction by 12 is required // semitone slider supplies values 0 to 24, subtraction by 12 is required
final int currentSemitones = progress - 12; final int currentSemitones = progress - 12;
@ -557,16 +538,6 @@ public class PlaybackParameterDialog extends DialogFragment {
setCurrentPlaybackParameters(); setCurrentPlaybackParameters();
} }
} }
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
// Do Nothing.
}
}; };
} }

View File

@ -0,0 +1,12 @@
package org.schabi.newpipe.util
import android.widget.SeekBar
/**
* Why the hell didn't they make a stub implementation for this?
*/
abstract class SimpleOnSeekBarChangeListener : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {}
override fun onStartTrackingTouch(seekBar: SeekBar) {}
override fun onStopTrackingTouch(seekBar: SeekBar) {}
}

View File

@ -1,11 +1,11 @@
package org.schabi.newpipe.views.player package org.schabi.newpipe.views.player
import android.animation.Animator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.animation.addListener
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.databinding.PlayerFastSeekSecondsViewBinding import org.schabi.newpipe.databinding.PlayerFastSeekSecondsViewBinding
import org.schabi.newpipe.util.DeviceUtils import org.schabi.newpipe.util.DeviceUtils
@ -163,19 +163,10 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
setFloatValues(0f, 1f) setFloatValues(0f, 1f)
addUpdateListener { update(it.animatedValue as Float) } addUpdateListener { update(it.animatedValue as Float) }
addListener(object : AnimatorListener { addListener(
override fun onAnimationStart(animation: Animator?) { onStart = { start() },
start() onEnd = { end() }
} )
override fun onAnimationEnd(animation: Animator?) {
end()
}
override fun onAnimationCancel(animation: Animator?) = Unit
override fun onAnimationRepeat(animation: Animator?) = Unit
})
} }
} }
} }