private void updateSlidingWindow() { // 1. Update the image window int start = Utils.clamp(mCurrentIndex - IMAGE_CACHE_SIZE / 2, 0, Math.max(0, mSize - IMAGE_CACHE_SIZE)); int end = Math.min(mSize, start + IMAGE_CACHE_SIZE); if (mActiveStart == start && mActiveEnd == end) return; mActiveStart = start; mActiveEnd = end; // 2. Update the data window start = Utils.clamp(mCurrentIndex - DATA_CACHE_SIZE / 2, 0, Math.max(0, mSize - DATA_CACHE_SIZE)); end = Math.min(mSize, start + DATA_CACHE_SIZE); if (mContentStart > mActiveStart || mContentEnd < mActiveEnd || Math.abs(start - mContentStart) > MIN_LOAD_COUNT) { for (int i = mContentStart; i < mContentEnd; ++i) { if (i < start || i >= end) { mData[i % DATA_CACHE_SIZE] = null; } } mContentStart = start; mContentEnd = end; if (mReloadTask != null) mReloadTask.notifyDirty(); } }
public void setCurrentPhoto(Path path, int indexHint) { if (mItemPath == path) return; mItemPath = path; mCurrentIndex = indexHint; updateSlidingWindow(); updateImageCache(); fireModelInvalidated(); // We need to reload content if the path doesn't match. MediaItem item = getCurrentMediaItem(); if (item != null && item.getPath() != path) { if (mReloadTask != null) mReloadTask.notifyDirty(); } }