use of com.android.example.devsummit.archdemo.job.NetworkException in project dev-summit-architecture-demo by yigit.
the class FetchFeedJob method onRun.
@Override
public void onRun() throws Throwable {
long timestamp = mFeedModel.getLatestTimestamp(mUserId);
final Call<FeedResponse> feed;
if (mUserId == null) {
feed = mApiService.feed(timestamp);
} else {
feed = mApiService.userFeed(mUserId, timestamp);
}
Response<FeedResponse> response = feed.execute();
if (response.isSuccess()) {
Post oldest = handleResponse(response.body());
mEventBus.post(new FetchedFeedEvent(true, mUserId, oldest));
} else {
throw new NetworkException(response.code());
}
}
use of com.android.example.devsummit.archdemo.job.NetworkException in project dev-summit-architecture-demo by yigit.
the class SaveNewPostJob method onRun.
@Override
public void onRun() throws Throwable {
Post post = mPostModel.loadByClientIdAndUserId(mClientId, mUserId);
if (post != null && !post.isPending()) {
// looks like post probably arrived from somewhere else. Good Job!
mEventBus.post(new UpdatedPostEvent(post));
return;
}
Response<NewPostResponse> response = mApiService.sendPost(mText, mClientId, mUserId).execute();
if (response.isSuccess()) {
NewPostResponse body = response.body();
body.getPost().setPending(false);
mPostModel.save(body.getPost());
mUserModel.save(body.getUser());
mEventBus.post(new UpdatedPostEvent(body.getPost()));
} else {
throw new NetworkException(response.code());
}
}
Aggregations