// Path: app/src/main/java/com/lucilu/rxdynamicsearch/IInjectable.java
// public interface IInjectable {
// 
//     /**
//      * Called when object is ready to be injected.
//      */
//     void onInject();
// }
// 
// Path: app/src/main/java/com/lucilu/rxdynamicsearch/viewmodel/base/ViewModel.java
// public abstract class ViewModel {
// 
//     @Nullable
//     private CompositeSubscription mSubscriptions;
// 
//     /**
//      * Cleans up the view model
//      */
//     public void dispose() {
//         unsubscribeFromDataStore();
//     }
// 
//     /**
//      * Cleans up current subscriptions and subscribes to new events.
//      */
//     public void subscribeToDataStore() {
//         unsubscribeFromDataStore();
//         mSubscriptions = new CompositeSubscription();
//         subscribeToData(mSubscriptions);
//     }
// 
//     private void unsubscribeFromDataStore() {
//         if (mSubscriptions != null) {
//             mSubscriptions.clear();
//             mSubscriptions = null;
//         }
//     }
// 
//     /**
//      * Provides {@link CompositeSubscription} that all bindings should be registered to.
//      *
//      * @param subscription that holds the {@link Subscription}s created by view model
//      */
//     protected abstract void subscribeToData(@NonNull final CompositeSubscription subscription);
// }


import com.lucilu.rxdynamicsearch.IInjectable;
import com.lucilu.rxdynamicsearch.viewmodel.base.ViewModel;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import rx.subscriptions.CompositeSubscription;
package com.lucilu.rxdynamicsearch.fragments.base;




/**
 * This base fragment provides the common functionality to all fragments in the app.
 */
public abstract class BaseFragment extends Fragment implements IInjectable {

    @NonNull
    private final CompositeSubscription mSubscription = new CompositeSubscription();

    @Override
    public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        onInject();

        getViewModel().subscribeToDataStore();
    }

    @Override
    public void onResume() {
        super.onResume();
        onBind(mSubscription);
    }

    @Override
    public void onPause() {
        mSubscription.clear();
        super.onPause();
    }

    @Override
    public void onDestroyView() {
        getViewModel().dispose();
        super.onDestroyView();
    }

    protected abstract void onBind(@NonNull final CompositeSubscription subscription);

    @NonNull
// Path: app/src/main/java/com/lucilu/rxdynamicsearch/IInjectable.java
// public interface IInjectable {
// 
//     /**
//      * Called when object is ready to be injected.
//      */
//     void onInject();
// }
// 
// Path: app/src/main/java/com/lucilu/rxdynamicsearch/viewmodel/base/ViewModel.java
// public abstract class ViewModel {
// 
//     @Nullable
//     private CompositeSubscription mSubscriptions;
// 
//     /**
//      * Cleans up the view model
//      */
//     public void dispose() {
//         unsubscribeFromDataStore();
//     }
// 
//     /**
//      * Cleans up current subscriptions and subscribes to new events.
//      */
//     public void subscribeToDataStore() {
//         unsubscribeFromDataStore();
//         mSubscriptions = new CompositeSubscription();
//         subscribeToData(mSubscriptions);
//     }
// 
//     private void unsubscribeFromDataStore() {
//         if (mSubscriptions != null) {
//             mSubscriptions.clear();
//             mSubscriptions = null;
//         }
//     }
// 
//     /**
//      * Provides {@link CompositeSubscription} that all bindings should be registered to.
//      *
//      * @param subscription that holds the {@link Subscription}s created by view model
//      */
//     protected abstract void subscribeToData(@NonNull final CompositeSubscription subscription);
// }


// Path: app/src/main/java/com/lucilu/rxdynamicsearch/fragments/base/BaseFragment.java
import com.lucilu.rxdynamicsearch.IInjectable;
import com.lucilu.rxdynamicsearch.viewmodel.base.ViewModel;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import rx.subscriptions.CompositeSubscription;

package com.lucilu.rxdynamicsearch.fragments.base;




/**
 * This base fragment provides the common functionality to all fragments in the app.
 */
public abstract class BaseFragment extends Fragment implements IInjectable {

    @NonNull
    private final CompositeSubscription mSubscription = new CompositeSubscription();

    @Override
    public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        onInject();

        getViewModel().subscribeToDataStore();
    }

    @Override
    public void onResume() {
        super.onResume();
        onBind(mSubscription);
    }

    @Override
    public void onPause() {
        mSubscription.clear();
        super.onPause();
    }

    @Override
    public void onDestroyView() {
        getViewModel().dispose();
        super.onDestroyView();
    }

    protected abstract void onBind(@NonNull final CompositeSubscription subscription);

    @NonNull
    protected abstract ViewModel getViewModel();