Search in sources :

Example 1 with DisposableHolder

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

Example 2 with DisposableHolder

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));
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Element(org.jsoup.nodes.Element) DisposableHolder(com.vegen.smartcampus.baseframework.network.DisposableHolder) Document(org.jsoup.nodes.Document)

Example 3 with DisposableHolder

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));
}
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)

Example 4 with DisposableHolder

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

Aggregations

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