/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.reactivex.android.samples;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.AsyncObserver;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.Callable;

public class MainActivity extends Activity {
    private static final String TAG = "RxAndroidSamples";

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        findViewById(R.id.button_run_scheduler).setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {
                onRunSchedulerExampleButtonClicked();
            }
        });
    }

    void onRunSchedulerExampleButtonClicked() {
      sampleObservable()
            // Run on a background thread
            .subscribeOn(Schedulers.io())
            // Be notified on the main thread
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new AsyncObserver<String>() {
                @Override public void onComplete() {
                    Log.d(TAG, "onComplete()");
                }

                @Override public void onError(Throwable e) {
                    Log.e(TAG, "onError()", e);
                }

                @Override public void onNext(String string) {
                    Log.d(TAG, "onNext(" + string + ")");
                }
            });
    }

    static Observable<String> sampleObservable() {
        return Observable.defer(new Callable<ObservableSource<? extends String>>() {
          @Override public ObservableSource<? extends String> call() throws Exception {
                // Do some long running operation
                SystemClock.sleep(5000);
                return Observable.just("one", "two", "three", "four", "five");
            }
        });
    }
}

@@ -879,23 +879,81 @@
 vex.
-observers.Async
+disposables.CompositeDisposable;%0Aimport io.reactivex.observers.Disposable
 Obse
@@ -1144,16 +1144,96 @@
 ples%22;%0A%0A
+    private final CompositeDisposable disposables = new CompositeDisposable();%0A%0A
     @Ove
@@ -1614,24 +1614,130 @@
  %7D);%0A    %7D%0A%0A
+    @Override protected void onDestroy() %7B%0A        super.onDestroy();%0A        disposables.clear();%0A    %7D%0A%0A
     void onR
@@ -1778,16 +1778,34 @@
 %7B%0A      
+  disposables.add(
 sampleOb
@@ -2026,18 +2026,27 @@
 ribe
+With
 (new 
-Async
+Disposable
 Obse
@@ -2440,32 +2440,32 @@
               %7D%0A
-
             %7D);%0A
@@ -2454,32 +2454,33 @@
 %7D%0A            %7D)
+)
 ;%0A    %7D%0A%0A    sta

Update sample to compile with latest RxJava 2.0 APIs.