Several image attachment fixes

Make sure to use the default photo attachment image when an attachment
couldn't be loaded

Don't update the progress bar when only the action bar was meant to be
updated

Don't transition to indeterminate progress bar mode, when we had previously
determined the state.

Bug: 6956516
Change-Id: I086d27689693769fe88313593a46e9610fc1a74c
diff --git a/res/drawable-hdpi/default_image.png b/res/drawable-hdpi/default_image.png
new file mode 100644
index 0000000..43e8744
--- /dev/null
+++ b/res/drawable-hdpi/default_image.png
Binary files differ
diff --git a/res/drawable-mdpi/default_image.png b/res/drawable-mdpi/default_image.png
new file mode 100644
index 0000000..e66e04a
--- /dev/null
+++ b/res/drawable-mdpi/default_image.png
Binary files differ
diff --git a/res/drawable-xhdpi/default_image.png b/res/drawable-xhdpi/default_image.png
new file mode 100644
index 0000000..88118a8
--- /dev/null
+++ b/res/drawable-xhdpi/default_image.png
Binary files differ
diff --git a/src/com/android/mail/photo/MailPhotoViewActivity.java b/src/com/android/mail/photo/MailPhotoViewActivity.java
index 0991513..e25289d 100644
--- a/src/com/android/mail/photo/MailPhotoViewActivity.java
+++ b/src/com/android/mail/photo/MailPhotoViewActivity.java
@@ -184,9 +184,17 @@
         }
 
         updateActionItems();
+    }
+
+    @Override
+    public void onFragmentVisible(PhotoViewFragment fragment) {
+        super.onFragmentVisible(fragment);
+
+        final Attachment attachment = getCurrentAttachment();
         updateProgressAndEmptyViews(fragment, attachment);
     }
 
+
     /**
      * Updates the empty views of the fragment based upon the current
      * state of the attachment.
@@ -195,6 +203,7 @@
      */
     private void updateProgressAndEmptyViews(
             PhotoViewFragment fragment, final Attachment attachment) {
+
         final ProgressBarWrapper progressBar = fragment.getPhotoProgressBar();
         final TextView emptyText = fragment.getEmptyText();
         final ImageView retryButton = fragment.getRetryButton();
@@ -204,7 +213,7 @@
             progressBar.setMax(attachment.size);
             progressBar.setProgress(attachment.downloadedSize);
             progressBar.setIndeterminate(false);
-        } else {
+        } else if (fragment.isProgressBarNeeded()) {
             progressBar.setIndeterminate(true);
         }
 
diff --git a/src/com/android/mail/providers/Attachment.java b/src/com/android/mail/providers/Attachment.java
index fee998d..4488fab 100644
--- a/src/com/android/mail/providers/Attachment.java
+++ b/src/com/android/mail/providers/Attachment.java
@@ -25,6 +25,7 @@
 import com.android.mail.providers.UIProvider.AttachmentDestination;
 import com.android.mail.providers.UIProvider.AttachmentState;
 import com.android.mail.utils.LogTag;
+import com.android.mail.utils.LogUtils;
 import com.google.common.collect.Lists;
 
 import org.json.JSONArray;
@@ -189,6 +190,16 @@
                 originExtras == null ? "" : originExtras, ""));
     }
 
+    @Override
+    public String toString() {
+        try {
+            return toJSON().toString();
+        } catch (JSONException e) {
+            LogUtils.e(LOG_TAG, e, "JSONException in toString");
+            return super.toString();
+        }
+    }
+
     private static Uri parseOptionalUri(String uriString) {
         return uriString == null ? null : Uri.parse(uriString);
     }