am 61ab647c: Merge "Fixed the issue that media sets still appear after deleting all albums in Gallery3D." into gingerbread

* commit '61ab647c5ad9a101a01fff7f677fead8d37ebfba':
  Fixed the issue that media sets still appear after deleting all albums in Gallery3D.
diff --git a/src/com/cooliris/cache/CacheService.java b/src/com/cooliris/cache/CacheService.java
index c8a5fc0..6f68913 100644
--- a/src/com/cooliris/cache/CacheService.java
+++ b/src/com/cooliris/cache/CacheService.java
@@ -1011,26 +1011,33 @@
                         }
                         ++ctr;
                     } while (ctr < numSets);
-                    // We now check for any deleted sets.
-                    final byte[] albumData = sAlbumCache.get(ALBUM_CACHE_METADATA_INDEX, 0);
-                    if (albumData != null && albumData.length > 0) {
-                        final DataInputStream dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(albumData), 256));
-                        try {
-                            final int numAlbums = dis.readInt();
-                            for (int i = 0; i < numAlbums; ++i) {
-                                final long setId = dis.readLong();
-                                Utils.readUTF(dis);
-                                dis.readBoolean();
-                                dis.readBoolean();
-                                if (!setIds.contains(setId)) {
+                }
+                // We now check for any deleted sets.
+                final byte[] albumData = sAlbumCache.get(ALBUM_CACHE_METADATA_INDEX, 0);
+                if (albumData != null && albumData.length > 0) {
+                    final DataInputStream dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(albumData), 256));
+                    try {
+                        final int numAlbums = dis.readInt();
+                        for (int i = 0; i < numAlbums; ++i) {
+                            final long setId = dis.readLong();
+                            Utils.readUTF(dis);
+                            dis.readBoolean();
+                            dis.readBoolean();
+                            if (!setIds.contains(setId)) {
+                                final byte[] existingData = sAlbumCache.get(ALBUM_CACHE_DIRTY_INDEX, 0);
+                                if (existingData != null && existingData.length == 1
+                                    && existingData[0] == sDummyData[0]) {
+                                    // markDirty() was already called, skip this time.
+                                    // (not do it too aggressively)
+                                } else {
                                     // This set was deleted, we need to recompute the cache.
                                     markDirty();
-                                    break;
                                 }
+                                break;
                             }
-                        } catch (Exception e) {
-                            ;
                         }
+                    } catch (Exception e) {
+                        ;
                     }
                 }
             } finally {