diff options
| author | Wei Huang <weih@google.com> | 2012-05-22 21:56:46 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-22 21:56:46 -0700 |
| commit | 13188c884a93f6086cbf4e860fb6dfcbc44c6e13 (patch) | |
| tree | 1b6f78b8dbf8976addafe11e2d9d09fa5822d547 /src | |
| parent | 96b012c84436c776fe515f7d70eb4f8f309ce38a (diff) | |
| parent | e8c1e69f85efb8673d0606f3aca729a366038753 (diff) | |
| download | android_packages_apps_Gallery2-13188c884a93f6086cbf4e860fb6dfcbc44c6e13.tar.gz android_packages_apps_Gallery2-13188c884a93f6086cbf4e860fb6dfcbc44c6e13.tar.bz2 android_packages_apps_Gallery2-13188c884a93f6086cbf4e860fb6dfcbc44c6e13.zip | |
Merge "Fix 6259517 "0 images / videos available" toast is displayed in gallery on launch though it has images / videos" into jb-dev
Diffstat (limited to 'src')
7 files changed, 39 insertions, 6 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 090ba0891..e7736918b 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -652,7 +652,9 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mInitialSynced = true; } clearLoadingBit(BIT_LOADING_SYNC); - if (resultCode == MediaSet.SYNC_RESULT_ERROR && mIsActive) { + if (resultCode == MediaSet.SYNC_RESULT_ERROR && mIsActive + && (mAlbumDataAdapter.size() == 0)) { + // show error toast only if the album is empty Toast.makeText((Context) mActivity, R.string.sync_album_error, Toast.LENGTH_LONG).show(); } diff --git a/src/com/android/gallery3d/app/AlbumSetDataLoader.java b/src/com/android/gallery3d/app/AlbumSetDataLoader.java index 819adccb7..39d4a8bdc 100644 --- a/src/com/android/gallery3d/app/AlbumSetDataLoader.java +++ b/src/com/android/gallery3d/app/AlbumSetDataLoader.java @@ -329,7 +329,7 @@ public class AlbumSetDataLoader { while (mActive) { synchronized (this) { if (mActive && !mDirty && updateComplete) { - updateLoading(false); + if (!mSource.isLoading()) updateLoading(false); Utils.waitWithoutInterrupt(this); continue; } diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index 8376b2792..aa72eb82c 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -300,9 +300,9 @@ public class AlbumSetPage extends ActivityState implements // Only show toast when there's no album and we are going to finish // the page. Toast is redundant if we are going to stay on this page. if ((mAlbumSetDataAdapter.size() == 0)) { - Toast.makeText((Context) mActivity, - R.string.empty_album, Toast.LENGTH_LONG).show(); if (mActivity.getStateManager().getStateCount() > 1) { + Toast.makeText((Context) mActivity, + R.string.empty_album, Toast.LENGTH_LONG).show(); mActivity.getStateManager().finishState(this); } } @@ -597,8 +597,7 @@ public class AlbumSetPage extends ActivityState implements } clearLoadingBit(BIT_LOADING_SYNC); if (resultCode == MediaSet.SYNC_RESULT_ERROR && mIsActive) { - Toast.makeText((Context) mActivity, R.string.sync_album_set_error, - Toast.LENGTH_LONG).show(); + Log.w(TAG, "failed to load album set"); } } finally { root.unlockRenderThread(); diff --git a/src/com/android/gallery3d/data/ComboAlbumSet.java b/src/com/android/gallery3d/data/ComboAlbumSet.java index 916b1639d..6d9a2a3d4 100644 --- a/src/com/android/gallery3d/data/ComboAlbumSet.java +++ b/src/com/android/gallery3d/data/ComboAlbumSet.java @@ -65,6 +65,14 @@ public class ComboAlbumSet extends MediaSet implements ContentListener { } @Override + public boolean isLoading() { + for (int i = 0, n = mSets.length; i < n; ++i) { + if (mSets[i].isLoading()) return true; + } + return false; + } + + @Override public long reload() { boolean changed = false; for (int i = 0, n = mSets.length; i < n; ++i) { diff --git a/src/com/android/gallery3d/data/LocalAlbumSet.java b/src/com/android/gallery3d/data/LocalAlbumSet.java index dbb518985..07741efcb 100644 --- a/src/com/android/gallery3d/data/LocalAlbumSet.java +++ b/src/com/android/gallery3d/data/LocalAlbumSet.java @@ -100,6 +100,7 @@ public class LocalAlbumSet extends MediaSet private final ChangeNotifier mNotifierVideo; private final String mName; private final Handler mHandler; + private boolean mIsLoading; private Future<ArrayList<MediaSet>> mLoadTask; private ArrayList<MediaSet> mLoadBuffer; @@ -261,6 +262,11 @@ public class LocalAlbumSet extends MediaSet } @Override + public synchronized boolean isLoading() { + return mIsLoading; + } + + @Override // synchronized on this function for // 1. Prevent calling reload() concurrently. // 2. Prevent calling onFutureDone() and reload() concurrently @@ -268,6 +274,7 @@ public class LocalAlbumSet extends MediaSet // "|" is used instead of "||" because we want to clear both flags. if (mNotifierImage.isDirty() | mNotifierVideo.isDirty()) { if (mLoadTask != null) mLoadTask.cancel(); + mIsLoading = true; mLoadTask = mApplication.getThreadPool().submit(new AlbumsLoader(), this); } if (mLoadBuffer != null) { @@ -285,6 +292,7 @@ public class LocalAlbumSet extends MediaSet public synchronized void onFutureDone(Future<ArrayList<MediaSet>> future) { if (mLoadTask != future) return; // ignore, wait for the latest task mLoadBuffer = future.get(); + mIsLoading = false; if (mLoadBuffer == null) mLoadBuffer = new ArrayList<MediaSet>(); mHandler.post(new Runnable() { @Override diff --git a/src/com/android/gallery3d/data/MediaSet.java b/src/com/android/gallery3d/data/MediaSet.java index ff9b8c386..67525b1f3 100644 --- a/src/com/android/gallery3d/data/MediaSet.java +++ b/src/com/android/gallery3d/data/MediaSet.java @@ -94,6 +94,14 @@ public abstract class MediaSet extends MediaObject { return false; } + /** + * Method {@link #reload()} may process the loading task in background, this method tells + * its client whether the loading is still in process or not. + */ + public boolean isLoading() { + return false; + } + public int getTotalMediaItemCount() { int total = getMediaItemCount(); for (int i = 0, n = getSubMediaSetCount(); i < n; i++) { diff --git a/src/com/android/gallery3d/data/MtpDeviceSet.java b/src/com/android/gallery3d/data/MtpDeviceSet.java index 6dcb0d2e6..1f26511fc 100644 --- a/src/com/android/gallery3d/data/MtpDeviceSet.java +++ b/src/com/android/gallery3d/data/MtpDeviceSet.java @@ -47,6 +47,7 @@ public class MtpDeviceSet extends MediaSet private Future<ArrayList<MediaSet>> mLoadTask; private ArrayList<MediaSet> mDeviceSet = new ArrayList<MediaSet>(); private ArrayList<MediaSet> mLoadBuffer; + private boolean mIsLoading; public MtpDeviceSet(Path path, GalleryApp application, MtpContext mtpContext) { super(path, nextVersionNumber()); @@ -113,9 +114,15 @@ public class MtpDeviceSet extends MediaSet } @Override + public synchronized boolean isLoading() { + return mIsLoading; + } + + @Override public synchronized long reload() { if (mNotifier.isDirty()) { if (mLoadTask != null) mLoadTask.cancel(); + mIsLoading = true; mLoadTask = mApplication.getThreadPool().submit(new DevicesLoader(), this); } if (mLoadBuffer != null) { @@ -133,6 +140,7 @@ public class MtpDeviceSet extends MediaSet public synchronized void onFutureDone(Future<ArrayList<MediaSet>> future) { if (future != mLoadTask) return; mLoadBuffer = future.get(); + mIsLoading = false; if (mLoadBuffer == null) mLoadBuffer = new ArrayList<MediaSet>(); mHandler.post(new Runnable() { |
