// Path: app/src/main/java/apidez/com/android_mvvm_sample/view/adapter/PlacesAdapter.java
// public class PlacesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
// 
//     private Context mContext;
//     private List<Place> mPlaces;
// 
//     public PlacesAdapter(Context context) {
//         mContext = context;
//         mPlaces = new ArrayList<>();
//     }
// 
//     @Override
//     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         final View view = LayoutInflater.from(mContext).inflate(R.layout.item_place, parent, false);
//         return new PlaceViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
//         PlaceViewHolder holder = (PlaceViewHolder) viewHolder;
//         holder.itemView.setOnClickListener(v -> {});
// 
//         Place place = mPlaces.get(position);
//         holder.name.setText(place.getName());
//         Picasso.with(mContext)
//                 .load(place.getIcon())
//                 .placeholder(R.drawable.ic_place_36dp)
//                 .into(holder.icon);
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mPlaces.size();
//     }
// 
//     // this view holder hold the view of one particular card
//     public static class PlaceViewHolder extends RecyclerView.ViewHolder {
// 
//         @Bind(R.id.name)
//         TextView name;
// 
//         @Bind(R.id.icon)
//         ImageView icon;
// 
//         public PlaceViewHolder(View view) {
//             super(view);
//             ButterKnife.bind(this, view);
//         }
//     }
// 
//     /**
//      * Update the list item
//      */
//     public void updatePlaces(List<Place> places) {
//         mPlaces = places;
//         notifyDataSetChanged();
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/MyApplication.java
// public class MyApplication extends Application {
// 
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Create app component
//         mAppComponent = DaggerAppComponent.builder()
//                 .appModule(new AppModule())
//                 .build();
// 
//         // Create component builder
//         mComponentBuilder = new ComponentBuilder(mAppComponent);
//     }
// 
//     public AppComponent component() {
//         return mAppComponent;
//     }
// 
//     public ComponentBuilder builder() {
//         return mComponentBuilder;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/viewmodel/IPlacesViewModel.java
// public interface IPlacesViewModel {
//     /**
//      * Fetch all places from google
//      */
//     Observable<Boolean> fetchAllPlaces();
// 
//     /**
//      * Observe current places
//      */
//     Observable<List<Place>> currentPlaces();
// 
//     /**
//      * Filter the places
//      */
//     void filterPlacesByType(String type);
// }


import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import javax.inject.Inject;
import apidez.com.android_mvvm_sample.R;
import apidez.com.android_mvvm_sample.view.adapter.PlacesAdapter;
import apidez.com.android_mvvm_sample.MyApplication;
import apidez.com.android_mvvm_sample.viewmodel.IPlacesViewModel;
import butterknife.Bind;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Recyclerview setup
        mPlacesAdapter = new PlacesAdapter(getActivity());
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setAdapter(mPlacesAdapter);
    }

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

        // Observe current places
        mViewModel.currentPlaces()
                .takeUntil(preDestroy())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(mPlacesAdapter::updatePlaces);

        // fetch all places
        mViewModel.fetchAllPlaces()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .takeUntil(preDestroy())
                .doOnSubscribe(mProgressDialog::show)
                .doOnTerminate(mProgressDialog::hide)
                .subscribe(succes -> {}, throwable -> {});
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Path: app/src/main/java/apidez/com/android_mvvm_sample/view/adapter/PlacesAdapter.java
// public class PlacesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
// 
//     private Context mContext;
//     private List<Place> mPlaces;
// 
//     public PlacesAdapter(Context context) {
//         mContext = context;
//         mPlaces = new ArrayList<>();
//     }
// 
//     @Override
//     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         final View view = LayoutInflater.from(mContext).inflate(R.layout.item_place, parent, false);
//         return new PlaceViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
//         PlaceViewHolder holder = (PlaceViewHolder) viewHolder;
//         holder.itemView.setOnClickListener(v -> {});
// 
//         Place place = mPlaces.get(position);
//         holder.name.setText(place.getName());
//         Picasso.with(mContext)
//                 .load(place.getIcon())
//                 .placeholder(R.drawable.ic_place_36dp)
//                 .into(holder.icon);
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mPlaces.size();
//     }
// 
//     // this view holder hold the view of one particular card
//     public static class PlaceViewHolder extends RecyclerView.ViewHolder {
// 
//         @Bind(R.id.name)
//         TextView name;
// 
//         @Bind(R.id.icon)
//         ImageView icon;
// 
//         public PlaceViewHolder(View view) {
//             super(view);
//             ButterKnife.bind(this, view);
//         }
//     }
// 
//     /**
//      * Update the list item
//      */
//     public void updatePlaces(List<Place> places) {
//         mPlaces = places;
//         notifyDataSetChanged();
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/MyApplication.java
// public class MyApplication extends Application {
// 
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         // Create app component
//         mAppComponent = DaggerAppComponent.builder()
//                 .appModule(new AppModule())
//                 .build();
// 
//         // Create component builder
//         mComponentBuilder = new ComponentBuilder(mAppComponent);
//     }
// 
//     public AppComponent component() {
//         return mAppComponent;
//     }
// 
//     public ComponentBuilder builder() {
//         return mComponentBuilder;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/android_mvvm_sample/viewmodel/IPlacesViewModel.java
// public interface IPlacesViewModel {
//     /**
//      * Fetch all places from google
//      */
//     Observable<Boolean> fetchAllPlaces();
// 
//     /**
//      * Observe current places
//      */
//     Observable<List<Place>> currentPlaces();
// 
//     /**
//      * Filter the places
//      */
//     void filterPlacesByType(String type);
// }


// Path: app/src/main/java/apidez/com/android_mvvm_sample/view/fragment/PlacesFragment.java
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import javax.inject.Inject;
import apidez.com.android_mvvm_sample.R;
import apidez.com.android_mvvm_sample.view.adapter.PlacesAdapter;
import apidez.com.android_mvvm_sample.MyApplication;
import apidez.com.android_mvvm_sample.viewmodel.IPlacesViewModel;
import butterknife.Bind;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Recyclerview setup
        mPlacesAdapter = new PlacesAdapter(getActivity());
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setAdapter(mPlacesAdapter);
    }

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

        // Observe current places
        mViewModel.currentPlaces()
                .takeUntil(preDestroy())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(mPlacesAdapter::updatePlaces);

        // fetch all places
        mViewModel.fetchAllPlaces()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .takeUntil(preDestroy())
                .doOnSubscribe(mProgressDialog::show)
                .doOnTerminate(mProgressDialog::hide)
                .subscribe(succes -> {}, throwable -> {});
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);