summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkaiyiz <kaiyiz@codeaurora.org>2013-10-22 15:06:46 +0800
committeremancebo <emancebo@cyngn.com>2014-09-04 10:40:17 -0700
commit1e61414ee3ba09378e78ee3f731c84fa7f6e7bcf (patch)
tree074652267c4c428163f6ec3b53a85e1c1778becd /src
parentb292d11a72a4b4787df2e4d1c1a24760dbcbcf50 (diff)
downloadandroid_packages_apps_Gallery2-1e61414ee3ba09378e78ee3f731c84fa7f6e7bcf.tar.gz
android_packages_apps_Gallery2-1e61414ee3ba09378e78ee3f731c84fa7f6e7bcf.tar.bz2
android_packages_apps_Gallery2-1e61414ee3ba09378e78ee3f731c84fa7f6e7bcf.zip
Gallery2: fix two same albums come out after double click tags
When user click group by tags in albumpage,it will start albumsetpage to make gallery display the pictures which are sorted by tags.Then albumpsetpage will new a thread to load albums data.So two threads will be created if user click group by tags twice quickly.So the data will be handled by two thread.So the size of the albums will be add twice. So two same albums came out. For thread security,we add a synchronized to make sure the mAlbums can be only handled by one thread. CRs-Fixed: 562742 Change-Id: Ib1e2356fe25811c6d5d083cedd1861ce3bf7dea3
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/data/ClusterAlbumSet.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/data/ClusterAlbumSet.java b/src/com/android/gallery3d/data/ClusterAlbumSet.java
index cb212ba36..7e86689a5 100644
--- a/src/com/android/gallery3d/data/ClusterAlbumSet.java
+++ b/src/com/android/gallery3d/data/ClusterAlbumSet.java
@@ -76,7 +76,14 @@ public class ClusterAlbumSet extends MediaSet implements ContentListener {
notifyContentChanged();
}
- private void updateClusters() {
+ private synchronized void updateClusters() {
+ /*
+ for (ClusterAlbum entry : mAlbums) {
+ entry.clear();
+ }
+ */
+ updateEmptyClusters();
+
mAlbums.clear();
Clustering clustering;
Context context = mApplication.getAndroidContext();
@@ -109,6 +116,8 @@ public class ClusterAlbumSet extends MediaSet implements ContentListener {
} else if (mKind == ClusterSource.CLUSTER_ALBUMSET_SIZE) {
long minSize = ((SizeClustering) clustering).getMinSize(i);
childPath = mPath.getChild(minSize);
+ } else if (mKind == ClusterSource.CLUSTER_ALBUMSET_TIME) {
+ childPath = mPath.getChild(childName.toLowerCase().hashCode());
} else {
childPath = mPath.getChild(i);
}
@@ -156,4 +165,31 @@ public class ClusterAlbumSet extends MediaSet implements ContentListener {
}
}
}
+ private void updateEmptyClusters() {
+ final HashSet<Path> existing = new HashSet<Path>();
+ mBaseSet.enumerateTotalMediaItems(new MediaSet.ItemConsumer() {
+ public void consume(int index, MediaItem item) {
+ if (item == null) return;
+ existing.add(item.getPath());
+ }
+ });
+
+ int n = mAlbums.size();
+
+ // The loop goes backwards because we may set empty to inexistent cluster albums.
+ for (int i = n - 1; i >= 0; i--) {
+ ArrayList<Path> oldPaths = mAlbums.get(i).getMediaItems();
+ ArrayList<Path> newPaths = new ArrayList<Path>();
+ int m = oldPaths.size();
+ for (int j = 0; j < m; j++) {
+ Path p = oldPaths.get(j);
+ if (existing.contains(p)) {
+ newPaths.add(p);
+ }
+ }
+ if (newPaths.isEmpty()) {
+ mAlbums.get(i).setMediaItems(new ArrayList<Path>());
+ }
+ }
+ }
}