SectionedItemTemplate.Builder
@ExperimentalCarApi
public final class SectionedItemTemplate.Builder
A builder that constructs SectionedItemTemplate instances.
Upon building, this class validates the following:
- The template is not both loading and populated with sections
- Only
RowSectionand/orGridSectionare added as sections
Summary
Public constructors |
|---|
Builder()Create a new |
Builder(@NonNull SectionedItemTemplate template)Create a new |
Public methods |
|
|---|---|
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueAdds a single |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueAdds a single |
@NonNull SectionedItemTemplate |
build()Constructs a new |
@NonNull SectionedItemTemplate.Builder |
Removes all actions in this template. |
@NonNull SectionedItemTemplate.Builder |
Removes all sections from this template. |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSets the actions that show up alongside the sections of this template (as opposed to the actions in the header), overwriting any other previously set actions from |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueThis method is deprecated. use |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSets how this list can be indexed alphabetically. |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSets or clears the optional header for this template. |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSets whether or not this template is in a loading state. |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSet how to handle a user's scroll position when this template is used as a refresh of another |
@NonNull SectionedItemTemplate.Builder |
@CanIgnoreReturnValueSets the sections in this template, overwriting any other previously set sections. |
Public constructors
Builder
public Builder(@NonNull SectionedItemTemplate template)
Create a new SectionedItemTemplate builder, copying the values from an existing instance.
Public methods
addAction
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder addAction(@NonNull Action action)
Adds a single Action to this template, appending to the existing list of actions. All actions must conform to the ACTIONS_CONSTRAINTS_FAB constraints.
addSection
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder addSection(@NonNull Section<Object> section)
Adds a single Section to this template, appending to the existing list of sections. Only sections listed in Builder can be added.
| See also | |
|---|---|
SectionedItemTemplate.Builder |
for a list of allowed section types |
build
public @NonNull SectionedItemTemplate build()
Constructs a new SectionedItemTemplate from the current state of this builder, throwing exceptions for any invalid state.
| See also | |
|---|---|
SectionedItemTemplate.Builder |
for the list of validation logic |
clearActions
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder clearActions()
Removes all actions in this template.
clearSections
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder clearSections()
Removes all sections from this template.
setActions
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setActions(@NonNull List<Action> actions)
Sets the actions that show up alongside the sections of this template (as opposed to the actions in the header), overwriting any other previously set actions from addAction or setActions. All actions must conform to the ACTIONS_CONSTRAINTS_FAB constraints.
setAlphabeticalIndexingAllowed
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.BuildersetAlphabeticalIndexingAllowed(boolean alphabeticalIndexingAllowed)
Sets whether this list can be indexed alphabetically, by item title. By default, this is false.
"Indexing" refers to the process of examining list contents (e.g. item titles) to sort, partition, or filter a list. Indexing is generally used for features called "Accelerators", which allow a user to quickly find a particular Item in a long list.
For example, a media app may, by default, show a user's playlists sorted by date created. If the app provides these playlists via the SectionedItemTemplate and enables isAlphabeticalIndexingAllowed, the user will be able to jump to their playlists that start with the letter "H". When this happens, the list is reconstructed and sorted alphabetically, then shown to the user, jumping down to the letter "H".
Individual items may be excluded from the list by setting their #isIndexable field to false.
setAlphabeticalIndexingStrategy
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setAlphabeticalIndexingStrategy(int alphabeticalIndexingStrategy)
Sets how this list can be indexed alphabetically. By default, this is ALPHABETICAL_INDEXING_DISABLED.
"Indexing" refers to the process of examining list contents (e.g. item titles) to sort, partition, or filter a list. Indexing is generally used for features called "Accelerators", which allow a user to quickly find a particular Item in a long list.
For example, a media app may, by default, provide a user's playlists sorted by date created in addSection. If setAlphabeticalIndexingStrategy is set to a non-disabled value, the user will be able to jump to their playlists that start with the letter "H". When this happens, the list is reconstructed and sorted alphabetically, then shown to the user, jumping down to the letter "H".
Individual items may be excluded from the reconstructed list by setting their #isIndexable field to false.
setHeader
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setHeader(@Nullable Header header)
Sets or clears the optional header for this template.
setLoading
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setLoading(boolean isLoading)
Sets whether or not this template is in a loading state. If passed true, sections cannot be added to the template. By default, this is false.
setScrollStatePersistenceStrategy
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setScrollStatePersistenceStrategy(int scrollStatePersistenceStrategy)
Set how to handle a user's scroll position when this template is used as a refresh of another SectionedItemTemplate.
For example, if a user is currently scrolled down to item 10 in an existing SectionedItemTemplate, setting this field to SCROLL_STATE_PRESERVE_INDEX would cause the user to be shown item 10 from this template. Alternatively, SCROLL_STATE_RESET_TO_TOP would cause the user to be reset to the top of this template.
By default, this is set to SCROLL_STATE_RESET_TO_TOP.
setSections
@CanIgnoreReturnValue
public @NonNull SectionedItemTemplate.Builder setSections(@NonNull List<Section<Object>> sections)
Sets the sections in this template, overwriting any other previously set sections. Only sections listed in Builder can be added.
| See also | |
|---|---|
SectionedItemTemplate.Builder |
for a list of allowed section types |