Answer the question
In order to leave comments, you need to log in
[java-rx] How to make data update when a new element is added?
The code works, but it seems to me that this approach is wrong
I have a database, requests are created through the Observer
Code in the UI
private Action1 subscriber = new Action1<List<SpeedLogDB>>() {
@Override
public void call(List<SpeedLogDB> speedLogDBs) {
setData(speedLogDBs);
}
};
private void reloadData() {
subscription = SpeedLogManager.getInstance().observableSpeedLogsForSession(1).subscribe(subscriber);
}
private PublishSubject<SpeedLogDB> updateDataBase = PublishSubject.create();
public Observable<List<SpeedLogDB>> observableSpeedLogsForSession(final long sessionId) {
return Observable.create(new Observable.OnSubscribe<List<SpeedLogDB>>() {
@Override
public void call(final Subscriber<? super List<SpeedLogDB>> subscriber) {
SessionDB session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
subscriber.onNext(session.getSpeedLogList());
}
updateDataBase.subscribe(new SimpleSubscriber<SpeedLogDB>() {
@Override
public void onNext(SpeedLogDB speedLogDB) {
SessionDB session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
subscriber.onNext(session.getSpeedLogList());
}
}
});
}
});
}
updateDataBase.onNext(null);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question