Loading src/com/android/gallery3d/app/AlbumDataLoader.java +26 −3 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ public class AlbumDataLoader { private LoadingListener mLoadingListener; private ReloadTask mReloadTask; // the data version on which last loading failed private long mFailedVersion = MediaObject.INVALID_DATA_VERSION; public AlbumDataLoader(AbstractGalleryActivity context, MediaSet mediaSet) { mSource = mediaSet; Loading @@ -93,7 +95,11 @@ public class AlbumDataLoader { if (mLoadingListener != null) mLoadingListener.onLoadingStarted(); return; case MSG_LOAD_FINISH: if (mLoadingListener != null) mLoadingListener.onLoadingFinished(); if (mLoadingListener != null) { boolean loadingFailed = (mFailedVersion != MediaObject.INVALID_DATA_VERSION); mLoadingListener.onLoadingFinished(loadingFailed); } return; } } Loading Loading @@ -245,6 +251,10 @@ public class AlbumDataLoader { @Override public UpdateInfo call() throws Exception { if (mFailedVersion == mVersion) { // previous loading failed, return null to pause loading return null; } UpdateInfo info = new UpdateInfo(); long version = mVersion; info.version = mSourceVersion; Loading Loading @@ -283,7 +293,14 @@ public class AlbumDataLoader { ArrayList<MediaItem> items = info.items; if (items == null) return null; mFailedVersion = MediaObject.INVALID_DATA_VERSION; if ((items == null) || items.isEmpty()) { if (info.reloadCount > 0) { mFailedVersion = info.version; Log.d(TAG, "loading failed: " + mFailedVersion); } return null; } int start = Math.max(info.reloadStart, mContentStart); int end = Math.min(info.reloadStart + items.size(), mContentEnd); Loading Loading @@ -340,11 +357,17 @@ public class AlbumDataLoader { synchronized (this) { if (mActive && !mDirty && updateComplete) { updateLoading(false); if (mFailedVersion != MediaObject.INVALID_DATA_VERSION) { Log.d(TAG, "reload pause"); } Utils.waitWithoutInterrupt(this); continue; if (mActive && (mFailedVersion != MediaObject.INVALID_DATA_VERSION)) { Log.d(TAG, "reload resume"); } continue; } mDirty = false; } updateLoading(true); long version = mSource.reload(); UpdateInfo info = executeAndWait(new GetUpdateInfo(version)); Loading src/com/android/gallery3d/app/AlbumPage.java +22 −7 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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(); } Loading @@ -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; } Loading @@ -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); } } Loading src/com/android/gallery3d/app/AlbumSetDataLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ public class AlbumSetDataLoader { if (mLoadingListener != null) mLoadingListener.onLoadingStarted(); return; case MSG_LOAD_FINISH: if (mLoadingListener != null) mLoadingListener.onLoadingFinished(); if (mLoadingListener != null) mLoadingListener.onLoadingFinished(false); return; } } Loading src/com/android/gallery3d/app/AlbumSetPage.java +1 −1 Original line number Diff line number Diff line Loading @@ -734,7 +734,7 @@ public class AlbumSetPage extends ActivityState implements } @Override public void onLoadingFinished() { public void onLoadingFinished(boolean loadingFailed) { clearLoadingBit(BIT_LOADING_RELOAD); } } Loading src/com/android/gallery3d/app/LoadingListener.java +6 −1 Original line number Diff line number Diff line Loading @@ -18,5 +18,10 @@ package com.android.gallery3d.app; public interface LoadingListener { public void onLoadingStarted(); public void onLoadingFinished(); /** * Called when loading is complete or no further progress can be made. * * @param loadingFailed true if data source cannot provide requested data */ public void onLoadingFinished(boolean loadingFailed); } Loading
src/com/android/gallery3d/app/AlbumDataLoader.java +26 −3 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ public class AlbumDataLoader { private LoadingListener mLoadingListener; private ReloadTask mReloadTask; // the data version on which last loading failed private long mFailedVersion = MediaObject.INVALID_DATA_VERSION; public AlbumDataLoader(AbstractGalleryActivity context, MediaSet mediaSet) { mSource = mediaSet; Loading @@ -93,7 +95,11 @@ public class AlbumDataLoader { if (mLoadingListener != null) mLoadingListener.onLoadingStarted(); return; case MSG_LOAD_FINISH: if (mLoadingListener != null) mLoadingListener.onLoadingFinished(); if (mLoadingListener != null) { boolean loadingFailed = (mFailedVersion != MediaObject.INVALID_DATA_VERSION); mLoadingListener.onLoadingFinished(loadingFailed); } return; } } Loading Loading @@ -245,6 +251,10 @@ public class AlbumDataLoader { @Override public UpdateInfo call() throws Exception { if (mFailedVersion == mVersion) { // previous loading failed, return null to pause loading return null; } UpdateInfo info = new UpdateInfo(); long version = mVersion; info.version = mSourceVersion; Loading Loading @@ -283,7 +293,14 @@ public class AlbumDataLoader { ArrayList<MediaItem> items = info.items; if (items == null) return null; mFailedVersion = MediaObject.INVALID_DATA_VERSION; if ((items == null) || items.isEmpty()) { if (info.reloadCount > 0) { mFailedVersion = info.version; Log.d(TAG, "loading failed: " + mFailedVersion); } return null; } int start = Math.max(info.reloadStart, mContentStart); int end = Math.min(info.reloadStart + items.size(), mContentEnd); Loading Loading @@ -340,11 +357,17 @@ public class AlbumDataLoader { synchronized (this) { if (mActive && !mDirty && updateComplete) { updateLoading(false); if (mFailedVersion != MediaObject.INVALID_DATA_VERSION) { Log.d(TAG, "reload pause"); } Utils.waitWithoutInterrupt(this); continue; if (mActive && (mFailedVersion != MediaObject.INVALID_DATA_VERSION)) { Log.d(TAG, "reload resume"); } continue; } mDirty = false; } updateLoading(true); long version = mSource.reload(); UpdateInfo info = executeAndWait(new GetUpdateInfo(version)); Loading
src/com/android/gallery3d/app/AlbumPage.java +22 −7 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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(); } Loading @@ -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; } Loading @@ -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); } } Loading
src/com/android/gallery3d/app/AlbumSetDataLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ public class AlbumSetDataLoader { if (mLoadingListener != null) mLoadingListener.onLoadingStarted(); return; case MSG_LOAD_FINISH: if (mLoadingListener != null) mLoadingListener.onLoadingFinished(); if (mLoadingListener != null) mLoadingListener.onLoadingFinished(false); return; } } Loading
src/com/android/gallery3d/app/AlbumSetPage.java +1 −1 Original line number Diff line number Diff line Loading @@ -734,7 +734,7 @@ public class AlbumSetPage extends ActivityState implements } @Override public void onLoadingFinished() { public void onLoadingFinished(boolean loadingFailed) { clearLoadingBit(BIT_LOADING_RELOAD); } } Loading
src/com/android/gallery3d/app/LoadingListener.java +6 −1 Original line number Diff line number Diff line Loading @@ -18,5 +18,10 @@ package com.android.gallery3d.app; public interface LoadingListener { public void onLoadingStarted(); public void onLoadingFinished(); /** * Called when loading is complete or no further progress can be made. * * @param loadingFailed true if data source cannot provide requested data */ public void onLoadingFinished(boolean loadingFailed); }