Merge "Delay appearance of "stop" button when loading attachments"
This commit is contained in:
commit
26e01b4ad2
@ -663,9 +663,33 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
||||
}
|
||||
}
|
||||
|
||||
private void onLoadAttachment(AttachmentInfo attachment) {
|
||||
private void onLoadAttachment(final AttachmentInfo attachment) {
|
||||
attachment.loadButton.setVisibility(View.GONE);
|
||||
attachment.cancelButton.setVisibility(View.VISIBLE);
|
||||
// If there's nothing in the download queue, we'll probably start right away so wait a
|
||||
// second before showing the cancel button
|
||||
if (AttachmentDownloadService.getQueueSize() == 0) {
|
||||
// Set to invisible; if the button is still in this state one second from now, we'll
|
||||
// assume the download won't start right away, and we make the cancel button visible
|
||||
attachment.cancelButton.setVisibility(View.INVISIBLE);
|
||||
// Create the timed task that will change the button state
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException e) { }
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (attachment.cancelButton.getVisibility() == View.INVISIBLE) {
|
||||
attachment.cancelButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
} else {
|
||||
attachment.cancelButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
ProgressBar bar = attachment.progressView;
|
||||
bar.setVisibility(View.VISIBLE);
|
||||
bar.setIndeterminate(true);
|
||||
|
@ -492,6 +492,10 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
||||
return mDownloadSet.findDownloadRequest(attachmentId) != null;
|
||||
}
|
||||
|
||||
/*package*/ int getSize() {
|
||||
return mDownloadSet.size();
|
||||
}
|
||||
|
||||
/*package*/ boolean dequeue(long attachmentId) {
|
||||
DownloadRequest req = mDownloadSet.findDownloadRequest(attachmentId);
|
||||
if (req != null) {
|
||||
@ -504,6 +508,17 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the service for the number of items in the download queue
|
||||
* @return the number of items queued for download
|
||||
*/
|
||||
public static int getQueueSize() {
|
||||
if (sRunningService != null) {
|
||||
return sRunningService.getSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the service whether a particular attachment is queued for download
|
||||
* @param attachmentId the id of the Attachment (as stored by EmailProvider)
|
||||
|
Loading…
Reference in New Issue
Block a user