use of gov.whitehouse.core.FeedHandler in project wh-app-android by WhiteHouse.
the class FeedManager method updateFeedFromServer.
public static void updateFeedFromServer(String url, String title, String viewType) {
final BehaviorSubject<Observable<List<FeedItem>>> subject;
final OkHttpClient client = getClient();
final Request request = getBaseRequest().url(url).get().build();
if (sFeedItemsSubject.get(url) == null) {
sFeedItemsSubject.put(url, BehaviorSubject.create());
}
subject = sFeedItemsSubject.get(url);
subject.onNext(Observable.create((Subscriber<? super List<FeedItem>> op) -> {
Response response;
try {
response = client.newCall(request).execute();
if (response.code() >= 400) {
op.onError(new IOException("Response code " + Integer.toString(response.code())));
} else {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
FeedHandler handler = new FeedHandler(title, viewType);
parser.parse(response.body().byteStream(), handler);
op.onNext(handler.getFeedItems());
}
op.onCompleted();
} catch (Exception e) {
op.onError(e);
}
}));
}
Aggregations