// Path: 2016-07-06_rxjava_tips/src/main/java/com/gdgand/rxjava/tips/MainActivity.java
// public class MainActivity extends AppCompatActivity {
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_main);
//         ButterKnife.bind(this);
//     }
// 
//     @OnClick(R.id.button1)
//     public void moveToExample1 () {
//         startActivity(new Intent(this, FirstExampleActivity.class));
//     }
// 
//     @OnClick(R.id.button2)
//     public void moveToExample2 () {
//         startActivity(new Intent(this, SecondExampleActivity.class));
//     }
// 
//     @OnClick(R.id.button3)
//     public void moveToExample3 () {
//         startActivity(new Intent(this, ThirdExampleActivity.class));
//     }
// }


import android.os.Bundle;
import android.support.v4.util.LruCache;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;
import com.gdgand.rxjava.tips.MainActivity;
import com.gdgand.rxjava.tips.R;
import com.jakewharton.rxbinding.widget.RxTextView;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        results.setLayoutManager(layoutManager);
        results.setHasFixedSize(true);

        final SearchRecyclerAdapter adapter = new SearchRecyclerAdapter(Collections.emptyList());
        results.setAdapter(adapter);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.github.com")
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        LruCache<String, SearchResult> cache = new LruCache<>(5 * 1024 * 1024); // 5MiB

        final GitHubInteractor interactor = new GitHubInteractor(retrofit, cache);

        subs.add(RxUserBus.sub().subscribe((String s) -> {
            Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
        }));

        subs.add(RxTextView.textChanges(searchBar)
                .observeOn(Schedulers.io())
                .debounce(1, TimeUnit.SECONDS)
                .filter(charSequence -> charSequence.length() > 0)
                .switchMap((CharSequence seq) -> interactor.searchUsers(seq.toString()))
                .flatMap((SearchResult searchResult) ->
                        Observable.from(searchResult.getItems()).limit(20).toList())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(adapter::refreshResults, throwable -> {
// Path: 2016-07-06_rxjava_tips/src/main/java/com/gdgand/rxjava/tips/MainActivity.java
// public class MainActivity extends AppCompatActivity {
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_main);
//         ButterKnife.bind(this);
//     }
// 
//     @OnClick(R.id.button1)
//     public void moveToExample1 () {
//         startActivity(new Intent(this, FirstExampleActivity.class));
//     }
// 
//     @OnClick(R.id.button2)
//     public void moveToExample2 () {
//         startActivity(new Intent(this, SecondExampleActivity.class));
//     }
// 
//     @OnClick(R.id.button3)
//     public void moveToExample3 () {
//         startActivity(new Intent(this, ThirdExampleActivity.class));
//     }
// }


// Path: 2016-07-06_rxjava_tips/src/main/java/com/gdgand/rxjava/tips/example/FirstExampleActivity.java
import android.os.Bundle;
import android.support.v4.util.LruCache;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;
import com.gdgand.rxjava.tips.MainActivity;
import com.gdgand.rxjava.tips.R;
import com.jakewharton.rxbinding.widget.RxTextView;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        results.setLayoutManager(layoutManager);
        results.setHasFixedSize(true);

        final SearchRecyclerAdapter adapter = new SearchRecyclerAdapter(Collections.emptyList());
        results.setAdapter(adapter);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.github.com")
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        LruCache<String, SearchResult> cache = new LruCache<>(5 * 1024 * 1024); // 5MiB

        final GitHubInteractor interactor = new GitHubInteractor(retrofit, cache);

        subs.add(RxUserBus.sub().subscribe((String s) -> {
            Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
        }));

        subs.add(RxTextView.textChanges(searchBar)
                .observeOn(Schedulers.io())
                .debounce(1, TimeUnit.SECONDS)
                .filter(charSequence -> charSequence.length() > 0)
                .switchMap((CharSequence seq) -> interactor.searchUsers(seq.toString()))
                .flatMap((SearchResult searchResult) ->
                        Observable.from(searchResult.getItems()).limit(20).toList())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(adapter::refreshResults, throwable -> {
                    Log.e(MainActivity.class.getName(), throwable.getMessage());