Merge "Fix the problem that the ToggleSubscriptionDialogActivity appears twice when switch changed." into sc-dev
This commit is contained in:
@@ -54,7 +54,7 @@ public class AutoBrightnessDetailPreferenceController extends
|
||||
SettingsMainSwitchPreference pref = (SettingsMainSwitchPreference) screen.findPreference(
|
||||
getPreferenceKey());
|
||||
pref.addOnSwitchChangeListener(this);
|
||||
pref.updateStatus(isChecked());
|
||||
pref.setChecked(isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -86,9 +86,12 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||
mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced();
|
||||
}
|
||||
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
|
||||
initMainSwitchBar();
|
||||
if (mIsVisible) {
|
||||
mMainSwitchBar.show();
|
||||
updateStatus(isChecked());
|
||||
if (mMainSwitchBar.isChecked() != isChecked()) {
|
||||
setChecked(isChecked());
|
||||
}
|
||||
registerListenerToSwitchBar();
|
||||
} else {
|
||||
mMainSwitchBar.hide();
|
||||
@@ -144,18 +147,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
|
||||
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
|
||||
*/
|
||||
@@ -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() {
|
||||
for (OnBeforeCheckedChangeListener listener : mBeforeCheckedChangeListeners) {
|
||||
mMainSwitchBar.setOnBeforeCheckedChangeListener(listener);
|
||||
|
@@ -59,8 +59,8 @@ public class SettingsMainSwitchPreferenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateStatus_isRestricted_restrictIconShouldDisplay() {
|
||||
mPreference.updateStatus(true);
|
||||
public void onBindViewHolder_isRestricted_restrictIconShouldDisplay() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
final SettingsMainSwitchBar switchBar = mPreference.getSwitchBar();
|
||||
final ImageView restrictedIcon = switchBar.findViewById(
|
||||
|
Reference in New Issue
Block a user