use of com.vegen.smartcampus.baseframework.network.DisposableHolder in project SmartCampus by Vegen.
the class ArticleDetailPresenter method getNewsContent.
@Override
public void getNewsContent(String url) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
// 带有href属性的a元素
Elements links = body.select("a[href]");
for (Element element : links) {
element.attr("href", "");
}
Element author = body.select("#author").first();
Element contentbody = body.select("#contentbody").first();
Element showtag = body.select("#showtag").last();
if (mView != null) {
mView.showNewsContent("</br>" + (author.html() + contentbody.html() + showtag.html()).replace("font-size: 10.5pt", "font-size: 16.5pt").replace("FONT-SIZE: 10.5pt", "FONT-SIZE: 16.5pt").replace("src=\"/files", "src=\"" + Url.ROOT_URL + "/files").replace("href=\"\"", "").replace("【点击:", "【点击:" + SystemUtils.getRandom(5, 30)).replace("发布时间", "</br>发布时间"));
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
use of com.vegen.smartcampus.baseframework.network.DisposableHolder in project SmartCampus by Vegen.
the class EmploymentArticleDetailPresenter method getEmploymentList.
@Override
public void getEmploymentList(String url, int type) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
if (mView != null) {
mView.showEmploymentList(filterData(body, type));
mView.hideLoading(false);
if (type == Constant.FAIR)
mView.loadMoreEnd(true);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
use of com.vegen.smartcampus.baseframework.network.DisposableHolder in project SmartCampus by Vegen.
the class HomePresenter method getNewsList.
@Override
public void getNewsList(String url) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
Element photoList = body.getElementById("ListNews").getElementById("leftbox").getElementById("photolist");
// 新闻列表
List<NewsList> newsListList = new ArrayList<>();
// NEWS_TYPE_FOCUS 要闻
newsListList.add(new NewsList(NEWS_TYPE_FOCUS, getTagNews(photoList, "xxyw", NEWS_TYPE_FOCUS)));
// NEWS_TYPE_COMPREHENSIVE 综合
newsListList.add(new NewsList(NEWS_TYPE_COMPREHENSIVE, getTagNews(photoList, "zhxw", NEWS_TYPE_COMPREHENSIVE)));
// NEWS_TYPE_FLASH 快讯
newsListList.add(new NewsList(NEWS_TYPE_FLASH, getTagNews(photoList, "xykx", NEWS_TYPE_FLASH)));
// NEWS_TYPE_OTHER 其他
newsListList.add(new NewsList(NEWS_TYPE_OTHER, getTagNews(photoList, "otherPic", NEWS_TYPE_OTHER)));
List<String> strings = new ArrayList<>();
Elements elements = photoList.select("div.more");
for (Element element : elements) {
String id = element.getElementsByTag("a").attr("href");
strings.add(id);
}
if (mView != null) {
mView.showNewsList(newsListList);
mView.moreNewsClassId(strings);
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
use of com.vegen.smartcampus.baseframework.network.DisposableHolder in project SmartCampus by Vegen.
the class MoreNewsPresenter method getNewsList.
@Override
public void getNewsList(int page, String url, int newsType, String view_state, String view_state_generator, String event_validation) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Connection connection = Jsoup.connect(url);
connection.data("__EVENTARGUMENT", "");
connection.data("__EVENTTARGET", "PageNavigator1$LnkBtnNext");
connection.data("__EVENTVALIDATION", event_validation);
connection.data("__VIEWSTATE", view_state);
connection.data("__VIEWSTATEGENERATOR", view_state_generator);
connection.data("Date", "30");
connection.data("tags", "");
Document document = connection.post();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
// 下一页的参数
String __VIEWSTATE = body.select("#__VIEWSTATE").first().attr("value").trim();
String __VIEWSTATEGENERATOR = body.select("#__VIEWSTATEGENERATOR").first().attr("value").trim();
String __EVENTVALIDATION = body.select("#__EVENTVALIDATION").first().attr("value").trim();
Map<String, String> newsForm = new HashMap<>();
newsForm.put("__VIEWSTATE", __VIEWSTATE);
newsForm.put("__VIEWSTATEGENERATOR", __VIEWSTATEGENERATOR);
newsForm.put("__EVENTVALIDATION", __EVENTVALIDATION);
// 本页的数据
Element photoList = body.getElementById("ListNews").getElementById("leftbox").getElementById("photolist");
List<News> newsList = getTagNews(photoList, newsType);
if (mView != null) {
mView.nextNewsListForm(newsForm);
mView.showNewsList(newsList);
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
mView.loadMoreFail();
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
Aggregations