Create a PagedList which loads data from the provided data source on a background thread, posting updates to the main thread. @param dataSource DataSource providing data to the PagedList @param notifyExecutor Thread that will use and consume data from the PagedList. Generally
(@NonNull DataSource<K, T> dataSource,
@NonNull Executor notifyExecutor,
@NonNull Executor fetchExecutor,
@Nullable BoundaryCallback<T> boundaryCallback,
@NonNull Config config,
@Nullable K key)
| 195 | * @return Newly created PagedList, which will page in data from the DataSource as needed. |
| 196 | */ |
| 197 | @NonNull |
| 198 | @SuppressWarnings("WeakerAccess") /* synthetic access */ |
| 199 | static <K, T> PagedList<T> create(@NonNull DataSource<K, T> dataSource, |
| 200 | @NonNull Executor notifyExecutor, |
| 201 | @NonNull Executor fetchExecutor, |
| 202 | @Nullable BoundaryCallback<T> boundaryCallback, |
| 203 | @NonNull Config config, |
| 204 | @Nullable K key) { |
| 205 | if (dataSource.isContiguous() || !config.enablePlaceholders) { |
| 206 | int lastLoad = ContiguousPagedList.LAST_LOAD_UNSPECIFIED; |
| 207 | if (!dataSource.isContiguous()) { |
| 208 | //noinspection unchecked |
| 209 | dataSource = (DataSource<K, T>) ((PositionalDataSource<T>) dataSource) |
| 210 | .wrapAsContiguousWithoutPlaceholders(); |
| 211 | if (key != null) { |
| 212 | lastLoad = (Integer) key; |
| 213 | } |
| 214 | } |
| 215 | ContiguousDataSource<K, T> contigDataSource = (ContiguousDataSource<K, T>) dataSource; |
| 216 | return new ContiguousPagedList<>(contigDataSource, |
| 217 | notifyExecutor, |
| 218 | fetchExecutor, |
| 219 | boundaryCallback, |
| 220 | config, |
| 221 | key, |
| 222 | lastLoad); |
| 223 | } else { |
| 224 | return new TiledPagedList<>((PositionalDataSource<T>) dataSource, |
| 225 | notifyExecutor, |
| 226 | fetchExecutor, |
| 227 | boundaryCallback, |
| 228 | config, |
| 229 | (key != null) ? (Integer) key : 0); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Builder class for PagedList. |
no test coverage detected