Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57cbaa1e authored by Hung-ying Tyan's avatar Hung-ying Tyan
Browse files

Request sync when there's no mediaItem in a mediaSet.

This is to fix the problem where media items haven't been sync'ed when the album
set or album is viewed for the first time.

+ Add MediaSet.SyncListener.
+ Make AlbumPage and AlbumSetPage implement SyncListener.
+ Implement requestSync() for ComboAlbum and ComboAlbumSet.
+ add ActivityState.isDestroyed(). This also fixes the problem where
  StateManager.finishState() may be called twice.

Bug: 5337899
Change-Id: I25364c3ac25721a2650701c5d7931bfb6daa9303
parent eaa750f6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -199,6 +199,11 @@
    <!-- This toast message is shown when network connection is lost while doing clustering -->
    <string name="no_connectivity">Some locations couldn\'t be identified due to network problems.</string>

    <!-- This toast message is shown when failed to load the album data. [CHAR LIMIT=NONE] -->
    <string name="sync_album_error">Failed to download the photos in this album. Please retry later.</string>
    <!-- This toast message is shown when failed to load the album list data. [CHAR LIMIT=NONE] -->
    <string name="sync_album_set_error">Failed to download the list of albums. Please retry later.</string>

    <!-- The title of the menu item to let user choose the which portion of
         the media items the user wants to see. When pressed, a submenu will
         appear and user can choose one of "show images only",
+7 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ abstract public class ActivityState {
        ResultEntry next;
    }

    private boolean mDestroyed = false;

    protected ActivityState() {
    }

@@ -139,5 +141,10 @@ abstract public class ActivityState {
    }

    protected void onDestroy() {
        mDestroyed = true;
    }

    boolean isDestroyed() {
        return mDestroyed;
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -147,7 +147,6 @@ public class AlbumDataAdapter implements AlbumView.Model {
            mContentStart = contentStart;
            mContentEnd = contentEnd;
        }
        MediaItem[] data = mData;
        long[] itemVersion = mItemVersion;
        long[] setVersion = mSetVersion;
        if (contentStart >= end || start >= contentEnd) {
@@ -168,9 +167,6 @@ public class AlbumDataAdapter implements AlbumView.Model {
    public void setActiveWindow(int start, int end) {
        if (start == mActiveStart && end == mActiveEnd) return;

        mActiveStart = start;
        mActiveEnd = end;

        Utils.assertTrue(start <= end
                && end - start <= mData.length && end <= mSize);

+22 −3
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ import com.android.gallery3d.util.GalleryUtils;
import java.util.Random;

public class AlbumPage extends ActivityState implements GalleryActionBar.ClusterRunner,
        SelectionManager.SelectionListener {
        SelectionManager.SelectionListener, MediaSet.SyncListener {
    @SuppressWarnings("unused")
    private static final String TAG = "AlbumPage";

@@ -102,7 +102,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
    private ProgressDialog mProgressDialog;
    private Future<?> mPendingTask;

    private Future<Void> mSyncTask = null;
    private Future<Integer> mSyncTask = null;

    private GLView mRootPane = new GLView() {
        private float mMatrix[] = new float[16];
@@ -360,6 +360,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mAlbumDataAdapter != null) {
            mAlbumDataAdapter.setLoadingListener(null);
        }
@@ -566,6 +567,24 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
        mActionModeHandler.updateSupportedOperation(path, selected);
    }

    @Override
    public void onSyncDone(final MediaSet mediaSet, final int resultCode) {
        Log.d(TAG, "onSyncDone: " + Utils.maskDebugInfo(mediaSet.getName()) + " result="
                + resultCode);
        ((Activity) mActivity).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (!mIsActive) return;
                mediaSet.notifyContentChanged(); // force reload to handle spinner

                if (resultCode == MediaSet.SYNC_RESULT_ERROR) {
                    Toast.makeText((Context) mActivity, R.string.sync_album_error,
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    private class MyLoadingListener implements LoadingListener {
        @Override
        public void onLoadingStarted() {
@@ -577,7 +596,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
            if (!mIsActive) return;
            if (mAlbumDataAdapter.size() == 0) {
                if (mSyncTask == null) {
                    mSyncTask = mMediaSet.requestSync();
                    mSyncTask = mMediaSet.requestSync(AlbumPage.this);
                }
                if (mSyncTask.isDone()){
                    Toast.makeText((Context) mActivity,
+44 −6
Original line number Diff line number Diff line
@@ -54,10 +54,12 @@ import com.android.gallery3d.ui.PositionRepository.Position;
import com.android.gallery3d.ui.SelectionManager;
import com.android.gallery3d.ui.SlotView;
import com.android.gallery3d.ui.StaticBackground;
import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.GalleryUtils;

public class AlbumSetPage extends ActivityState implements
        SelectionManager.SelectionListener, GalleryActionBar.ClusterRunner,
        EyePosition.EyePositionListener {
        EyePosition.EyePositionListener, MediaSet.SyncListener {
    @SuppressWarnings("unused")
    private static final String TAG = "AlbumSetPage";

@@ -100,6 +102,8 @@ public class AlbumSetPage extends ActivityState implements
    private float mY;
    private float mZ;

    private Future<Integer> mSyncTask = null;

    private final GLView mRootPane = new GLView() {
        private final float mMatrix[] = new float[16];

@@ -291,6 +295,10 @@ public class AlbumSetPage extends ActivityState implements
        DetailsHelper.pause();
        GalleryActionBar actionBar = mActivity.getGalleryActionBar();
        if (actionBar != null) actionBar.hideClusterMenu();
        if (mSyncTask != null) {
            mSyncTask.cancel();
            mSyncTask = null;
        }
    }

    @Override
@@ -552,6 +560,26 @@ public class AlbumSetPage extends ActivityState implements
        mDetailsHelper.show();
    }

    @Override
    public void onSyncDone(final MediaSet mediaSet, final int resultCode) {
        if (resultCode == MediaSet.SYNC_RESULT_ERROR) {
            Log.d(TAG, "onSyncDone: " + Utils.maskDebugInfo(mediaSet.getName()) + " result="
                    + resultCode);
        }
        ((Activity) mActivity).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (!mIsActive) return;
                mediaSet.notifyContentChanged(); // force reload to handle spinner

                if (resultCode == MediaSet.SYNC_RESULT_ERROR) {
                    Toast.makeText((Context) mActivity, R.string.sync_album_set_error,
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    private class MyLoadingListener implements LoadingListener {
        public void onLoadingStarted() {
            GalleryUtils.setSpinnerVisibility((Activity) mActivity, true);
@@ -559,11 +587,21 @@ public class AlbumSetPage extends ActivityState implements

        public void onLoadingFinished() {
            if (!mIsActive) return;

            if (mSyncTask == null) {
                // Request sync in case the mediaSet hasn't been sync'ed before.
                mSyncTask = mMediaSet.requestSync(AlbumSetPage.this);
            }
            if (mSyncTask.isDone()){
                // The mediaSet is in sync. Turn off the loading indicator.
                GalleryUtils.setSpinnerVisibility((Activity) mActivity, false);
            if (mAlbumSetDataAdapter.size() == 0) {

                // 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)
                        && (mActivity.getStateManager().getStateCount() > 1)) {
                    Toast.makeText((Context) mActivity,
                            R.string.empty_album, Toast.LENGTH_LONG).show();
                if (mActivity.getStateManager().getStateCount() > 1) {
                    mActivity.getStateManager().finishState(AlbumSetPage.this);
                }
            }
Loading