// Path: app/src/main/java/apidez/com/databinding/MyApplication.java
// public class MyApplication extends Application {
//     private static Context mContext;
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mContext = this;
// 
//         // 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;
//     }
// 
//     public static Context context() {
//         return mContext;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/databinding/view/adapter/PlacesAdapter.java
// public class PlacesAdapter extends BaseRecyclerViewAdapter<Place> {
//     private Context mContext;
// 
//     public PlacesAdapter(Context context) {
//         mContext = context;
//         mItems = new ArrayList<>();
//     }
// 
//     @Override
//     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         ItemPlaceBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_place, parent, false);
//         return new PlaceViewHolder(binding.getRoot());
//     }
// 
//     @Override
//     public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
//         PlaceViewHolder holder = (PlaceViewHolder) viewHolder;
//         Place place = mItems.get(position);
//         holder.getBinding().setVariable(BR.place, place);
//         holder.getBinding().executePendingBindings();
//         holder.itemView.setOnClickListener(v -> {
//         });
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mItems.size();
//     }
// 
//     // this view holder hold the view of one particular card
//     public static class PlaceViewHolder extends RecyclerView.ViewHolder {
//         private ItemPlaceBinding binding;
// 
//         public PlaceViewHolder(View rowView) {
//             super(rowView);
//             binding = DataBindingUtil.bind(rowView);
//         }
// 
//         public ItemPlaceBinding getBinding() {
//             return binding;
//         }
//     }
// }
// 
// Path: app/src/main/java/apidez/com/databinding/viewmodel/IPlacesViewModel.java
// public interface IPlacesViewModel {
//     /**
//      * Fetch all places from google
//      */
//     Observable<Boolean> fetchAllPlaces();
// 
//     /**
//      * Observe current places
//      */
//     ObservableArrayList<Place> getCurrentPlaces();
// 
//     /**
//      * Filter the places
//      */
//     void filterPlacesByType(String type);
// 
//     /**
//      * Porgressbar
//      */
//     Observable<Boolean> progress();
// }


import android.app.ProgressDialog;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
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 android.widget.Toast;
import javax.inject.Inject;
import apidez.com.databinding.MyApplication;
import apidez.com.databinding.R;
import apidez.com.databinding.databinding.FragmentPlacesBinding;
import apidez.com.databinding.view.adapter.PlacesAdapter;
import apidez.com.databinding.viewmodel.IPlacesViewModel;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
        binding.setViewModel(mViewModel);
        setupView();
        return binding.getRoot();
    }

    private void setupView() {
        // Toolbar
        ((AppCompatActivity) getActivity()).setSupportActionBar(binding.toolbar);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Setup recycler view
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        binding.recyclerView.setAdapter(new PlacesAdapter(getContext()));

        // Swipe to refresh
        binding.swipeRefresh.setOnRefreshListener(this::downloadData);

        // Progress dialog
        mProgressDialog = new ProgressDialog(getContext());
        mProgressDialog.setMessage(getString(R.string.loading));
        mProgressDialog.setCancelable(false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel.progress()
                .observeOn(AndroidSchedulers.mainThread())
                .takeUntil(preDestroy())
                .subscribe(done -> {
// Path: app/src/main/java/apidez/com/databinding/MyApplication.java
// public class MyApplication extends Application {
//     private static Context mContext;
//     protected AppComponent mAppComponent;
//     protected ComponentBuilder mComponentBuilder;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         mContext = this;
// 
//         // 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;
//     }
// 
//     public static Context context() {
//         return mContext;
//     }
// }
// 
// Path: app/src/main/java/apidez/com/databinding/view/adapter/PlacesAdapter.java
// public class PlacesAdapter extends BaseRecyclerViewAdapter<Place> {
//     private Context mContext;
// 
//     public PlacesAdapter(Context context) {
//         mContext = context;
//         mItems = new ArrayList<>();
//     }
// 
//     @Override
//     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//         ItemPlaceBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_place, parent, false);
//         return new PlaceViewHolder(binding.getRoot());
//     }
// 
//     @Override
//     public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
//         PlaceViewHolder holder = (PlaceViewHolder) viewHolder;
//         Place place = mItems.get(position);
//         holder.getBinding().setVariable(BR.place, place);
//         holder.getBinding().executePendingBindings();
//         holder.itemView.setOnClickListener(v -> {
//         });
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mItems.size();
//     }
// 
//     // this view holder hold the view of one particular card
//     public static class PlaceViewHolder extends RecyclerView.ViewHolder {
//         private ItemPlaceBinding binding;
// 
//         public PlaceViewHolder(View rowView) {
//             super(rowView);
//             binding = DataBindingUtil.bind(rowView);
//         }
// 
//         public ItemPlaceBinding getBinding() {
//             return binding;
//         }
//     }
// }
// 
// Path: app/src/main/java/apidez/com/databinding/viewmodel/IPlacesViewModel.java
// public interface IPlacesViewModel {
//     /**
//      * Fetch all places from google
//      */
//     Observable<Boolean> fetchAllPlaces();
// 
//     /**
//      * Observe current places
//      */
//     ObservableArrayList<Place> getCurrentPlaces();
// 
//     /**
//      * Filter the places
//      */
//     void filterPlacesByType(String type);
// 
//     /**
//      * Porgressbar
//      */
//     Observable<Boolean> progress();
// }


// Path: app/src/main/java/apidez/com/databinding/view/fragment/PlacesFragment.java
import android.app.ProgressDialog;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
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 android.widget.Toast;
import javax.inject.Inject;
import apidez.com.databinding.MyApplication;
import apidez.com.databinding.R;
import apidez.com.databinding.databinding.FragmentPlacesBinding;
import apidez.com.databinding.view.adapter.PlacesAdapter;
import apidez.com.databinding.viewmodel.IPlacesViewModel;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

        binding.setViewModel(mViewModel);
        setupView();
        return binding.getRoot();
    }

    private void setupView() {
        // Toolbar
        ((AppCompatActivity) getActivity()).setSupportActionBar(binding.toolbar);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        // Setup recycler view
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        binding.recyclerView.setAdapter(new PlacesAdapter(getContext()));

        // Swipe to refresh
        binding.swipeRefresh.setOnRefreshListener(this::downloadData);

        // Progress dialog
        mProgressDialog = new ProgressDialog(getContext());
        mProgressDialog.setMessage(getString(R.string.loading));
        mProgressDialog.setCancelable(false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel.progress()
                .observeOn(AndroidSchedulers.mainThread())
                .takeUntil(preDestroy())
                .subscribe(done -> {
                    if (done) {