Android 使用PageKeyedDataSource反复滚动下载图像

Android 使用PageKeyedDataSource反复滚动下载图像,android,android-recyclerview,android-glide,Android,Android Recyclerview,Android Glide,我正在使用名为of PageKeyedDataSource的Android架构组件的分页库。我有无限滚动所有工作良好的分页期望图像加载一次又一次(已经加载),而滚动到顶部使用滑翔 这是我的代码: public class ItemDataSource extends PageKeyedDataSource<Integer, InspirationData> { //the size of a page that we want private static final int FI

我正在使用名为of PageKeyedDataSource的Android架构组件的分页库。我有无限滚动所有工作良好的分页期望图像加载一次又一次(已经加载),而滚动到顶部使用滑翔

这是我的代码:

public class ItemDataSource extends PageKeyedDataSource<Integer, InspirationData> {

//the size of a page that we want
private static final int FIRST_PAGE = 1;

String userid = "";
String deviceId = "";

@Override
public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull final LoadInitialCallback<Integer, InspirationData> callback) {

    userid = SharedPreferencesUtils.getUserId(TrendiiApp.trendiiApp.getApplicationContext());

    if (userid.equalsIgnoreCase("0")) {
        deviceId = Util.getDeviceid(TrendiiApp.trendiiApp.getApplicationContext());
    }


    RetrofitClient.getInstance()
            .getApi().getInspirations(userid, deviceId, FIRST_PAGE)
            .enqueue(new Callback<MainInspirationResponse>() {
                @Override
                public void onResponse(Call<MainInspirationResponse> call, Response<MainInspirationResponse> response) {
                    Log.v("TSTSTSTS", userid + " : " + deviceId + " : " + FIRST_PAGE);
                    if (response.body() != null) {
                        callback.onResult(response.body().getInspirationDataList(), null, FIRST_PAGE + 1);
                    }
                }

                @Override
                public void onFailure(Call<MainInspirationResponse> call, Throwable t) {
                    Log.v("EOROROROR", t.getMessage());
                }
            });
}

//this will load the previous page
@Override
public void loadBefore(@NonNull final LoadParams<Integer> params, @NonNull final LoadCallback<Integer, InspirationData> callback) {
    userid = SharedPreferencesUtils.getUserId(TrendiiApp.trendiiApp.getApplicationContext());

    if (userid.equalsIgnoreCase("0")) {
        deviceId = Util.getDeviceid(TrendiiApp.trendiiApp.getApplicationContext());
    }

    RetrofitClient.getInstance()
            .getApi().getInspirations(userid, deviceId, FIRST_PAGE)
            .enqueue(new Callback<MainInspirationResponse>() {
                @Override
                public void onResponse(Call<MainInspirationResponse> call, Response<MainInspirationResponse> response) {


                    Integer adjacentKey = (params.key > 1) ? params.key - 1 : null;
                    if (response.body() != null) {
                        callback.onResult(response.body().getInspirationDataList(), adjacentKey);
                    }
                }

                @Override
                public void onFailure(Call<MainInspirationResponse> call, Throwable t) {
                    Log.v("EOROROROR", t.getMessage());
                }
            });
}

//this will load the next page
@Override
public void loadAfter(@NonNull final LoadParams<Integer> params, @NonNull final LoadCallback<Integer, InspirationData> callback) {
    userid = SharedPreferencesUtils.getUserId(TrendiiApp.trendiiApp.getApplicationContext());

    if (userid.equalsIgnoreCase("0")) {
        deviceId = Util.getDeviceid(TrendiiApp.trendiiApp.getApplicationContext());
    }

    RetrofitClient.getInstance()
            .getApi().getInspirations(userid, deviceId, params.key)
            .enqueue(new Callback<MainInspirationResponse>() {
                @Override
                public void onResponse(Call<MainInspirationResponse> call, Response<MainInspirationResponse> response) {

                    if (response.body() != null) {
                        Integer key = params.key + 1;
                        ExtraInfo extraInfo = response.body().getExtraInfo();
                        if (extraInfo.getTotalpages() != key) {
                            callback.onResult(response.body().getInspirationDataList(), key);
                        }
                    }
                }

                @Override
                public void onFailure(Call<MainInspirationResponse> call, Throwable t) {
                    Log.v("EOROROROR", t.getMessage());
                }
            });
}
}
DiskCacheStrategy。所有
也不起作用。 任何先进的帮助将不胜感激

尝试添加

requestOptions.skipMemoryCache(false)
requestOptions.skipMemoryCache(false)