aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/java/com/bumptech
diff options
context:
space:
mode:
authorSam Judd <judds@google.com>2014-09-09 18:49:35 -0700
committerSam Judd <judds@google.com>2014-09-12 09:48:25 -0700
commit36d52a4b762f98482163e38c68a324ae20392e7d (patch)
treeaffcb69329d3fbe365cff3602a41a83acae0a6f8 /library/src/main/java/com/bumptech
parente0239113cb498388e7c46664df6490335de6bb84 (diff)
downloadglide-36d52a4b762f98482163e38c68a324ae20392e7d.tar.gz
Don't restart cancelled requests.
Fixes #128
Diffstat (limited to 'library/src/main/java/com/bumptech')
-rw-r--r--library/src/main/java/com/bumptech/glide/manager/RequestTracker.java19
-rw-r--r--library/src/main/java/com/bumptech/glide/request/GenericRequest.java24
-rw-r--r--library/src/main/java/com/bumptech/glide/request/Request.java21
-rw-r--r--library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java16
4 files changed, 64 insertions, 16 deletions
diff --git a/library/src/main/java/com/bumptech/glide/manager/RequestTracker.java b/library/src/main/java/com/bumptech/glide/manager/RequestTracker.java
index 97e0b077..1fed826d 100644
--- a/library/src/main/java/com/bumptech/glide/manager/RequestTracker.java
+++ b/library/src/main/java/com/bumptech/glide/manager/RequestTracker.java
@@ -54,8 +54,8 @@ public class RequestTracker {
public void pauseRequests() {
isPaused = true;
for (Request request : requests) {
- if (!request.isComplete() && !request.isFailed()) {
- request.clear();
+ if (request.isRunning()) {
+ request.pause();
}
}
}
@@ -66,7 +66,7 @@ public class RequestTracker {
public void resumeRequests() {
isPaused = false;
for (Request request : requests) {
- if (!request.isComplete() && !request.isRunning()) {
+ if (!request.isComplete() && !request.isCancelled() && !request.isRunning()) {
request.begin();
}
}
@@ -86,16 +86,9 @@ public class RequestTracker {
*/
public void restartRequests() {
for (Request request : requests) {
- if (request.isFailed()) {
- if (isPaused) {
- // Ensure the request will be restarted in onResume.
- request.clear();
- } else {
- request.begin();
- }
- } else if (!request.isComplete()) {
- // Make sure we re-queue the request, we may just have not received the failure yet.
- request.clear();
+ if (!request.isComplete() && !request.isCancelled()) {
+ // Ensure the request will be restarted in onResume.
+ request.pause();
if (!isPaused) {
request.begin();
}
diff --git a/library/src/main/java/com/bumptech/glide/request/GenericRequest.java b/library/src/main/java/com/bumptech/glide/request/GenericRequest.java
index d20643bc..999e464b 100644
--- a/library/src/main/java/com/bumptech/glide/request/GenericRequest.java
+++ b/library/src/main/java/com/bumptech/glide/request/GenericRequest.java
@@ -40,12 +40,20 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
private static final double TO_MEGABYTE = 1d / (1024d * 1024d);
private enum Status {
+ /** Created but not yet running. */
PENDING,
+ /** In the process of fetching media. */
RUNNING,
+ /** Waiting for a callback given to the Target to be called to determine target dimensions. */
WAITING_FOR_SIZE,
+ /** Finished loading media successfully. */
COMPLETE,
+ /** Failed to load media. */
FAILED,
+ /** Cancelled by the user, may not be restarted. */
CANCELLED,
+ /** Temporarily paused by the system, may be restarted. */
+ PAUSED,
}
private int placeholderResourceId;
@@ -298,6 +306,17 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
}
}
+ @Override
+ public boolean isPaused() {
+ return status == Status.PAUSED;
+ }
+
+ @Override
+ public void pause() {
+ clear();
+ status = Status.PAUSED;
+ }
+
private void releaseResource(Resource resource) {
engine.release(resource);
this.resource = null;
@@ -319,6 +338,11 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
return status == Status.COMPLETE;
}
+ @Override
+ public boolean isCancelled() {
+ return status == Status.CANCELLED;
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/library/src/main/java/com/bumptech/glide/request/Request.java b/library/src/main/java/com/bumptech/glide/request/Request.java
index 837470bf..b1c4e917 100644
--- a/library/src/main/java/com/bumptech/glide/request/Request.java
+++ b/library/src/main/java/com/bumptech/glide/request/Request.java
@@ -11,22 +11,37 @@ public interface Request {
public void begin();
/**
- * Prevents any bitmaps being loaded from previous requests, releases any resources held by this request and
- * displays the current placeholder if one was provided.
+ * Identical to {@link #clear()} except that the request may later be restarted.
+ */
+ public void pause();
+
+ /**
+ * Prevents any bitmaps being loaded from previous requests, releases any resources held by this request,
+ * displays the current placeholder if one was provided, and marks the request as having been cancelled.
*/
public void clear();
/**
+ * Returns true if this request is paused and may be restarted.
+ */
+ public boolean isPaused();
+
+ /**
* Returns true if this request is running and has not completed or failed.
*/
public boolean isRunning();
/**
- * Returns true if the request has successfully completed.
+ * Returns true if the request has completed successfully.
*/
public boolean isComplete();
/**
+ * Returns true if the request has been cancelled.
+ */
+ public boolean isCancelled();
+
+ /**
* Returns true if the request has failed.
*/
public boolean isFailed();
diff --git a/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java b/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java
index 5c5d6b5a..d7033e45 100644
--- a/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java
+++ b/library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java
@@ -57,6 +57,12 @@ public class ThumbnailRequestCoordinator implements RequestCoordinator, Request
}
}
+ @Override
+ public void pause() {
+ full.pause();
+ thumb.pause();
+ }
+
/**
* {@inheritDoc}
*/
@@ -66,6 +72,11 @@ public class ThumbnailRequestCoordinator implements RequestCoordinator, Request
full.clear();
}
+ @Override
+ public boolean isPaused() {
+ return full.isPaused();
+ }
+
/**
* Returns true if the full request is still running.
*/
@@ -82,6 +93,11 @@ public class ThumbnailRequestCoordinator implements RequestCoordinator, Request
return full.isComplete();
}
+ @Override
+ public boolean isCancelled() {
+ return full.isCancelled();
+ }
+
/**
* Returns true if the full request has failed.
*/