content: //******************************************************************************
  // SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
  //
  // Web: http://www.scichart.com
  // Support: support@scichart.com
  // Sales:   sales@scichart.com
  //
  // ShowcaseExampleBaseFragment.java is part of the SCICHART® Examples. Permission is hereby granted
  // to modify, create derivative works, distribute and publish any part of this source
  // code whether for commercial, private or personal use.
  //
  // The SCICHART® examples are distributed in the hope that they will be useful, but
  // without any warranty. It is provided "AS IS" without warranty of any kind, either
  // expressed or implied.
  //******************************************************************************
  
  package com.scichart.examples.fragments.base;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.viewbinding.ViewBinding;
  
  import com.scichart.examples.fragments.base.ExampleBaseFragment;
  import com.trello.rxlifecycle3.LifecycleProvider;
  import com.trello.rxlifecycle3.LifecycleTransformer;
  import com.trello.rxlifecycle3.RxLifecycle;
  import com.trello.rxlifecycle3.android.FragmentEvent;
  import com.trello.rxlifecycle3.android.RxLifecycleAndroid;
  
  import io.reactivex.Observable;
  import io.reactivex.subjects.BehaviorSubject;
  
  public abstract class ShowcaseExampleBaseFragment<TViewBinding extends ViewBinding> extends ExampleBaseFragment<TViewBinding> implements LifecycleProvider<FragmentEvent> {
      private final BehaviorSubject<FragmentEvent> lifecycleSubject = BehaviorSubject.create();
  
      @Override
      @NonNull
      public Observable<FragmentEvent> lifecycle() {
          return lifecycleSubject;
      }
  
      @Override
      @NonNull
      public <T> LifecycleTransformer<T> bindUntilEvent(@NonNull FragmentEvent event) {
          return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
      }
  
      @Override
      @NonNull
      public <T> LifecycleTransformer<T> bindToLifecycle() {
          return RxLifecycleAndroid.bindFragment(lifecycleSubject);
      }
  
      @Override
      public void onStart() {
          super.onStart();
  
          lifecycleSubject.onNext(FragmentEvent.START);
      }
  
      @Override
      public void onPause() {
          lifecycleSubject.onNext(FragmentEvent.PAUSE);
  
          super.onPause();
      }
  
      @Override
      public void onResume() {
          super.onResume();
  
          lifecycleSubject.onNext(FragmentEvent.RESUME);
      }
  
      @Override
      public void onStop() {
          lifecycleSubject.onNext(FragmentEvent.STOP);
  
          super.onStop();
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
  
          lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
      }
  
      @Override
      public void onDestroyView() {
          lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW);
  
          super.onDestroyView();
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          lifecycleSubject.onNext(FragmentEvent.CREATE);
      }
  
      @Override
      public void onDestroy() {
          lifecycleSubject.onNext(FragmentEvent.DESTROY);
  
          super.onDestroy();
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
  
          lifecycleSubject.onNext(FragmentEvent.ATTACH);
      }
  
      @Override
      public void onDetach() {
          lifecycleSubject.onNext(FragmentEvent.DETACH);
  
          super.onDetach();
      }
  }
  