Search in sources :

Example 1 with NewsList

use of com.itculturalfestival.smartcampus.entity.NewsList 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));
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Element(org.jsoup.nodes.Element) DisposableHolder(com.vegen.smartcampus.baseframework.network.DisposableHolder) ArrayList(java.util.ArrayList) NewsList(com.itculturalfestival.smartcampus.entity.NewsList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

NewsList (com.itculturalfestival.smartcampus.entity.NewsList)1 DisposableHolder (com.vegen.smartcampus.baseframework.network.DisposableHolder)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 Disposable (io.reactivex.disposables.Disposable)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1