A class for managing and starting requests for Glide. Can use activity, fragment and connectivity lifecycle events to intelligently stop, start, and restart requests. Retrieve either by instantiating a new object, or to take advantage built in Activity and Fragment lifecycle handling, use the static
| 55 | * @see Glide#with(Context) |
| 56 | */ |
| 57 | public class RequestManager |
| 58 | implements ComponentCallbacks2, LifecycleListener, ModelTypes<RequestBuilder<Drawable>> { |
| 59 | private static final RequestOptions DECODE_TYPE_BITMAP = decodeTypeOf(Bitmap.class).lock(); |
| 60 | private static final RequestOptions DECODE_TYPE_GIF = decodeTypeOf(GifDrawable.class).lock(); |
| 61 | private static final RequestOptions DOWNLOAD_ONLY_OPTIONS = |
| 62 | diskCacheStrategyOf(DiskCacheStrategy.DATA).priority(Priority.LOW).skipMemoryCache(true); |
| 63 | |
| 64 | protected final Glide glide; |
| 65 | protected final Context context; |
| 66 | |
| 67 | @SuppressWarnings("WeakerAccess") |
| 68 | @Synthetic |
| 69 | final Lifecycle lifecycle; |
| 70 | |
| 71 | @GuardedBy("this") |
| 72 | private final RequestTracker requestTracker; |
| 73 | |
| 74 | @GuardedBy("this") |
| 75 | private final RequestManagerTreeNode treeNode; |
| 76 | |
| 77 | @GuardedBy("this") |
| 78 | private final TargetTracker targetTracker = new TargetTracker(); |
| 79 | |
| 80 | private final Runnable addSelfToLifecycle = |
| 81 | new Runnable() { |
| 82 | @Override |
| 83 | public void run() { |
| 84 | lifecycle.addListener(RequestManager.this); |
| 85 | } |
| 86 | }; |
| 87 | private final ConnectivityMonitor connectivityMonitor; |
| 88 | // Adding default listeners should be much less common than starting new requests. We want |
| 89 | // some way of making sure that requests don't mutate our listeners without creating a new copy of |
| 90 | // the list each time a request is started. |
| 91 | private final CopyOnWriteArrayList<RequestListener<Object>> defaultRequestListeners; |
| 92 | |
| 93 | @GuardedBy("this") |
| 94 | private RequestOptions requestOptions; |
| 95 | |
| 96 | private boolean pauseAllRequestsOnTrimMemoryModerate; |
| 97 | |
| 98 | private boolean clearOnStop; |
| 99 | |
| 100 | public RequestManager( |
| 101 | @NonNull Glide glide, |
| 102 | @NonNull Lifecycle lifecycle, |
| 103 | @NonNull RequestManagerTreeNode treeNode, |
| 104 | @NonNull Context context) { |
| 105 | this( |
| 106 | glide, |
| 107 | lifecycle, |
| 108 | treeNode, |
| 109 | new RequestTracker(), |
| 110 | glide.getConnectivityMonitorFactory(), |
| 111 | context); |
| 112 | } |
| 113 | |
| 114 | // Our usage is safe here. |
nothing calls this directly
no test coverage detected