From e8c1e69f85efb8673d0606f3aca729a366038753 Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Thu, 17 May 2012 12:29:12 +0800 Subject: Fix 6259517 "0 images / videos available" toast is displayed in gallery on launch though it has images / videos And removed sync error toast. Bug: 6259517 Change-Id: Ib7b25176a6db290220661a2e98e4e031043201d9 --- src/com/android/gallery3d/app/AlbumPage.java | 4 +++- src/com/android/gallery3d/app/AlbumSetDataLoader.java | 2 +- src/com/android/gallery3d/app/AlbumSetPage.java | 7 +++---- src/com/android/gallery3d/data/ComboAlbumSet.java | 8 ++++++++ src/com/android/gallery3d/data/LocalAlbumSet.java | 8 ++++++++ src/com/android/gallery3d/data/MediaSet.java | 8 ++++++++ src/com/android/gallery3d/data/MtpDeviceSet.java | 8 ++++++++ 7 files changed, 39 insertions(+), 6 deletions(-) (limited to 'src') 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 @@ -64,6 +64,14 @@ public class ComboAlbumSet extends MediaSet implements ContentListener { return mName; } + @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; 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> mLoadTask; private ArrayList mLoadBuffer; @@ -260,6 +261,11 @@ public class LocalAlbumSet extends MediaSet } } + @Override + public synchronized boolean isLoading() { + return mIsLoading; + } + @Override // synchronized on this function for // 1. Prevent calling 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> future) { if (mLoadTask != future) return; // ignore, wait for the latest task mLoadBuffer = future.get(); + mIsLoading = false; if (mLoadBuffer == null) mLoadBuffer = new ArrayList(); 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> mLoadTask; private ArrayList mDeviceSet = new ArrayList(); private ArrayList mLoadBuffer; + private boolean mIsLoading; public MtpDeviceSet(Path path, GalleryApp application, MtpContext mtpContext) { super(path, nextVersionNumber()); @@ -112,10 +113,16 @@ public class MtpDeviceSet extends MediaSet return mName; } + @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> future) { if (future != mLoadTask) return; mLoadBuffer = future.get(); + mIsLoading = false; if (mLoadBuffer == null) mLoadBuffer = new ArrayList(); mHandler.post(new Runnable() { -- cgit v1.2.3