1 package com.bumptech.glide.manager; 2 3 import android.annotation.SuppressLint; 4 import android.annotation.TargetApi; 5 import android.app.Fragment; 6 import android.os.Build; 7 8 import com.bumptech.glide.RequestManager; 9 10 /** 11 * A view-less {@link android.app.Fragment} used to safely store an {@link com.bumptech.glide.RequestManager} that 12 * can be used to start, stop and manage Glide requests started for targets the fragment or activity this fragment is a 13 * child of. 14 * 15 * @see com.bumptech.glide.manager.SupportRequestManagerFragment 16 * @see com.bumptech.glide.manager.RequestManagerRetriever 17 * @see com.bumptech.glide.RequestManager 18 */ 19 @TargetApi(Build.VERSION_CODES.HONEYCOMB) 20 public class RequestManagerFragment extends Fragment { 21 private final ActivityFragmentLifecycle lifecycle; 22 private RequestManager requestManager; 23 RequestManagerFragment()24 public RequestManagerFragment() { 25 this(new ActivityFragmentLifecycle()); 26 } 27 28 // For testing only. 29 @SuppressLint("ValidFragment") RequestManagerFragment(ActivityFragmentLifecycle lifecycle)30 RequestManagerFragment(ActivityFragmentLifecycle lifecycle) { 31 this.lifecycle = lifecycle; 32 } 33 34 /** 35 * Sets the current {@link com.bumptech.glide.RequestManager}. 36 * 37 * @param requestManager The request manager to use. 38 */ setRequestManager(RequestManager requestManager)39 public void setRequestManager(RequestManager requestManager) { 40 this.requestManager = requestManager; 41 } 42 getGlideLifecycle()43 ActivityFragmentLifecycle getGlideLifecycle() { 44 return lifecycle; 45 } 46 47 /** 48 * Returns the current {@link com.bumptech.glide.RequestManager} or null if none exists. 49 */ getRequestManager()50 public RequestManager getRequestManager() { 51 return requestManager; 52 } 53 54 @Override onStart()55 public void onStart() { 56 super.onStart(); 57 lifecycle.onStart(); 58 } 59 60 @Override onStop()61 public void onStop() { 62 super.onStop(); 63 lifecycle.onStop(); 64 } 65 66 @Override onDestroy()67 public void onDestroy() { 68 super.onDestroy(); 69 lifecycle.onDestroy(); 70 } 71 } 72