Merge "Showing multiple photos in the photo viewer." into jb-ub-mail
diff --git a/src/com/android/mail/browse/MessageFooterView.java b/src/com/android/mail/browse/MessageFooterView.java
index a4c5e13..3b8c2be 100644
--- a/src/com/android/mail/browse/MessageFooterView.java
+++ b/src/com/android/mail/browse/MessageFooterView.java
@@ -132,6 +132,7 @@
}
private void renderAttachments(List<Attachment> attachments) {
+ int index = 0;
for (Attachment attachment : attachments) {
MessageHeaderAttachment attachView = (MessageHeaderAttachment) findViewWithTag(
attachment.uri);
@@ -142,7 +143,8 @@
addView(attachView);
}
- attachView.render(attachment);
+ attachView.render(attachment, mMessageHeaderItem.message.attachmentListUri, index);
+ index++;
}
}
diff --git a/src/com/android/mail/browse/MessageHeaderAttachment.java b/src/com/android/mail/browse/MessageHeaderAttachment.java
index cf762e6..3dc8344 100644
--- a/src/com/android/mail/browse/MessageHeaderAttachment.java
+++ b/src/com/android/mail/browse/MessageHeaderAttachment.java
@@ -71,10 +71,12 @@
private Attachment mAttachment;
private ImageView mIcon;
private ImageView.ScaleType mIconScaleType;
+ private int mPhotoIndex;
private TextView mTitle;
private TextView mSubTitle;
private String mAttachmentSizeText;
private String mDisplayType;
+ private Uri mAttachmentsListUri;
private ProgressDialog mViewProgressDialog;
private AttachmentCommandHandler mCommandHandler;
private ProgressBar mProgress;
@@ -203,9 +205,11 @@
* cause sub-views to update.
*
*/
- public void render(Attachment attachment) {
+ public void render(Attachment attachment, Uri attachmentsListUri, int index) {
final Attachment prevAttachment = mAttachment;
mAttachment = attachment;
+ mAttachmentsListUri = attachmentsListUri;
+ mPhotoIndex = index;
LogUtils.d(LOG_TAG, "got attachment list row: name=%s state/dest=%d/%d dled=%d" +
" contentUri=%s MIME=%s", attachment.name, attachment.state,
@@ -459,7 +463,8 @@
final PhotoViewIntentBuilder builder =
Intents.newPhotoViewActivityIntentBuilder(getContext());
builder.setAlbumName(mAttachment.name)
- .setResolvedPhotoUri(mAttachment.contentUri.toString());
+ .setPhotosUri(mAttachmentsListUri.toString())
+ .setPhotoIndex(mPhotoIndex);
getContext().startActivity(builder.build());
return;
diff --git a/src/com/android/mail/photo/Intents.java b/src/com/android/mail/photo/Intents.java
index 5ca4f75..4bd204f 100644
--- a/src/com/android/mail/photo/Intents.java
+++ b/src/com/android/mail/photo/Intents.java
@@ -156,7 +156,8 @@
/** Build the intent */
public Intent build() {
if (TextUtils.isEmpty(mPhotosUri) && TextUtils.isEmpty(mResolvedPhotoUri)) {
- throw new IllegalArgumentException("Either PhotosUri or ResolvedPhotoUri must be set.");
+ throw new IllegalArgumentException(
+ "Either PhotosUri or ResolvedPhotoUri must be set.");
}
mIntent.setAction(Intent.ACTION_VIEW);
diff --git a/src/com/android/mail/photo/PhotoViewActivity.java b/src/com/android/mail/photo/PhotoViewActivity.java
index 22f4518..4e0fad8 100644
--- a/src/com/android/mail/photo/PhotoViewActivity.java
+++ b/src/com/android/mail/photo/PhotoViewActivity.java
@@ -506,7 +506,7 @@
final Uri uri =
TextUtils.isEmpty(mResolvedPhotoUri) ?
Uri.parse(mPhotosUri) : Uri.parse(mResolvedPhotoUri);
- return new PhotoPagerLoader(this, uri, mResolvedPhotoUri, mPageHint);
+ return new PhotoPagerLoader(this, uri, mPageHint);
}
return null;
}
diff --git a/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java b/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java
index f54c7c0..f71885c 100644
--- a/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java
+++ b/src/com/android/mail/photo/adapters/BaseCursorPagerAdapter.java
@@ -25,15 +25,17 @@
import android.util.SparseIntArray;
import android.view.View;
+import com.android.mail.providers.UIProvider;
+
import java.util.HashMap;
/**
- * Page adapter for use with an EsCursorLoader. Unlike other cursor adapters, this has no
+ * Page adapter for use with an BaseCursorLoader. Unlike other cursor adapters, this has no
* observers for automatic refresh. Instead, it depends upon external mechanisms to provide
* the update signal.
*/
public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter {
- private static final String TAG = "EsCursorPagerAdapter";
+ private static final String TAG = "BaseCursorPagerAdapter";
Context mContext;
private boolean mDataValid;
@@ -90,7 +92,7 @@
final Integer rowId;
if (moveCursorTo(position)) {
- rowId = mCursor.getInt(mRowIDColumn);
+ rowId = mCursor.getString(mRowIDColumn).hashCode();
} else {
rowId = null;
}
@@ -151,7 +153,7 @@
*/
public long getItemId(int position) {
if (mDataValid && moveCursorTo(position)) {
- return mCursor.getLong(mRowIDColumn);
+ return mCursor.getString(mRowIDColumn).hashCode();
} else {
return 0;
}
@@ -177,7 +179,7 @@
Cursor oldCursor = mCursor;
mCursor = newCursor;
if (newCursor != null) {
- mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
+ mRowIDColumn = UIProvider.ATTACHMENT_URI_COLUMN;
mDataValid = true;
} else {
mRowIDColumn = -1;
@@ -205,7 +207,7 @@
@Override
protected String makeFragmentName(int viewId, int index) {
if (moveCursorTo(index)) {
- return "android:espager:" + viewId + ":" + mCursor.getInt(mRowIDColumn);
+ return "android:pager:" + viewId + ":" + mCursor.getString(mRowIDColumn).hashCode();
} else {
return super.makeFragmentName(viewId, index);
}
@@ -231,7 +233,7 @@
mCursor = c;
mDataValid = cursorPresent;
mContext = context;
- mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
+ mRowIDColumn = cursorPresent ? UIProvider.ATTACHMENT_URI_COLUMN : -1;
}
/**
@@ -248,7 +250,7 @@
mCursor.moveToPosition(-1);
while (mCursor.moveToNext()) {
- final int rowId = mCursor.getInt(mRowIDColumn);
+ final int rowId = mCursor.getString(mRowIDColumn).hashCode();
final int position = mCursor.getPosition();
itemPosition.append(rowId, position);
diff --git a/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java b/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java
index 8ce24fd..ab93bd6 100644
--- a/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java
+++ b/src/com/android/mail/photo/adapters/PhotoPagerAdapter.java
@@ -28,6 +28,7 @@
import com.android.mail.photo.fragments.LoadingFragment;
import com.android.mail.photo.fragments.PhotoViewFragment;
import com.android.mail.photo.provider.PhotoContract.PhotoQuery;
+import com.android.mail.providers.UIProvider;
/**
* Pager adapter for the photo view
@@ -58,14 +59,14 @@
@Override
public Fragment getItem(Context context, Cursor cursor) {
- final long photoId = cursor.getLong(PhotoQuery.INDEX_PHOTO_ID);
- final String photoUrl = cursor.getString(PhotoQuery.INDEX_URI);
+// final long photoId = cursor.getLong(PhotoQuery.INDEX_PHOTO_ID);
+ final String photoUri = cursor.getString(UIProvider.ATTACHMENT_CONTENT_URI_COLUMN);
// create new PhotoViewFragment
final PhotoViewIntentBuilder builder =
Intents.newPhotoViewFragmentIntentBuilder(mContext);
- builder.setPhotoId(photoId)
- .setResolvedPhotoUri(photoUrl)
+ builder
+ .setResolvedPhotoUri(photoUri)
.setAlbumName(mDefaultAlbumName)
.setForceLoadId(mForceLoadId);
diff --git a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java b/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
index 4b88df5..226ac90 100644
--- a/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
+++ b/src/com/android/mail/photo/loaders/PhotoPagerLoader.java
@@ -19,38 +19,26 @@
import android.content.Context;
import android.database.Cursor;
-import android.database.MatrixCursor;
import android.net.Uri;
-import android.text.TextUtils;
-import com.android.mail.photo.provider.PhotoContract.PhotoQuery;
+import com.android.mail.providers.UIProvider;
/**
* Loader for a set of photo IDs.
*/
public class PhotoPagerLoader extends PhotoCursorLoader {
- private String mResolvedPhotoUri;
public PhotoPagerLoader(
- Context context, Uri photosUri, String resolvedPhotoUri, int pageHint) {
+ Context context, Uri photosUri, int pageHint) {
super(context, photosUri, pageHint != LOAD_LIMIT_UNLIMITED, pageHint);
- mResolvedPhotoUri = resolvedPhotoUri;
}
@Override
public Cursor esLoadInBackground() {
Cursor returnCursor = null;
- if (!TextUtils.isEmpty(mResolvedPhotoUri)) {
- returnCursor = new MatrixCursor(PhotoQuery.PROJECTION);
- ((MatrixCursor) returnCursor).newRow()
- .add(0) // _id
- .add(mResolvedPhotoUri);
- return returnCursor;
- }
-
final Uri loaderUri = getLoaderUri();
setUri(loaderUri);
- setProjection(PhotoQuery.PROJECTION);
+ setProjection(UIProvider.ATTACHMENT_PROJECTION);
returnCursor = super.esLoadInBackground();
return returnCursor;