diff options
Diffstat (limited to 'src/com/android/gallery3d/data/LocalMergeAlbum.java')
-rw-r--r-- | src/com/android/gallery3d/data/LocalMergeAlbum.java | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/data/LocalMergeAlbum.java b/src/com/android/gallery3d/data/LocalMergeAlbum.java index f0b5e5726..e07dc5ed8 100644 --- a/src/com/android/gallery3d/data/LocalMergeAlbum.java +++ b/src/com/android/gallery3d/data/LocalMergeAlbum.java @@ -24,7 +24,6 @@ import com.android.gallery3d.common.ApiHelper; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Comparator; -import java.util.NoSuchElementException; import java.util.SortedMap; import java.util.TreeMap; @@ -40,6 +39,7 @@ public class LocalMergeAlbum extends MediaSet implements ContentListener { private final Comparator<MediaItem> mComparator; private final MediaSet[] mSources; + private final boolean[] mDirtySources; private FetchCache[] mFetcher; private int mSupportedOperation; @@ -53,11 +53,11 @@ public class LocalMergeAlbum extends MediaSet implements ContentListener { super(path, INVALID_DATA_VERSION); mComparator = comparator; mSources = sources; + mDirtySources = new boolean[mSources.length]; mBucketId = bucketId; for (MediaSet set : mSources) { set.addContentListener(this); } - reload(); } @Override @@ -70,7 +70,6 @@ public class LocalMergeAlbum extends MediaSet implements ContentListener { } private void updateData() { - ArrayList<MediaSet> matches = new ArrayList<MediaSet>(); int supported = mSources.length == 0 ? 0 : MediaItem.SUPPORT_ALL; mFetcher = new FetchCache[mSources.length]; for (int i = 0, n = mSources.length; i < n; ++i) { @@ -173,17 +172,26 @@ public class LocalMergeAlbum extends MediaSet implements ContentListener { } @Override - public long reload() { - boolean changed = false; + protected boolean isDirtyLocked() { + boolean dirty = false; for (int i = 0, n = mSources.length; i < n; ++i) { - if (mSources[i].reload() > mDataVersion) changed = true; + mDirtySources[i] = mSources[i].isDirtyLocked(); + dirty |= mDirtySources[i] + || mSources[i].getDataVersion() > getDataVersion(); } - if (changed) { - mDataVersion = nextVersionNumber(); - updateData(); - invalidateCache(); + return dirty; + } + + @Override + public void load() throws InterruptedException { + for (int i = 0, n = mSources.length; i < n; ++i) { + if (mDirtySources[i]) { + mSources[i].load(); + mDirtySources[i] = false; + } } - return mDataVersion; + updateData(); + invalidateCache(); } @Override |