content: package com.trello.rxlifecycle.components;
  
  import android.app.Fragment;
  import android.os.Bundle;
  import android.support.annotation.CallSuper;
  import android.support.annotation.CheckResult;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.view.View;
  import com.trello.rxlifecycle.LifecycleProvider;
  import com.trello.rxlifecycle.LifecycleTransformer;
  import com.trello.rxlifecycle.RxLifecycle;
  import com.trello.rxlifecycle.android.FragmentEvent;
  import com.trello.rxlifecycle.android.RxLifecycleAndroid;
  import rx.Observable;
  import rx.subjects.BehaviorSubject;
  
  public class RxFragment extends Fragment implements LifecycleProvider<FragmentEvent> {
  
      private final BehaviorSubject<FragmentEvent> lifecycleSubject = BehaviorSubject.create();
  
      @Override
      @NonNull
      @CheckResult
      public final Observable<FragmentEvent> lifecycle() {
          return lifecycleSubject.asObservable();
      }
  
      @Override
      @NonNull
      @CheckResult
      public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull FragmentEvent event) {
          return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
      }
  
      @Override
      @NonNull
      @CheckResult
      public final <T> LifecycleTransformer<T> bindToLifecycle() {
          return RxLifecycleAndroid.bindFragment(lifecycleSubject);
      }
  
      @Override
      @CallSuper
      public void onAttach(android.app.Activity activity) {
          super.onAttach(activity);
          lifecycleSubject.onNext(FragmentEvent.ATTACH);
      }
  
      @Override
      @CallSuper
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          lifecycleSubject.onNext(FragmentEvent.CREATE);
      }
  
      @Override
      @CallSuper
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
      }
  
      @Override
      @CallSuper
      public void onStart() {
          super.onStart();
          lifecycleSubject.onNext(FragmentEvent.START);
      }
  
      @Override
      @CallSuper
      public void onResume() {
          super.onResume();
          lifecycleSubject.onNext(FragmentEvent.RESUME);
      }
  
      @Override
      @CallSuper
      public void onPause() {
          lifecycleSubject.onNext(FragmentEvent.PAUSE);
          super.onPause();
      }
  
      @Override
      @CallSuper
      public void onStop() {
          lifecycleSubject.onNext(FragmentEvent.STOP);
          super.onStop();
      }
  
      @Override
      @CallSuper
      public void onDestroyView() {
          lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW);
          super.onDestroyView();
      }
  
      @Override
      @CallSuper
      public void onDestroy() {
          lifecycleSubject.onNext(FragmentEvent.DESTROY);
          super.onDestroy();
      }
  
      @Override
      @CallSuper
      public void onDetach() {
          lifecycleSubject.onNext(FragmentEvent.DETACH);
          super.onDetach();
      }
  }
  