// 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/more/SafeObservable.java
// public class SafeObservable<T> extends Observable<T> {
//     protected SafeObservable(OnSubscribe<T> f) {
//         super(f);
//     }
// 
//     public Subscription safeSubscribe(Subscriber<T> subscriber) {
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext) {
//         Action1<Throwable> onError = InternalObservableUtils.ERROR_NOT_IMPLEMENTED;
//         Action0 onCompleted = Actions.empty();
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext, final Action1<Throwable> onError) {
//         Action0 onCompleted = Actions.empty();
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext,
//                                       final Action1<Throwable> onError, final Action0 onCompleted) {
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// }


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.gdgand.rxjava.tips.example.more.SafeObservable;
import com.jakewharton.rxbinding.widget.RxTextView;
import java.util.Collections;
import java.util.List;
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;
package com.gdgand.rxjava.tips.example;




//import rx.plugins.DebugHook;
//import rx.plugins.DebugNotification;
//import rx.plugins.DebugNotificationListener;
//import rx.plugins.RxJavaPlugins;

public class ThirdExampleActivity extends AppCompatActivity {
    @BindView(R.id.search_bar) EditText searchBar;
    @BindView(R.id.results) RecyclerView results;

//    static {
//        String TAG = "Rx-Debug Example";
//        RxJavaPlugins.getInstance().registerObservableExecutionHook(new DebugHook(new DebugNotificationListener() {
//            public Object onNext(DebugNotification n) {
//                Log.v(TAG, "onNext on " + n);
//                return super.onNext(n);
//            }
//
//
//            public Object start(DebugNotification n) {
//                Log.v(TAG, "start on " + n);
//                return super.start(n);
//            }
//
//
//            public void complete(Object context) {
//                Log.v(TAG, "complete on " + context);
//            }
//
//            public void error(Object context, Throwable e) {
//                Log.e(TAG, "error on " + context);
//            }
//        }));
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);
        ButterKnife.bind(this);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        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);

        RxUserBus.subSafe().safeSubscribe((String s) -> {
            Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
        });

// 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/more/SafeObservable.java
// public class SafeObservable<T> extends Observable<T> {
//     protected SafeObservable(OnSubscribe<T> f) {
//         super(f);
//     }
// 
//     public Subscription safeSubscribe(Subscriber<T> subscriber) {
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext) {
//         Action1<Throwable> onError = InternalObservableUtils.ERROR_NOT_IMPLEMENTED;
//         Action0 onCompleted = Actions.empty();
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext, final Action1<Throwable> onError) {
//         Action0 onCompleted = Actions.empty();
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// 
//     public Subscription safeSubscribe(final Action1<? super T> onNext,
//                                       final Action1<Throwable> onError, final Action0 onCompleted) {
//         Subscriber<T> subscriber = new ActionSubscriber<T>(onNext, onError, onCompleted);
//         WeakSubscriberDecorator<T> weakSubscriberDecorator = new WeakSubscriberDecorator<>(subscriber);
//         return subscribe(weakSubscriberDecorator);
//     }
// }


// Path: 2016-07-06_rxjava_tips/src/main/java/com/gdgand/rxjava/tips/example/ThirdExampleActivity.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.gdgand.rxjava.tips.example.more.SafeObservable;
import com.jakewharton.rxbinding.widget.RxTextView;
import java.util.Collections;
import java.util.List;
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;

package com.gdgand.rxjava.tips.example;




//import rx.plugins.DebugHook;
//import rx.plugins.DebugNotification;
//import rx.plugins.DebugNotificationListener;
//import rx.plugins.RxJavaPlugins;

public class ThirdExampleActivity extends AppCompatActivity {
    @BindView(R.id.search_bar) EditText searchBar;
    @BindView(R.id.results) RecyclerView results;

//    static {
//        String TAG = "Rx-Debug Example";
//        RxJavaPlugins.getInstance().registerObservableExecutionHook(new DebugHook(new DebugNotificationListener() {
//            public Object onNext(DebugNotification n) {
//                Log.v(TAG, "onNext on " + n);
//                return super.onNext(n);
//            }
//
//
//            public Object start(DebugNotification n) {
//                Log.v(TAG, "start on " + n);
//                return super.start(n);
//            }
//
//
//            public void complete(Object context) {
//                Log.v(TAG, "complete on " + context);
//            }
//
//            public void error(Object context, Throwable e) {
//                Log.e(TAG, "error on " + context);
//            }
//        }));
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);
        ButterKnife.bind(this);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        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);

        RxUserBus.subSafe().safeSubscribe((String s) -> {
            Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
        });

        SafeObservable<List<SearchItem>> itemsObservable = (SafeObservable<List<SearchItem>>)