Skip to content

Instantly share code, notes, and snippets.

View tcw165's full-sized avatar
💭
building AI

TC Wang tcw165

💭
building AI
View GitHub Profile
/**
* The Observable that emits the items emitted by the [src] Observable when a
* second ObservableSource, [whenSrc], emits an true; It buffers all them items
* emitted by the [src] when [whenSrc] emits an false.
*/
open class TakeWhenObservable<T>(private val src: ObservableSource<T>,
private val whenSrc: ObservableSource<Boolean>,
private val bufferSize: Int = Flowable.bufferSize())
: Observable<T>() {
public final class LambdaObserver<T>
extends AtomicReference<Disposable>
implements Observer<T>,
Disposable,
LambdaConsumerIntrospection {
// ...
@Override
public void onComplete() {
class BindWidgetWithModel<T>(widget: IWidget<T>,
model: T,
caughtErrorSignal: Observer<Throwable>? = null)
: Observable<Boolean>() {
private val mWidget = widget
private val mModel = model
private val mCaughtErrorSignal = caughtErrorSignal
public final class ConsumerSingleObserver<T>
extends AtomicReference<Disposable>
implements SingleObserver<T>,
Disposable,
LambdaConsumerIntrospection {
// ...
@Override
public void onSubscribe(Disposable d) {
class FooSingle : Single<Boolean>() {
override fun subscribeActual(observer: SingleObserver<in Boolean>) {
val d = FooDisposable(mWidget)
observer.onSubscribe(d)
try {
// Allocate memory or register listeners...
// Tell the observer the sole result
final class ViewClickObservable extends Observable<Object> {
private final View view;
ViewClickObservable(View view) {
this.view = view;
}
@Override
protected void subscribeActual(Observer<? super Object> observer) {
Listener listener = new Listener(view);
public static Observable<Object> clicks(View view) {
return new ViewClickObservable(view);
}
// Whatever Activity
private val mDisposables = CompositeDisposable()
private val mBtnFoo by lazy { findViewById<View>(R.id.foo) }
override fun onResume() {
mDisposables.add(
RxView.click(mBtnFoo)
.subscribe {
println("oh click on Foo")
// Copyright Feb 2018-present [email protected]
//
// Original authors: Robert Sedgewick and Kevin Wayne
// Maintainer author: TAI CHUN WANG
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
private val mDisposablesOnCreate = CompositeDisposable()
// Activity onCreate().
override fun onCreate() {
// Long computation operation.
mDisposablesOnCreate.add(
// Share button.
onClickShare()
.switchMap { _ ->
// First, switchMap convert the click to an action observable.