diff options
author | Hung-ying Tyan <tyanh@google.com> | 2012-10-30 17:47:35 +0800 |
---|---|---|
committer | Hung-ying Tyan <tyanh@google.com> | 2012-10-30 19:44:15 +0800 |
commit | 05da3f520eacb9219964b6ed57ef37846d889fd7 (patch) | |
tree | b574f8ac1346a4fe96918c6b1977f4623cb61fb3 /src/com/android/gallery3d/app/AlbumPage.java | |
parent | 38c5d92c4a3659f3ae51a3b0f61bfb9eb2ed0043 (diff) | |
download | android_packages_apps_Gallery2-05da3f520eacb9219964b6ed57ef37846d889fd7.tar.gz android_packages_apps_Gallery2-05da3f520eacb9219964b6ed57ef37846d889fd7.tar.bz2 android_packages_apps_Gallery2-05da3f520eacb9219964b6ed57ef37846d889fd7.zip |
Show sync error toast only when both loading and syncing are done.
Bug: 7427597
Change-Id: Ie1fe8510e2a2225424b3c2892b2c0a8b4021324c
Diffstat (limited to 'src/com/android/gallery3d/app/AlbumPage.java')
-rw-r--r-- | src/com/android/gallery3d/app/AlbumPage.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 4c945a45b..ee7a107fd 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -108,6 +108,8 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private int mLoadingBits = 0; private boolean mInitialSynced = false; + private int mSyncResult; + private boolean mLoadingFailed; private RelativePosition mOpenCenter = new RelativePosition(); private Handler mHandler; @@ -419,6 +421,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster // Set the reload bit here to prevent it exit this page in clearLoadingBit(). setLoadingBit(BIT_LOADING_RELOAD); + mLoadingFailed = false; mAlbumDataAdapter.resume(); mAlbumView.resume(); @@ -693,17 +696,13 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster public void run() { GLRoot root = mActivity.getGLRoot(); root.lockRenderThread(); + mSyncResult = resultCode; try { if (resultCode == MediaSet.SYNC_RESULT_SUCCESS) { mInitialSynced = true; } clearLoadingBit(BIT_LOADING_SYNC); - if (resultCode == MediaSet.SYNC_RESULT_ERROR && mIsActive - && (mAlbumDataAdapter.size() == 0)) { - // show error toast only if the album is empty - Toast.makeText(mActivity, R.string.sync_album_error, - Toast.LENGTH_LONG).show(); - } + showSyncErrorIfNecessary(mLoadingFailed); } finally { root.unlockRenderThread(); } @@ -711,6 +710,19 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster }); } + // Show sync error toast when all the following conditions are met: + // (1) both loading and sync are done, + // (2) sync result is error, + // (3) the page is still active, and + // (4) no photo is shown or loading fails. + private void showSyncErrorIfNecessary(boolean loadingFailed) { + if ((mLoadingBits == 0) && (mSyncResult == MediaSet.SYNC_RESULT_ERROR) && mIsActive + && (loadingFailed || (mAlbumDataAdapter.size() == 0))) { + Toast.makeText(mActivity, R.string.sync_album_error, + Toast.LENGTH_LONG).show(); + } + } + private void setLoadingBit(int loadTaskBit) { mLoadingBits |= loadTaskBit; } @@ -731,11 +743,14 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster @Override public void onLoadingStarted() { setLoadingBit(BIT_LOADING_RELOAD); + mLoadingFailed = false; } @Override - public void onLoadingFinished() { + public void onLoadingFinished(boolean loadingFailed) { clearLoadingBit(BIT_LOADING_RELOAD); + mLoadingFailed = loadingFailed; + showSyncErrorIfNecessary(loadingFailed); } } |