From 7ed375d6829e18a0d342d31c3217d6263b9a5c33 Mon Sep 17 00:00:00 2001 From: zhuw Date: Tue, 2 Aug 2016 15:47:08 +0800 Subject: Gallery:Fix page skipping error after the editing 1. Add isLoading function at ClusterAlbumSet and ClusterAlbum. 2. Add isLoading function at FilterDeleteSet. 3. Modify ReloadTask in PhotoDataAdapter to control the loop by using the isLoading function. Change-Id: If3578294163120a0b52db0696deb7d5a764e0c1c CRs-Fixed: 1042817 --- src/com/android/gallery3d/app/PhotoDataAdapter.java | 14 ++++++++++++-- src/com/android/gallery3d/data/ClusterAlbum.java | 5 +++++ src/com/android/gallery3d/data/ClusterAlbumSet.java | 10 +++++++++- src/com/android/gallery3d/data/FilterDeleteSet.java | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java index c6ad14ded..872706fee 100755 --- a/src/com/android/gallery3d/app/PhotoDataAdapter.java +++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java @@ -1308,6 +1308,7 @@ public class PhotoDataAdapter implements PhotoPage.Model { } } mDirty = false; + version = mSource.reload(); if (mIsFromTimelineScreen) { mSource.setClusterKind(GalleryActivity.CLUSTER_ALBUMSET_NO_TITLE); @@ -1316,6 +1317,12 @@ public class PhotoDataAdapter implements PhotoPage.Model { if (version == MediaObject.INVALID_DATA_VERSION) { continue; } + if (mSource.isLoading()) { + mDirty = true; + continue; + } else { + mSourceVersion = version; + } UpdateInfo info = executeAndWait(new GetUpdateInfo()); updateLoading(true); @@ -1331,9 +1338,9 @@ public class PhotoDataAdapter implements PhotoPage.Model { if (info.version != version) { info.reloadContent = true; - info.size = mSource.getMediaItemCount(); } if (!info.reloadContent) continue; + info.size = mSource.getMediaItemCount(); // Check it is from camera or not boolean isCameraFlag = false; @@ -1436,7 +1443,10 @@ public class PhotoDataAdapter implements PhotoPage.Model { // Don't change index if mSize == 0 if (mSize > 0) { - if (index >= mSize) index = mSize - 1; + // Due to the set identification and new photo, photos + // in the last two positions disappear in the temp info.items. + // Don't change index in such a situation. + if (index >= mSize + 2) index = mSize - 1; } info.indexHint = index; diff --git a/src/com/android/gallery3d/data/ClusterAlbum.java b/src/com/android/gallery3d/data/ClusterAlbum.java index b7d1c3f36..4e2cc18ea 100644 --- a/src/com/android/gallery3d/data/ClusterAlbum.java +++ b/src/com/android/gallery3d/data/ClusterAlbum.java @@ -178,6 +178,11 @@ public class ClusterAlbum extends MediaSet implements ContentListener { return super.getMediaType(); } + @Override + public boolean isLoading() { + return mClusterAlbumSet.isLoading(); + } + @Override public long reload() { long version = mClusterAlbumSet.reload(); diff --git a/src/com/android/gallery3d/data/ClusterAlbumSet.java b/src/com/android/gallery3d/data/ClusterAlbumSet.java index 0986a8d69..7695bd35c 100644 --- a/src/com/android/gallery3d/data/ClusterAlbumSet.java +++ b/src/com/android/gallery3d/data/ClusterAlbumSet.java @@ -32,6 +32,7 @@ public class ClusterAlbumSet extends MediaSet implements ContentListener { private MediaSet mBaseSet; private int mKind; private ArrayList mAlbums = new ArrayList(); + private boolean mIsLoading; private int mTotalMediaItemCount; /** mTotalSelectableMediaItemCount is the count of items @@ -63,12 +64,19 @@ public class ClusterAlbumSet extends MediaSet implements ContentListener { return mBaseSet.getName(); } + @Override + public synchronized boolean isLoading() { + return mIsLoading; + } + @Override public long reload() { synchronized (this) { long version = mBaseSet.reload(); - if (version > mDataVersion && !mBaseSet.isLoading()) { + mIsLoading = mBaseSet.isLoading(); + if (version > mDataVersion && !mIsLoading) { updateClusters(); + mIsLoading = false; mDataVersion = nextVersionNumber(); } if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) { diff --git a/src/com/android/gallery3d/data/FilterDeleteSet.java b/src/com/android/gallery3d/data/FilterDeleteSet.java index fcf0dec74..5c34fda70 100644 --- a/src/com/android/gallery3d/data/FilterDeleteSet.java +++ b/src/com/android/gallery3d/data/FilterDeleteSet.java @@ -35,6 +35,8 @@ public class FilterDeleteSet extends MediaSet implements ContentListener { private static final int REQUEST_REMOVE = 2; private static final int REQUEST_CLEAR = 3; + private boolean mIsLoading; + private static class Request { int type; // one of the REQUEST_* constants Path path; @@ -141,12 +143,21 @@ public class FilterDeleteSet extends MediaSet implements ContentListener { return base; } + @Override + public boolean isLoading() { + return mIsLoading; + } + // We apply the pending requests in the mRequests to construct mCurrent in reload(). @Override public long reload() { + mIsLoading = true; boolean newData = mBaseSet.reload() > mDataVersion; synchronized (mRequests) { if (!newData && mRequests.isEmpty()) { + if (!mBaseSet.isLoading()) { + mIsLoading = false; + } return mDataVersion; } for (int i = 0; i < mRequests.size(); i++) { @@ -220,6 +231,9 @@ public class FilterDeleteSet extends MediaSet implements ContentListener { } mDataVersion = nextVersionNumber(); + if (!mBaseSet.isLoading()) { + mIsLoading = false; + } return mDataVersion; } -- cgit v1.2.3