package com.wk.rxandroid;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action1;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        Observable testObservable = Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onNext("Hello world");
                subscriber.onCompleted();
            }
        });

        testObservable.subscribe(
                o -> printMethod(o)
        );

        testObservable.subscribe(
                o -> printMethod2(o)
        );
    }

    private void printMethod2(Object o) {
        Log.d("wenchao", "Subscribe2 " + o);

    }

    private void printMethod(Object o) {
        Log.d("wenchao", "Subscribe " + o);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -351,16 +351,65 @@
 uItem;%0A%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A%0A
 import r
@@ -552,16 +552,230 @@
 ivity %7B%0A
+    List%3CString%3E names = Arrays.asList(%22Didiet%22, %22Doni%22, %22Asep%22, %22Reza%22,%0A            %22Sari%22, %22Rendi%22, %22Akbar%22);%0A%0A    public static String currentThreadName() %7B%0A        return Thread.currentThread().getName();%0A    %7D
 %0A    @Ov
@@ -1469,261 +1469,21 @@
 ble.
-create(new Observable.OnSubscribe%3CString%3E() %7B%0A            @Override%0A            public void call(Subscriber%3C? super String%3E subscriber) %7B%0A                subscriber.onNext(%22Hello world%22);%0A                subscriber.onCompleted();%0A            %7D%0A        %7D
+just(%22lol%22, 1
 );%0A%0A

use of just