Improve volume slider

In the Settings, the Preference#onBindViewHolder will be invoked
3 times when a preference is getting highlighted. This caused that a
disabled volume slider becomes enabled after getting highlighted.

This change is to optimize the init method of VolumeSeekbarPreference
to speed up the initial process and fix the unexpected behavior.

Bug: 275352565
Test: manual test and robotest pass
Change-Id: I77f28386f6d6e4a45297f1ca7bcbaf16ed6136a4
This commit is contained in:
Mill Chen
2023-07-07 20:52:13 +08:00
parent b3b27451a3
commit c69899ccef
2 changed files with 18 additions and 4 deletions

View File

@@ -131,6 +131,11 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
protected void init() {
if (mSeekBar == null) return;
// It's unnecessary to set up relevant volumizer configuration if preference is disabled.
if (!isEnabled()) {
mSeekBar.setEnabled(false);
return;
}
final SeekBarVolumizer.Callback sbvc = new SeekBarVolumizer.Callback() {
@Override
public void onSampleStarting(SeekBarVolumizer sbv) {
@@ -179,10 +184,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
if (mListener != null) {
mListener.onUpdateMuteState();
}
if (!isEnabled()) {
mSeekBar.setEnabled(false);
mVolumizer.stop();
}
}
protected void updateIconView() {