@Test public void takeTakesCorrectTimes() throws Exception { String string1 = "STRING 1"; String string2 = "STRING 2"; ObservableField<String> observed = new ObservableField<>(string1); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(string1) , observed).take(2).immediate(); assertTrue(observing.get()); observed.set(string2); assertFalse(observing.get()); observed.set(string1); assertFalse(observing.get()); }
@Test public void skipSkipsCorrectTimes() throws Exception { String string1 = "STRING 1"; String string2 = "STRING 2"; ObservableField<String> observed = new ObservableField<>(string1); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(string1) , observed).skip(1); observed.set(string1); assertFalse(observing.get()); observed.set(string2); assertFalse(observing.get()); observed.set(string1); assertTrue(observing.get()); }
public PasswordReadViewModel(Navigator navigator, PasswordInteractor interactor, int id) { this.navigator = navigator; this.interactor = interactor; this.id = id; this.title = new ObservableField<>(); this.icon = new ObservableField<>(); this.username = new ObservableField<>(); this.password = new ObservableField<>(); this.displayPassword = new ObservableBoolean(false); this.customFields = new ObservableArrayList<>(); realmPassword = interactor.readPassword(id); realmPassword.addChangeListener(this::updateView); updateView(realmPassword); }
/** * Creates {@code RxCommand} to execute the specified command from the specified {@link * Observable} with the specified initial state. * * @param canExecuteSource an {@link Observable} to emit whether this {@code RxCommand} can * execute * @param canExecute whether this {@code RxCommand} can execute initially */ public RxCommand(@Nullable final Observable<Boolean> canExecuteSource, boolean canExecute) { canExecuteFlag = new ObservableBoolean(canExecute); if (canExecuteSource != null) { canExecuteSourceDisposable = canExecuteSource.distinctUntilChanged() .subscribeWith(new DisposableObserver<Boolean>() { @Override public void onNext(Boolean value) { canExecuteFlag.set(value); } @Override public void onError(Throwable e) { kicker.onError(e); RxCommand.this.dispose(); } @Override public void onComplete() { kicker.onComplete(); RxCommand.this.dispose(); } }); } }
@Inject public SignInActivityViewModel(BaseActivity activity, SignInUseCase signInUseCase, CheckSessionUseCase checkSessionUseCase) { super(activity); this.signInUseCase = signInUseCase; this.checkSessionUseCase = checkSessionUseCase; name = new ObservableField<>(); password = new ObservableField<>(); buttonEnabled = new ObservableBoolean(false); checkSessionUseCase.run() .compose(bindToLifecycle().forSingle()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(authToken -> { Timber.v("Check session: " + authToken.token); Toast.makeText(getContext(), "Already signed in", Toast.LENGTH_SHORT).show(); goToNext(); }, Timber::e); }
Listener(final ObservableBoolean observableBoolean, final Observer<? super Boolean> observer) { this.observableBoolean = observableBoolean; this.onPropertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int ignoredPropertyId) { if (!isDisposed()) { ObservableBoolean observableBoolean = (ObservableBoolean) observable; observer.onNext(observableBoolean.get()); } } }; }
public FollowersViewModel(@NonNull DataListener dataListener, @NonNull Context context, TwitterSession session, Long userId) { this.dataListener = dataListener; this.context = context; this.session = session; this.userId = userId; activityFollowerProgressBar = new ObservableInt(View.VISIBLE); activityFollowerSwipeRefreshLayout = new ObservableInt(View.GONE); activityFollowerRecyclerView = new ObservableInt(View.GONE); activityFollowerIsPullToRefresh = new ObservableBoolean(false); initializeViews(); fetchFollowersList(false, false, cursor); }
/** * Default constructor. * @param context The context of the current activity. */ public ExplorerViewModel(Context context) { this.context = context; this.isLoading = new ObservableBoolean(false); this.isRefreshing = new ObservableBoolean(false); this.files = new ObservableArrayList<FileViewModel>(); this.isSelectionMode = new ObservableBoolean(false); this.numberSelectedItems = new ObservableInt(0); this.changeDirectory("/"); }
/** * Default constructor. * @param context The context of the current activity. */ public ListServerViewModel(Activity context) { this.context = context; this.servers = new ObservableArrayList<FtpServerViewModel>(); this.selectedServer = new ObservableField<FtpServerViewModel>(); this.selectedServerVisible = new ObservableBoolean(); }
@Inject public PostListComponentViewModel(Bus bus, IRepository repository, INavigator navigator, ILocalization localization) { super(bus); this.repository = repository; this.navigator = navigator; this.localization = localization; this.posts = new ObservableArrayList<>(); this.isBusy = new ObservableBoolean(); this.loadCommand = new Command(this::loadPosts); }
@Test public void fireNotifiesChange() throws Exception { ObservableEvent event = new ObservableEvent(); ObservableBoolean fired = Cinder.computeBoolean(()->true, event); event.fire(); assertTrue(fired.get()); }
@Test public void computesBoolean() throws Exception { boolean bool1 = true; boolean bool2 = false; ObservableBoolean truth = new ObservableBoolean(bool1); ObservableBoolean computedTruth = Cinder.computeBoolean(()->truth.get(), truth).immediate(); assertEquals(computedTruth.get(), bool1); truth.set(bool2); assertEquals(computedTruth.get(), bool2); }
@Test public void onceTakesOnce() throws Exception { String string1 = "STRING 1"; String string2 = "STRING 2"; ObservableField<String> observed = new ObservableField<>(string1); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(string1), observed).once().immediate(); assertTrue(observing.get()); observed.set(string2); assertTrue(observing.get()); }
@Test public void filterFilters() throws Exception { String badString = "BAD STRING"; String goodString = "GOOD STRING"; ObservableField<String> observed = new ObservableField<>(""); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(goodString) , observed).filter(()->observed.get().startsWith("GOOD")); observed.set(badString); assertFalse(observing.get()); observed.set(goodString); assertTrue(observing.get()); }
@Test public void takeWhileTakesWhileTrue() throws Exception { String badString = "BAD STRING"; String goodString = "GOOD STRING"; ObservableField<String> observed = new ObservableField<>(""); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(goodString) , observed).takeWhile(()->observed.get().startsWith("GOOD")); observed.set(goodString); assertTrue(observing.get()); observed.set(badString); assertTrue(observing.get()); }
@Test public void skipWhileSkipsWhileTrue() throws Exception { String badString = "BAD STRING"; String goodString = "GOOD STRING"; ObservableField<String> observed = new ObservableField<>(""); ObservableBoolean observing = Cinder.computeBoolean(()-> observed.get().equals(goodString) , observed).skipWhile(()->observed.get().startsWith("BAD")); observed.set(badString); assertFalse(observing.get()); observed.set(goodString); assertTrue(observing.get()); }
@Test public void withDefaultAssignsDefault() throws Exception { ObservableBoolean observing = Cinder.computeBoolean(()->false ).withDefault(true); assertTrue(observing.get()); }
@Test public void convertsObservableBooleanToRx() throws Exception { ObservableBoolean observableBoolean = new ObservableBoolean(); Observable<Boolean> rxBoolean = RxCinder.convert(observableBoolean); final String TEST_KEY = "TEST_KEY"; final ArrayMap<String, Boolean> testMap = new ArrayMap<>(); rxBoolean.subscribe((b)->{ testMap.put(TEST_KEY, b);}); observableBoolean.set(true); assertTrue(testMap.get(TEST_KEY)); }
public LoginViewModel(LoginInteractor interactor, ProNavigator navigator) { this.interactor = interactor; this.navigator = navigator; email = new ObservableField<>(); password = new ObservableField<>(); passwordRepeat = new ObservableField<>(); inProgress = new ObservableBoolean(); }
/** * I would like to use this in the layout expressions, but there seems to be an issue related to this. * See https://code.google.com/p/android/issues/detail?id=230115 */ public <T> void onFieldChanged(ObservableField<T> field, ObservableBoolean errorIndicator, boolean hasFocus, Validator<T> validator) { if (hasFocus) { errorIndicator.set(false); } else { T value = field.get(); errorIndicator.set(!validator.validate(value)); Log.d(TAG, "Field is invalid: " + errorIndicator.get()); dataValid.set(validateForm()); } }
private static TestObserver<Boolean> observableBooleanTestObserver(RxCommand command) { return Observe.allPropertiesOf(command.getEnabled()) .map(new Function<ObservableBoolean, Boolean>() { @Override public Boolean apply(ObservableBoolean value) throws Exception { return value.get(); } }) .test(); }
private static <T> TestObserver<Boolean> hasErrorObserver(final RxProperty<T> property) { return Observe.propertyOf(property.getHasError(), 0, new Function<ObservableBoolean, Boolean>() { @Override public Boolean apply(ObservableBoolean value) throws Exception { return value.get(); } }) .test(); }
@Inject public StarredRepoListFragmentViewModel(BaseFragment fragment, GetStarredReposUseCase getStarredReposUseCase, EventBus eventBus) { super(fragment); this.getStarredReposUseCase = getStarredReposUseCase; this.eventBus = eventBus; repos = new ObservableArrayList<>(); isConnecting = new ObservableBoolean(true); isRefreshing = new ObservableBoolean(false); }
@Inject public RepoListItemViewModel(BaseFragment fragment, StarUseCase starUseCase, UnstarUseCase unstarUseCase, EventBus eventBus) { super(fragment); this.starUseCase = starUseCase; this.unstarUseCase = unstarUseCase; this.eventBus = eventBus; this.repo = new ObservableField<>(); this.starred = new ObservableBoolean(false); }
@Inject public RepoInfoFragmentViewModel(BaseFragment fragment, GetRepoUseCase getRepoUseCase, CheckStarUseCase checkStarUseCase, StarUseCase starUseCase, UnstarUseCase unstarUseCase, EventBus eventBus) { super(fragment); this.getRepoUseCase = getRepoUseCase; this.checkStarUseCase = checkStarUseCase; this.starUseCase = starUseCase; this.unstarUseCase = unstarUseCase; this.eventBus = eventBus; this.repo = new ObservableField<>(); this.isConnecting = new ObservableBoolean(true); this.starred = new ObservableBoolean(false); }
@Inject public UserActivityViewModel(BaseActivity activity, GetUserUseCase getUserUseCase, EventBus eventBus) { super(activity); this.getUserUseCase = getUserUseCase; this.eventBus = eventBus; this.user = new ObservableField<>(); this.isConnecting = new ObservableBoolean(true); }
@Inject public MyRepoListFragmentViewModel(BaseFragment fragment, GetUserReposUseCase getUserReposUseCase, EventBus eventBus) { super(fragment); this.getUserReposUseCase = getUserReposUseCase; this.eventBus = eventBus; repos = new ObservableArrayList<>(); isConnecting = new ObservableBoolean(true); isRefreshing = new ObservableBoolean(false); }
public ObservableBoolean getIsFired() { return isFired; }
public void setIsFired(ObservableBoolean isFired) { this.isFired = isFired; notifyChange(); }
public ObservableBoolean getChecked() { return checked; }
public void setChecked(ObservableBoolean checked) { this.checked = checked; }
public ObservableBoolean getIsLoading() { return mIsLoading; }
public MainViewModel(Context context) { this.context = context; this.user = new UserBean(); this.agree = new ObservableBoolean(); }
public ObservableBoolean getAgree() { return agree; }
ObservableBooleanObservable(ObservableBoolean observableBoolean) { this.observableBoolean = observableBoolean; }
public VehicleInfo(ObservableBoolean isSelected, String logoUrl, String brand, String description) { this.isSelected = isSelected; this.logoUrl = logoUrl; this.brand = brand; this.description = description; }
/** * Default constructor. * @param mainViewModel The parent view model. */ public FileViewModel(ExplorerViewModel mainViewModel) { this.mainViewModel = mainViewModel; this.isSelected = new ObservableBoolean(false); }
public ObservableBoolean getIsBusy() { return isBusy; }
public Command(boolean canExecute, boolean isVisible, Action0 execute) { this.canExecute = new ObservableBoolean(canExecute); this.isVisible = new ObservableBoolean(isVisible); this.execute = execute; }