use of rx.functions.Action1 in project realm-java by realm.
the class RxJavaTests method findFirstAsync_emittedOnUpdate.
@Test
@RunTestInLooperThread
public void findFirstAsync_emittedOnUpdate() {
final AtomicInteger subscriberCalled = new AtomicInteger(0);
Realm realm = looperThread.realm;
realm.beginTransaction();
AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
subscription = realm.where(AllTypes.class).findFirstAsync().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {
@Override
public void call(AllTypes rxObject) {
if (subscriberCalled.incrementAndGet() == 2) {
looperThread.testComplete();
}
}
});
realm.beginTransaction();
obj.setColumnLong(1);
realm.commitTransaction();
}
use of rx.functions.Action1 in project Rutgers-Course-Tracker by tevjef.
the class SectionInfoPresenterImpl method loadRMP.
public void loadRMP() {
final Iterable<Instructors> professorsNotFound = new ArrayList<>(mSection.getInstructors());
cancePreviousSubscription();
Subscriber<Professor> subscriber = new Subscriber<Professor>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Professor professor) {
if (getView() != null)
getView().addRMPProfessor(professor);
}
};
mSubscription = buildSearchParameters(mSection).flatMap(new Func1<Parameter, Observable<Professor>>() {
@Override
public Observable<Professor> call(Parameter parameter) {
return rmp.getProfessor(parameter);
}
}).doOnNext(new Action1<Professor>() {
@Override
public void call(Professor professor) {
for (final Iterator<Instructors> iterator = professorsNotFound.iterator(); iterator.hasNext(); ) {
Instructors i = iterator.next();
if (StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getLastName()) > .70 || StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getFirstName()) > .70) {
iterator.remove();
}
}
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).doOnTerminate(new Action0() {
@Override
public void call() {
if (getView() != null) {
getView().showRatingsLayout();
getView().hideRatingsLoading();
for (Instructors i : professorsNotFound) {
getView().addErrorProfessor(i.getName());
}
}
}
}).subscribe(subscriber);
}
use of rx.functions.Action1 in project sqlbrite by square.
the class ItemsFragment method onResume.
@Override
public void onResume() {
super.onResume();
String listId = String.valueOf(getListId());
subscriptions = new CompositeSubscription();
Observable<Integer> itemCount = //
db.createQuery(TodoItem.TABLE, COUNT_QUERY, listId).map(new Func1<Query, Integer>() {
@Override
public Integer call(Query query) {
Cursor cursor = query.run();
try {
if (!cursor.moveToNext()) {
throw new AssertionError("No rows");
}
return cursor.getInt(0);
} finally {
cursor.close();
}
}
});
Observable<String> listName = db.createQuery(TodoList.TABLE, TITLE_QUERY, listId).map(new Func1<Query, String>() {
@Override
public String call(Query query) {
Cursor cursor = query.run();
try {
if (!cursor.moveToNext()) {
throw new AssertionError("No rows");
}
return cursor.getString(0);
} finally {
cursor.close();
}
}
});
subscriptions.add(Observable.combineLatest(listName, itemCount, new Func2<String, Integer, String>() {
@Override
public String call(String listName, Integer itemCount) {
return listName + " (" + itemCount + ")";
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<String>() {
@Override
public void call(String title) {
getActivity().setTitle(title);
}
}));
subscriptions.add(db.createQuery(TodoItem.TABLE, LIST_QUERY, listId).mapToList(TodoItem.MAPPER).observeOn(AndroidSchedulers.mainThread()).subscribe(adapter));
}
use of rx.functions.Action1 in project Reader by TheKeeperOfPie.
the class TableLink method storeLinks.
public Action1<SQLiteDatabase> storeLinks(final List<Link> links) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
List<Link> linksWithComments = new ArrayList<>();
for (int index = links.size() - 1; index >= 0; index--) {
if (!links.get(index).getComments().getChildren().isEmpty()) {
linksWithComments.add(links.remove(index));
}
}
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON);
sqLiteDatabase.beginTransaction();
for (Link link : links) {
transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
TransactionInsertOrReplace transactionWithComments = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON, COLUMN_COMMENTS);
sqLiteDatabase.beginTransaction();
for (Link link : linksWithComments) {
transactionWithComments.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson(), link.getJsonComments());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
};
}
use of rx.functions.Action1 in project storio by pushtorefresh.
the class ObservableBehaviorCheckerTest method assertThatObservableEmitsOnceNegative.
@Test(expected = IllegalStateException.class)
public void assertThatObservableEmitsOnceNegative() {
final Observable<Integer> testObservable = Observable.just(1, 2);
new ObservableBehaviorChecker<Integer>().observable(testObservable).expectedNumberOfEmissions(1).testAction(new Action1<Integer>() {
final AtomicInteger numberOfInvocations = new AtomicInteger(0);
@Override
public void call(Integer i) {
if (numberOfInvocations.incrementAndGet() > 1) {
fail("Should be called once");
}
}
}).checkBehaviorOfObservable();
}
Aggregations