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