Fix 5196286: Crash if the last clustered album is deleted.

Change-Id: I5e451d3cebd61c31465cba56aebe66cc3a999e2d
diff --git a/src/com/android/gallery3d/app/AlbumSetDataAdapter.java b/src/com/android/gallery3d/app/AlbumSetDataAdapter.java
index 9086ddb..85f3bf5 100644
--- a/src/com/android/gallery3d/app/AlbumSetDataAdapter.java
+++ b/src/com/android/gallery3d/app/AlbumSetDataAdapter.java
@@ -355,6 +355,14 @@
                     if (info.version != version) {
                         info.version = version;
                         info.size = mSource.getSubMediaSetCount();
+
+                        // If the size becomes smaller after reload(), we may
+                        // receive from GetUpdateInfo an index which is too
+                        // big. Because the main thread is not aware of the size
+                        // change until we call UpdateContent.
+                        if (info.index >= info.size) {
+                            info.index = INDEX_NONE;
+                        }
                     }
                     if (info.index != INDEX_NONE) {
                         info.item = mSource.getSubMediaSet(info.index);