// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/adapter/Queue2Adapter.java
// public class Queue2Adapter extends RecyclerView.Adapter<Queue2Adapter.QueueViewHolder> {
// 
//     private Context context;
//     private List<String> titles;
// 
//     public Queue2Adapter(Context context) {
//         this.context = context;
//         titles = new ArrayList<>();
//     }
// 
//     public void add(String title) {
//         titles.add(title);
//     }
// 
//     @Override
//     public Queue2Adapter.QueueViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// 
//         TextView view = new TextView(context);
//         view.setTextSize(20);
//         view.setPadding(20, 20, 20, 20);
//         return new QueueViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(Queue2Adapter.QueueViewHolder holder, int position) {
//         holder.tvTitle.setText(getItem(position));
//     }
// 
//     private String getItem(int position) {
//         return titles.get(position);
//     }
// 
//     @Override
//     public int getItemCount() {
//         return titles.size();
//     }
// 
//     public void add(int index, String title) {
//         titles.add(index, title);
//     }
// 
//     static class QueueViewHolder extends RecyclerView.ViewHolder {
//         TextView tvTitle;
// 
//         public QueueViewHolder(View itemView) {
//             super(itemView);
//             tvTitle = (TextView) itemView;
//         }
//     }
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/BottomCommand.java
// public class BottomCommand implements Command {
//     private final Queue2Adapter adapter;
// 
//     public BottomCommand(Queue2Adapter adapter) {
// 
//         this.adapter = adapter;
//     }
// 
//     @Override
//     public void call() {
//         try {
//             Thread.sleep(700);
//         } catch (InterruptedException e) {
//             e.printStackTrace();
//         }
//         Observable.just(adapter.getItemCount())
//                 .observeOn(AndroidSchedulers.mainThread())
//                 .subscribe(integer -> {
//                     adapter.add(0, "Bottom : " + String.valueOf(integer));
//                     adapter.notifyDataSetChanged();
//                 });
//     }
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/Command.java
// public interface Command {
//     void call();
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/TopCommand.java
// public class TopCommand implements Command {
//     private final Queue2Adapter adapter;
// 
//     public TopCommand(Queue2Adapter adapter) {
// 
//         this.adapter = adapter;
//     }
// 
//     @Override
//     public void call() {
//         try {
//             Thread.sleep(700);
//         } catch (InterruptedException e) {
//             e.printStackTrace();
//         }
//         Observable.just(adapter.getItemCount())
//                 .observeOn(AndroidSchedulers.mainThread())
//                 .subscribe(integer -> {
//                     adapter.add("Top : " + String.valueOf(integer));
//                     adapter.notifyDataSetChanged();
//                 });
// 
//     }
// }


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.gdgand.rxjava.rxjavasample.R;
import com.gdgand.rxjava.rxjavasample.queue.adapter.Queue2Adapter;
import com.gdgand.rxjava.rxjavasample.queue.command.BottomCommand;
import com.gdgand.rxjava.rxjavasample.queue.command.Command;
import com.gdgand.rxjava.rxjavasample.queue.command.TopCommand;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
package com.gdgand.rxjava.rxjavasample.queue;




public class Queue2Activity extends AppCompatActivity {

    @BindView(R.id.rv_queue2)
    RecyclerView rvQueue;

