androidx.paging.WrapperPageKeyedDataSource Maven / Gradle / Ivy
/*
* Copyright 2016-2019 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.arch.core.util.Function;
import java.util.List;
class WrapperPageKeyedDataSource extends PageKeyedDataSource {
private final PageKeyedDataSource mSource;
private final Function, List> mListFunction;
WrapperPageKeyedDataSource(PageKeyedDataSource source,
Function, List> listFunction) {
mSource = source;
mListFunction = listFunction;
}
@Override
public void addInvalidatedCallback(@NonNull InvalidatedCallback onInvalidatedCallback) {
mSource.addInvalidatedCallback(onInvalidatedCallback);
}
@Override
public void removeInvalidatedCallback(@NonNull InvalidatedCallback onInvalidatedCallback) {
mSource.removeInvalidatedCallback(onInvalidatedCallback);
}
@Override
public void invalidate() {
mSource.invalidate();
}
@Override
public boolean isInvalid() {
return mSource.isInvalid();
}
@Override
public void loadInitial(@NonNull LoadInitialParams params,
final @NonNull LoadInitialCallback callback) {
mSource.loadInitial(params, new LoadInitialCallback() {
@Override
public void onResult(@NonNull List data, int position, int totalCount,
@Nullable K previousPageKey, @Nullable K nextPageKey) {
callback.onResult(convert(mListFunction, data), position, totalCount,
previousPageKey, nextPageKey);
}
@Override
public void onResult(@NonNull List data, @Nullable K previousPageKey,
@Nullable K nextPageKey) {
callback.onResult(convert(mListFunction, data), previousPageKey, nextPageKey);
}
});
}
@Override
public void loadBefore(@NonNull LoadParams params,
final @NonNull LoadCallback callback) {
mSource.loadBefore(params, new LoadCallback() {
@Override
public void onResult(@NonNull List data, @Nullable K adjacentPageKey) {
callback.onResult(convert(mListFunction, data), adjacentPageKey);
}
});
}
@Override
public void loadAfter(@NonNull LoadParams params,
final @NonNull LoadCallback callback) {
mSource.loadAfter(params, new LoadCallback() {
@Override
public void onResult(@NonNull List data, @Nullable K adjacentPageKey) {
callback.onResult(convert(mListFunction, data), adjacentPageKey);
}
});
}
}