Merge "Fix the problem that the ToggleSubscriptionDialogActivity appears twice when switch changed." into sc-dev

This commit is contained in:
Stanley Wang
2021-06-29 09:48:54 +00:00
committed by Android (Google) Code Review
3 changed files with 14 additions and 16 deletions

View File

@@ -54,7 +54,7 @@ public class AutoBrightnessDetailPreferenceController extends
SettingsMainSwitchPreference pref = (SettingsMainSwitchPreference) screen.findPreference( SettingsMainSwitchPreference pref = (SettingsMainSwitchPreference) screen.findPreference(
getPreferenceKey()); getPreferenceKey());
pref.addOnSwitchChangeListener(this); pref.addOnSwitchChangeListener(this);
pref.updateStatus(isChecked()); pref.setChecked(isChecked());
} }
@Override @Override

View File

@@ -86,9 +86,12 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced(); mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced();
} }
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar); mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
initMainSwitchBar();
if (mIsVisible) { if (mIsVisible) {
mMainSwitchBar.show(); mMainSwitchBar.show();
updateStatus(isChecked()); if (mMainSwitchBar.isChecked() != isChecked()) {
setChecked(isChecked());
}
registerListenerToSwitchBar(); registerListenerToSwitchBar();
} else { } else {
mMainSwitchBar.hide(); mMainSwitchBar.hide();
@@ -144,18 +147,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
super.setChecked(isChecked); super.setChecked(isChecked);
} }
/**
* Update the switch status of preference
*/
public void updateStatus(boolean checked) {
setChecked(checked);
if (mMainSwitchBar != null) {
mMainSwitchBar.setTitle(mTitle);
mMainSwitchBar.setDisabledByAdmin(mEnforcedAdmin);
mMainSwitchBar.show();
}
}
/** /**
* Show the MainSwitchBar * Show the MainSwitchBar
*/ */
@@ -251,6 +242,13 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
} }
} }
private void initMainSwitchBar() {
if (mMainSwitchBar != null) {
mMainSwitchBar.setTitle(mTitle);
mMainSwitchBar.setDisabledByAdmin(mEnforcedAdmin);
}
}
private void registerListenerToSwitchBar() { private void registerListenerToSwitchBar() {
for (OnBeforeCheckedChangeListener listener : mBeforeCheckedChangeListeners) { for (OnBeforeCheckedChangeListener listener : mBeforeCheckedChangeListeners) {
mMainSwitchBar.setOnBeforeCheckedChangeListener(listener); mMainSwitchBar.setOnBeforeCheckedChangeListener(listener);

View File

@@ -59,8 +59,8 @@ public class SettingsMainSwitchPreferenceTest {
} }
@Test @Test
public void updateStatus_isRestricted_restrictIconShouldDisplay() { public void onBindViewHolder_isRestricted_restrictIconShouldDisplay() {
mPreference.updateStatus(true); mPreference.onBindViewHolder(mHolder);
final SettingsMainSwitchBar switchBar = mPreference.getSwitchBar(); final SettingsMainSwitchBar switchBar = mPreference.getSwitchBar();
final ImageView restrictedIcon = switchBar.findViewById( final ImageView restrictedIcon = switchBar.findViewById(