From 922280596ba53e3e1d71d332e8ca1d4e8b89c716 Mon Sep 17 00:00:00 2001 From: Qi Ling Date: Thu, 21 Apr 2011 19:40:07 -0700 Subject: Fixed the issue that media sets still appear after deleting all albums in Gallery3D. If we delete all media sets in Gallery3D by "Selecte All" and "Delete" (basically, making Gallery3D empty through one shot delete), next time we enter Gallery3D we can see delted albums are still there. The cause of this issue is when the number of media sets becomes zero (e.g., after one shot delete), the original logic skips checking for any deleted sets. We should check if there is any change in media sets (including the case it is totally gone), regardless of the current number of media sets Change-Id: I9bc45fb13925b5ca9176d88fcfead0690c69ba63 Signed-off-by: madan ankapura --- src/com/cooliris/cache/CacheService.java | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) 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 @@ public final class CacheService extends IntentService { } ++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 { -- cgit v1.2.3