public abstract class

TiledDataSource<T>

extends PositionalDataSource<java.lang.Object>

 java.lang.Object

androidx.paging.DataSource<java.lang.Integer, java.lang.Object>

androidx.paging.PositionalDataSource<java.lang.Object>

↳androidx.paging.TiledDataSource<T>

Summary

Constructors
publicTiledDataSource()

Methods
public abstract intcountItems()

public abstract voidloadInitial(PositionalDataSource.LoadInitialParams params, PositionalDataSource.LoadInitialCallback<java.lang.Object> callback)

Load initial list data.

public abstract java.util.List<java.lang.Object>loadRange(int startPosition, int count)

public abstract voidloadRange(PositionalDataSource.LoadRangeParams params, PositionalDataSource.LoadRangeCallback<java.lang.Object> callback)

Called to load a range of data from the DataSource.

from PositionalDataSource<T>computeInitialLoadPosition, computeInitialLoadSize, map, mapByPage
from DataSource<Key, Value>addInvalidatedCallback, invalidate, isInvalid, map, mapByPage, removeInvalidatedCallback
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TiledDataSource()

Methods

public abstract int countItems()

public abstract java.util.List<java.lang.Object> loadRange(int startPosition, int count)

public abstract void loadInitial(PositionalDataSource.LoadInitialParams params, PositionalDataSource.LoadInitialCallback<java.lang.Object> callback)

Load initial list data.

This method is called to load the initial page(s) from the DataSource.

Result list must be a multiple of pageSize to enable efficient tiling.

Parameters:

params: Parameters for initial load, including requested start position, load size, and page size.
callback: Callback that receives initial load data, including position and total data set size.

public abstract void loadRange(PositionalDataSource.LoadRangeParams params, PositionalDataSource.LoadRangeCallback<java.lang.Object> callback)

Called to load a range of data from the DataSource.

This method is called to load additional pages from the DataSource after the LoadInitialCallback passed to dispatchLoadInitial has initialized a PagedList.

Unlike PositionalDataSource.loadInitial(PositionalDataSource.LoadInitialParams, PositionalDataSource.LoadInitialCallback), this method must return the number of items requested, at the position requested.

Parameters:

params: Parameters for load, including start position and load size.
callback: Callback that receives loaded data.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.paging;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.WorkerThread;

import java.util.Collections;
import java.util.List;

// NOTE: Room 1.0 depends on this class, so it should not be removed until
// we can require a version of Room that uses PositionalDataSource directly
/**
 * @param <T> Type loaded by the TiledDataSource.
 *
 * @deprecated Use {@link PositionalDataSource}
 * @hide
 */
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public abstract class TiledDataSource<T> extends PositionalDataSource<T> {

    @WorkerThread
    public abstract int countItems();

    @Override
    boolean isContiguous() {
        return false;
    }

    @Nullable
    @WorkerThread
    public abstract List<T> loadRange(int startPosition, int count);

    @Override
    public void loadInitial(@NonNull LoadInitialParams params,
            @NonNull LoadInitialCallback<T> callback) {
        int totalCount = countItems();
        if (totalCount == 0) {
            callback.onResult(Collections.<T>emptyList(), 0, 0);
            return;
        }

        // bound the size requested, based on known count
        final int firstLoadPosition = computeInitialLoadPosition(params, totalCount);
        final int firstLoadSize = computeInitialLoadSize(params, firstLoadPosition, totalCount);

        // convert from legacy behavior
        List<T> list = loadRange(firstLoadPosition, firstLoadSize);
        if (list != null && list.size() == firstLoadSize) {
            callback.onResult(list, firstLoadPosition, totalCount);
        } else {
            // null list, or size doesn't match request
            // The size check is a WAR for Room 1.0, subsequent versions do the check in Room
            invalidate();
        }
    }

    @Override
    public void loadRange(@NonNull LoadRangeParams params,
            @NonNull LoadRangeCallback<T> callback) {
        List<T> list = loadRange(params.startPosition, params.loadSize);
        if (list != null) {
            callback.onResult(list);
        } else {
            invalidate();
        }
    }
}