/**
* Created by marius on 1/9/15.
*
* @music Beware of safety - Kaura
*/
public class RxValuesSampleViewModel {
public RxBoolean enabled = new RxBoolean();
public void toggle() {
enabled.set(!enabled.get());
}
[...]
}
public class RxValuesSampleView {
private final RxValuesSampleViewModel viewModel = new RxValuesSampleViewModel();
[...]
public void bind() {
viewModel.enabled.valueObservable().
subscribe(button::setEnabled);
}
}
import rx.Observable;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Alegria
*/
public interface RxValue<T> {
Observable<T> valueObservable();
void valueChanged(T value);
}
import android.databinding.ObservableShort;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Alegria
*/
public class RxShort extends ObservableShort implements RxValue<Short> {
private BehaviorSubject<Short> valueSubject = BehaviorSubject.create();
public RxShort(short value) {
super(value);
}
public RxShort() {
super();
}
@Override
public void set(short value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Short> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Short value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableLong;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Vehicle Lunar
*/
public class RxLong extends ObservableLong implements RxValue<Long> {
private BehaviorSubject<Long> valueSubject = BehaviorSubject.create();
public RxLong(long value) {
super(value);
}
public RxLong() {
super();
}
@Override
public void set(long value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Long> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Long value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableInt;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Me sobren paraules
*/
public class RxInt extends ObservableInt implements RxValue<Integer> {
private BehaviorSubject<Integer> valueSubject = BehaviorSubject.create();
public RxInt(int value) {
super(value);
}
public RxInt() {
super();
}
@Override
public void set(int value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Integer> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Integer value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableFloat;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Vehicle Lunar
*/
public class RxFloat extends ObservableFloat implements RxValue<Float> {
private BehaviorSubject<Float> valueSubject = BehaviorSubject.create();
public RxFloat(float value) {
super(value);
}
public RxFloat() {
super();
}
@Override
public void set(float value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Float> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Float value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableField;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Me sobren paraules
*/
public class RxField<T> extends ObservableField<T> implements RxValue<T> {
private BehaviorSubject<T> valueSubject = BehaviorSubject.create();
public RxField(T value) {
super(value);
}
public RxField() {
super();
}
@Override
public void set(T value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<T> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(T value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableDouble;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Vehicle Lunar
*/
public class RxDouble extends ObservableDouble implements RxValue<Double> {
private BehaviorSubject<Double> valueSubject = BehaviorSubject.create();
public RxDouble(double value) {
super(value);
}
public RxDouble() {
super();
}
@Override
public void set(double value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Double> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Double value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableChar;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Vehicle Lunar
*/
public class RxChar extends ObservableChar implements RxValue<Character> {
private BehaviorSubject<Character> valueSubject = BehaviorSubject.create();
public RxChar(char value) {
super(value);
}
public RxChar() {
super();
}
@Override
public void set(char value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Character> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Character value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableByte;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Vehicle Lunar
*/
public class RxByte extends ObservableByte implements RxValue<Byte> {
private BehaviorSubject<Byte> valueSubject = BehaviorSubject.create();
public RxByte(byte value) {
super(value);
}
public RxByte() {
super();
}
@Override
public void set(byte value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Byte> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Byte value) {
valueSubject.onNext(value);
}
}
import android.databinding.ObservableBoolean;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/**
* Created by marius on 31/8/15.
*
* @music Antonia Font - Me sobren paraules
*/
public class RxBoolean extends ObservableBoolean implements RxValue<Boolean> {
private BehaviorSubject<Boolean> valueSubject = BehaviorSubject.create();
public RxBoolean(boolean value) {
super(value);
}
public RxBoolean() {
super();
}
@Override
public void set(boolean value) {
super.set(value);
valueSubject.onNext(value);
}
@Override
public Observable<Boolean> valueObservable() {
return valueSubject.asObservable();
}
@Override
public void valueChanged(Boolean value) {
valueSubject.onNext(value);
}
}