Simplify InlineSwitchPayloads and generalize get/set method
InlineSwitchPayload now assumes that all switches will be stored as 1 or 0, which simplifies the code. Moves Availability into ResultPayload, so that custom payloads can be created to set/get values which are more complicated than stotring ints (like bluetooth or DnD), and give more expressive reasons when unavailable. Bug: 62022517 Test: make RunSettingsRoboTests Change-Id: I87e6fc041bfd398e7daf6e6e479d502930d36f0f
This commit is contained in:
@@ -52,13 +52,14 @@ public class InlineSwitchViewHolder extends SearchViewHolder {
|
||||
return;
|
||||
}
|
||||
final InlineSwitchPayload payload = (InlineSwitchPayload) result.payload;
|
||||
switchView.setChecked(payload.getSwitchValue(mContext));
|
||||
switchView.setChecked(payload.getValue(mContext) == InlineSwitchPayload.TRUE);
|
||||
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
final Pair<Integer, Object> value = Pair.create(
|
||||
MetricsEvent.FIELD_SETTINGS_SEARCH_INLINE_RESULT_VALUE, isChecked
|
||||
? 1L : 0L);
|
||||
fragment.onSearchResultClicked(this, payload.settingsUri, value);
|
||||
payload.setSwitchValue(mContext, isChecked);
|
||||
fragment.onSearchResultClicked(this, payload.mSettingKey, value);
|
||||
int newValue = isChecked ? InlineSwitchPayload.TRUE : InlineSwitchPayload.FALSE;
|
||||
payload.setValue(mContext, newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user