@Test public void takeTakesCorrectTimes() throws Exception { float float1 = 123; float float2 = 32; ObservableFloat observed = new ObservableFloat(float1); ObservableFloat observing = Cinder.computeFloat(()-> observed.get() , observed).take(2).immediate(); assertTrue(observing.get() == float1); observed.set(float2); assertTrue(observing.get() == float2); observed.set(float1); assertTrue(observing.get() == float2); }
@Test public void skipSkipsCorrectTimes() throws Exception { float float1 = 123; float float2 = 32; ObservableFloat observed = new ObservableFloat(); ObservableFloat observing = Cinder.computeFloat(()-> observed.get() , observed).skip(1); observed.set(float1); assertTrue(observing.get() == 0); observed.set(float2); assertTrue(observing.get() == float2); observed.set(float1); assertTrue(observing.get() == float1); }
public BaseLibraryActivityViewModel(Context context, boolean fitSystemWindows) { super(context); mFitSystemWindows = fitSystemWindows; mExpandedHeight = getDimensionPixelSize(R.dimen.miniplayer_height); mAnimateSlideInOut = false; mMiniplayerHeight = new ObservableInt(0); mMiniplayerAlpha = new ObservableFloat(1.0f); mNowPlayingToolbarAlpha = new ObservableFloat(0.0f); int backgroundColor = getColor(R.color.background); mNowPlayingBackground = new ColorDrawable(backgroundColor); setPlaybackOngoing(false); }
Listener(final ObservableFloat observableFloat, final Observer<? super Float> observer) { this.observableFloat = observableFloat; this.onPropertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int ignoredPropertyId) { if (!isDisposed()) { ObservableFloat observableFloat = (ObservableFloat) observable; observer.onNext(observableFloat.get()); } } }; }
public SSQuarterliesViewModel(Context context, final DataListener dataListener, SsQuarterliesActivityBinding ssQuarterliesActivityBinding) { this.context = context; this.dataListener = dataListener; this.ssQuarterliesActivityBinding = ssQuarterliesActivityBinding; ssQuarterliesLoadingVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesListVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesLanguageFilterVisibility = new ObservableInt(View.GONE); ssQuarterliesErrorMessageVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesEmptyStateVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesErrorStateVisibility = new ObservableInt(View.INVISIBLE); ssQuarterliesListMarginTop = new ObservableFloat(0); ssFirebaseDatabase = FirebaseDatabase.getInstance().getReference(); ssFirebaseDatabase.keepSynced(true); this.ssQuarterlyLanguages = new ArrayList<>(); this.ssQuarterlies = new ArrayList<>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String ssLastLanguageSelected = prefs.getString(SSConstants.SS_LAST_LANGUAGE_INDEX, ""); ssDefaultLanguage = Locale.getDefault().getLanguage(); if (!ssLastLanguageSelected.isEmpty()){ ssDefaultLanguage = ssLastLanguageSelected; } ssQuarterlyLanguage = new SSQuarterlyLanguage(ssDefaultLanguage, getDisplayLanguageByCode(ssDefaultLanguage), 1); loadLanguages(); }
@Test public void computesFloat() throws Exception { float float1 = 0.4321f; float float2 = 1234.4321f; ObservableFloat obsFloat = new ObservableFloat(float1); ObservableFloat computedFloat = Cinder.computeFloat(()->obsFloat.get(), obsFloat).immediate(); assertEquals(computedFloat.get(), float1, 0.0001f); obsFloat.set(float2); assertEquals(computedFloat.get(), float2, 0.0001f); }
@Test public void onceTakesOnce() throws Exception { float float1 = 123; float float2 = 43; ObservableFloat observed = new ObservableFloat(float1); ObservableFloat observing = Cinder.computeFloat(()-> observed.get(), observed).once().immediate(); assertTrue(observing.get() == float1); observed.set(float2); assertTrue(observing.get() == float1); }
@Test public void filterFilters() throws Exception { float float1 = 123; float float2 = 32; ObservableFloat observed = new ObservableFloat(); ObservableFloat observing = Cinder.computeFloat(()-> observed.get() , observed).filter(()->observed.get() == float1); observed.set(float2); assertTrue(observing.get() == 0); observed.set(float1); assertTrue(observing.get() == float1); }
@Test public void takeWhileTakesWhileTrue() throws Exception { float float1 = 123; float float2 = 32; ObservableFloat observed = new ObservableFloat(); ObservableFloat observing = Cinder.computeFloat(()-> observed.get() , observed).takeWhile(()->observed.get() == float1); observed.set(float1); assertTrue(observing.get() == float1); observed.set(float2); assertTrue(observing.get() == float1); }
@Test public void skipWhileSkipsWhileTrue() throws Exception { float float1 = 123; float float2 = 32; ObservableFloat observed = new ObservableFloat(); ObservableFloat observing = Cinder.computeFloat(()-> observed.get() , observed).skipWhile(()->observed.get() == float1); observed.set(float1); assertTrue(observing.get() == 0); observed.set(float2); assertTrue(observing.get() == float2); }
@Test public void withDefaultAssignsDefault() throws Exception { float float1 = 12; ObservableFloat observing = Cinder.computeFloat(()->0 ).withDefault(float1); assertTrue(observing.get() == float1); }
@Test public void stopStops() throws Exception { float float1 = 123; float float2 = 43; ObservableFloat observed = new ObservableFloat(float1); CinderFloat observing = Cinder.computeFloat(()-> observed.get(), observed).immediate(); assertTrue(observing.get() == float1); observing.stop(); observed.set(float2); assertTrue(observing.get() == float1); }
@Test public void convertsObservableFloatToRx() throws Exception { ObservableFloat observableFloat = new ObservableFloat(); Observable<Float> rxFloat = RxCinder.convert(observableFloat); final String TEST_KEY = "TEST_KEY"; final ArrayMap<String, Float> testMap = new ArrayMap<>(); rxFloat.subscribe((c)->{ testMap.put(TEST_KEY, c);}); final float TEST_FLOAT = 23; observableFloat.set(TEST_FLOAT); assertTrue(testMap.get(TEST_KEY).equals(TEST_FLOAT)); }
@Test public void convertsRxFloatToObservable() throws Exception { float TEST_FLOAT = 234; Observable<Float> rxFloat = Observable.just(TEST_FLOAT); ObservableFloat observableFloat = RxCinder.convertFloat(rxFloat); assertTrue(observableFloat.get() == TEST_FLOAT); }
public ObservableFloat getValue() { return value; }
public void setValue(ObservableFloat value) { this.value = value; }
ObservableFloatObservable(ObservableFloat observableFloat) { this.observableFloat = observableFloat; }
public static Observable<Float> convert(ObservableFloat observableFloat){ return Observable.create((e)-> Cinder.observe(()->e.onNext(observableFloat.get()), observableFloat) ); }
public static ObservableFloat convertFloat(Observable<Float> observable){ ObservableFloat observableFloat = new ObservableFloat(); observable.subscribe((b)->observableFloat.set(b)); return observableFloat; }
@Bindable public ObservableFloat getMiniplayerAlpha() { return mMiniplayerAlpha; }
@Bindable public ObservableFloat getToolbarAlpha() { return mNowPlayingToolbarAlpha; }
/** * Create an observable of property change events on {@code observableFloat}. * <p> * <em>Warning:</em> The created observable keeps a strong reference to {@code observableFloat}. * Unsubscribe to free this reference. */ @CheckResult @NonNull // public static Observable<Float> propertyChanges(@NonNull ObservableFloat observableFloat) { checkNotNull(observableFloat, "observableFloat == null"); return new ObservableFloatObservable(observableFloat); }