Fix the attachement view layout.
The progress bar is not meant to be GONE. Encapsulated the progress view in MessageViewAttachmentInfo to make sure that won't happen. Bug 3417034 Change-Id: I1efee089cc7921f4428a38fcbcdc2e8aa3cec9fd
This commit is contained in:
parent
8c89674b64
commit
88c8044586
@ -751,9 +751,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
} else {
|
} else {
|
||||||
attachment.cancelButton.setVisibility(View.VISIBLE);
|
attachment.cancelButton.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
ProgressBar bar = attachment.progressView;
|
attachment.showProgressIndeterminate();
|
||||||
bar.setVisibility(View.VISIBLE);
|
|
||||||
bar.setIndeterminate(true);
|
|
||||||
mController.loadAttachment(attachment.mId, mMessageId, mAccountId);
|
mController.loadAttachment(attachment.mId, mMessageId, mAccountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,8 +760,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
if (AttachmentDownloadService.cancelQueuedAttachment(attachment.mId)) {
|
if (AttachmentDownloadService.cancelQueuedAttachment(attachment.mId)) {
|
||||||
attachment.loadButton.setVisibility(View.VISIBLE);
|
attachment.loadButton.setVisibility(View.VISIBLE);
|
||||||
attachment.cancelButton.setVisibility(View.GONE);
|
attachment.cancelButton.setVisibility(View.GONE);
|
||||||
ProgressBar bar = attachment.progressView;
|
attachment.hideProgress();
|
||||||
bar.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1116,18 +1113,22 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
* handling, as well as our determination of suitability for viewing (based on availability of
|
* handling, as well as our determination of suitability for viewing (based on availability of
|
||||||
* a viewer app) and saving (based upon the presence of external storage)
|
* a viewer app) and saving (based upon the presence of external storage)
|
||||||
*/
|
*/
|
||||||
static class MessageViewAttachmentInfo extends AttachmentInfo {
|
private static class MessageViewAttachmentInfo extends AttachmentInfo {
|
||||||
Button openButton;
|
private Button openButton;
|
||||||
Button saveButton;
|
private Button saveButton;
|
||||||
Button loadButton;
|
private Button loadButton;
|
||||||
Button infoButton;
|
private Button infoButton;
|
||||||
Button cancelButton;
|
private Button cancelButton;
|
||||||
ImageView iconView;
|
private ImageView iconView;
|
||||||
ProgressBar progressView;
|
|
||||||
boolean loaded;
|
|
||||||
|
|
||||||
private MessageViewAttachmentInfo(Context context, Attachment attachment) {
|
// Don't touch it directly from the outer class.
|
||||||
|
private ProgressBar mProgressView;
|
||||||
|
private boolean loaded;
|
||||||
|
|
||||||
|
private MessageViewAttachmentInfo(Context context, Attachment attachment,
|
||||||
|
ProgressBar progressView) {
|
||||||
super(context, attachment);
|
super(context, attachment);
|
||||||
|
mProgressView = progressView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1142,9 +1143,35 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
infoButton = oldInfo.infoButton;
|
infoButton = oldInfo.infoButton;
|
||||||
cancelButton = oldInfo.cancelButton;
|
cancelButton = oldInfo.cancelButton;
|
||||||
iconView = oldInfo.iconView;
|
iconView = oldInfo.iconView;
|
||||||
progressView = oldInfo.progressView;
|
mProgressView = oldInfo.mProgressView;
|
||||||
loaded = oldInfo.loaded;
|
loaded = oldInfo.loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideProgress() {
|
||||||
|
// Don't use GONE, which'll break the layout.
|
||||||
|
if (mProgressView.getVisibility() != View.INVISIBLE) {
|
||||||
|
mProgressView.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showProgress(int progress) {
|
||||||
|
if (mProgressView.getVisibility() != View.VISIBLE) {
|
||||||
|
mProgressView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (mProgressView.isIndeterminate()) {
|
||||||
|
mProgressView.setIndeterminate(false);
|
||||||
|
}
|
||||||
|
mProgressView.setProgress(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showProgressIndeterminate() {
|
||||||
|
if (mProgressView.getVisibility() != View.VISIBLE) {
|
||||||
|
mProgressView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (!mProgressView.isIndeterminate()) {
|
||||||
|
mProgressView.setIndeterminate(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1172,7 +1199,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
Button loadButton = attachmentInfo.loadButton;
|
Button loadButton = attachmentInfo.loadButton;
|
||||||
Button infoButton = attachmentInfo.infoButton;
|
Button infoButton = attachmentInfo.infoButton;
|
||||||
Button cancelButton = attachmentInfo.cancelButton;
|
Button cancelButton = attachmentInfo.cancelButton;
|
||||||
ProgressBar attachmentProgress = attachmentInfo.progressView;
|
|
||||||
|
|
||||||
if (!attachmentInfo.mAllowView) {
|
if (!attachmentInfo.mAllowView) {
|
||||||
openButton.setVisibility(View.GONE);
|
openButton.setVisibility(View.GONE);
|
||||||
@ -1183,7 +1209,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
|
|
||||||
if (!attachmentInfo.mAllowView && !attachmentInfo.mAllowSave) {
|
if (!attachmentInfo.mAllowView && !attachmentInfo.mAllowSave) {
|
||||||
// This attachment may never be viewed or saved, so block everything
|
// This attachment may never be viewed or saved, so block everything
|
||||||
attachmentProgress.setVisibility(View.GONE);
|
attachmentInfo.hideProgress();
|
||||||
openButton.setVisibility(View.GONE);
|
openButton.setVisibility(View.GONE);
|
||||||
saveButton.setVisibility(View.GONE);
|
saveButton.setVisibility(View.GONE);
|
||||||
loadButton.setVisibility(View.GONE);
|
loadButton.setVisibility(View.GONE);
|
||||||
@ -1194,8 +1220,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
// Note that for POP3 messages, the user will only see "Open" and "Save",
|
// Note that for POP3 messages, the user will only see "Open" and "Save",
|
||||||
// because the entire message is loaded before being shown.
|
// because the entire message is loaded before being shown.
|
||||||
// Hide "Load" and "Info", show "View" and "Save"
|
// Hide "Load" and "Info", show "View" and "Save"
|
||||||
attachmentProgress.setVisibility(View.VISIBLE);
|
attachmentInfo.showProgress(100);
|
||||||
attachmentProgress.setProgress(100);
|
|
||||||
if (attachmentInfo.mAllowSave) {
|
if (attachmentInfo.mAllowSave) {
|
||||||
saveButton.setVisibility(View.VISIBLE);
|
saveButton.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -1234,8 +1259,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
// If the attachment is queued, show the indeterminate progress bar. From this point,.
|
// If the attachment is queued, show the indeterminate progress bar. From this point,.
|
||||||
// any progress changes will cause this to be replaced by the normal progress bar
|
// any progress changes will cause this to be replaced by the normal progress bar
|
||||||
if (AttachmentDownloadService.isAttachmentQueued(attachmentInfo.mId)) {
|
if (AttachmentDownloadService.isAttachmentQueued(attachmentInfo.mId)) {
|
||||||
attachmentProgress.setVisibility(View.VISIBLE);
|
attachmentInfo.showProgressIndeterminate();
|
||||||
attachmentProgress.setIndeterminate(true);
|
|
||||||
loadButton.setVisibility(View.GONE);
|
loadButton.setVisibility(View.GONE);
|
||||||
cancelButton.setVisibility(View.VISIBLE);
|
cancelButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
@ -1256,9 +1280,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
* @param attachment A single attachment loaded from the provider
|
* @param attachment A single attachment loaded from the provider
|
||||||
*/
|
*/
|
||||||
private void addAttachment(Attachment attachment) {
|
private void addAttachment(Attachment attachment) {
|
||||||
MessageViewAttachmentInfo attachmentInfo =
|
|
||||||
new MessageViewAttachmentInfo(mContext, attachment);
|
|
||||||
|
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
View view = inflater.inflate(R.layout.message_view_attachment, null);
|
View view = inflater.inflate(R.layout.message_view_attachment, null);
|
||||||
|
|
||||||
@ -1272,6 +1293,9 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
Button cancelButton = (Button)view.findViewById(R.id.cancel);
|
Button cancelButton = (Button)view.findViewById(R.id.cancel);
|
||||||
ProgressBar attachmentProgress = (ProgressBar)view.findViewById(R.id.progress);
|
ProgressBar attachmentProgress = (ProgressBar)view.findViewById(R.id.progress);
|
||||||
|
|
||||||
|
MessageViewAttachmentInfo attachmentInfo = new MessageViewAttachmentInfo(
|
||||||
|
mContext, attachment, attachmentProgress);
|
||||||
|
|
||||||
// Check whether the attachment already exists
|
// Check whether the attachment already exists
|
||||||
if (Utility.attachmentExists(mContext, attachment)) {
|
if (Utility.attachmentExists(mContext, attachment)) {
|
||||||
attachmentInfo.loaded = true;
|
attachmentInfo.loaded = true;
|
||||||
@ -1283,7 +1307,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
attachmentInfo.infoButton = infoButton;
|
attachmentInfo.infoButton = infoButton;
|
||||||
attachmentInfo.cancelButton = cancelButton;
|
attachmentInfo.cancelButton = cancelButton;
|
||||||
attachmentInfo.iconView = attachmentIcon;
|
attachmentInfo.iconView = attachmentIcon;
|
||||||
attachmentInfo.progressView = attachmentProgress;
|
|
||||||
|
|
||||||
updateAttachmentButtons(attachmentInfo);
|
updateAttachmentButtons(attachmentInfo);
|
||||||
|
|
||||||
@ -1568,7 +1591,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
}
|
}
|
||||||
attachment.cancelButton.setVisibility(View.GONE);
|
attachment.cancelButton.setVisibility(View.GONE);
|
||||||
attachment.loadButton.setVisibility(View.VISIBLE);
|
attachment.loadButton.setVisibility(View.VISIBLE);
|
||||||
attachment.progressView.setVisibility(View.INVISIBLE);
|
attachment.hideProgress();
|
||||||
|
|
||||||
final String error;
|
final String error;
|
||||||
if (result.getCause() instanceof IOException) {
|
if (result.getCause() instanceof IOException) {
|
||||||
@ -1586,15 +1609,10 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||||||
private void showAttachmentProgress(long attachmentId, int progress) {
|
private void showAttachmentProgress(long attachmentId, int progress) {
|
||||||
MessageViewAttachmentInfo attachment = findAttachmentInfo(attachmentId);
|
MessageViewAttachmentInfo attachment = findAttachmentInfo(attachmentId);
|
||||||
if (attachment != null) {
|
if (attachment != null) {
|
||||||
ProgressBar bar = attachment.progressView;
|
|
||||||
if (progress == 0) {
|
if (progress == 0) {
|
||||||
// When the download starts, we can get rid of the indeterminate bar
|
|
||||||
bar.setVisibility(View.VISIBLE);
|
|
||||||
bar.setIndeterminate(false);
|
|
||||||
// And we're not implementing stop of in-progress downloads
|
|
||||||
attachment.cancelButton.setVisibility(View.GONE);
|
attachment.cancelButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
bar.setProgress(progress);
|
attachment.showProgress(progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user