    private PublishSubject<Command> commandQueue;
    private Queue2Adapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_queue2);

        ButterKnife.bind(this);

        initObject();
        initViews();
    }

    private void initObject() {
        commandQueue = PublishSubject.create();
        commandQueue.onBackpressureBuffer()
                .observeOn(Schedulers.io())
                .subscribe(Command::call, Throwable::printStackTrace);
    }

    private void initViews() {
        rvQueue.setLayoutManager(new LinearLayoutManager(Queue2Activity.this));
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/adapter/Queue2Adapter.java
// public class Queue2Adapter extends RecyclerView.Adapter<Queue2Adapter.QueueViewHolder> {
// 
//     private Context context;
//     private List<String> titles;
// 
//     public Queue2Adapter(Context context) {
//         this.context = context;
//         titles = new ArrayList<>();
//     }
// 
//     public void add(String title) {
//         titles.add(title);
//     }
// 
//     @Override
//     public Queue2Adapter.QueueViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// 
//         TextView view = new TextView(context);
//         view.setTextSize(20);
//         view.setPadding(20, 20, 20, 20);
//         return new QueueViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(Queue2Adapter.QueueViewHolder holder, int position) {
//         holder.tvTitle.setText(getItem(position));
//     }
// 
//     private String getItem(int position) {
//         return titles.get(position);
//     }
// 
//     @Override
//     public int getItemCount() {
//         return titles.size();
//     }
// 
//     public void add(int index, String title) {
//         titles.add(index, title);
//     }
// 
//     static class QueueViewHolder extends RecyclerView.ViewHolder {
//         TextView tvTitle;
// 
//         public QueueViewHolder(View itemView) {
//             super(itemView);
//             tvTitle = (TextView) itemView;
//         }
//     }
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/BottomCommand.java
// public class BottomCommand implements Command {
//     private final Queue2Adapter adapter;
// 
//     public BottomCommand(Queue2Adapter adapter) {
// 
//         this.adapter = adapter;
//     }
// 
//     @Override
//     public void call() {
//         try {
//             Thread.sleep(700);
//         } catch (InterruptedException e) {
//             e.printStackTrace();
//         }
//         Observable.just(adapter.getItemCount())
//                 .observeOn(AndroidSchedulers.mainThread())
//                 .subscribe(integer -> {
//                     adapter.add(0, "Bottom : " + String.valueOf(integer));
//                     adapter.notifyDataSetChanged();
//                 });
//     }
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/Command.java
// public interface Command {
//     void call();
// }
// 
// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/command/TopCommand.java
// public class TopCommand implements Command {
//     private final Queue2Adapter adapter;
// 
//     public TopCommand(Queue2Adapter adapter) {
// 
//         this.adapter = adapter;
//     }
// 
//     @Override
//     public void call() {
//         try {
//             Thread.sleep(700);
//         } catch (InterruptedException e) {
//             e.printStackTrace();
//         }
//         Observable.just(adapter.getItemCount())
//                 .observeOn(AndroidSchedulers.mainThread())
//                 .subscribe(integer -> {
//                     adapter.add("Top : " + String.valueOf(integer));
//                     adapter.notifyDataSetChanged();
//                 });
// 
//     }
// }


// Path: 2016-06-08_queue/app/src/main/java/com/gdgand/rxjava/rxjavasample/queue/Queue2Activity.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.gdgand.rxjava.rxjavasample.R;
import com.gdgand.rxjava.rxjavasample.queue.adapter.Queue2Adapter;
import com.gdgand.rxjava.rxjavasample.queue.command.BottomCommand;
import com.gdgand.rxjava.rxjavasample.queue.command.Command;
import com.gdgand.rxjava.rxjavasample.queue.command.TopCommand;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;

package com.gdgand.rxjava.rxjavasample.queue;




public class Queue2Activity extends AppCompatActivity {

    @BindView(R.id.rv_queue2)
    RecyclerView rvQueue;

    private PublishSubject<Command> commandQueue;
    private Queue2Adapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_queue2);

        ButterKnife.bind(this);

        initObject();
        initViews();
    }

    private void initObject() {
        commandQueue = PublishSubject.create();
        commandQueue.onBackpressureBuffer()
                .observeOn(Schedulers.io())
                .subscribe(Command::call, Throwable::printStackTrace);
    }

    private void initViews() {
        rvQueue.setLayoutManager(new LinearLayoutManager(Queue2Activity.this));
        adapter = new Queue2Adapter(Queue2Activity.this);