Search in sources :

Example 1 with MeiZiTu

use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.

the class AppApiHelper method action.

private Observable<BaseResult<List<MeiZiTu>>> action(Observable<String> stringObservable, String tag, final int page, final boolean pullToRefresh) {
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(tag, page);
    EvictDynamicKeyGroup evictDynamicKeyGroup = new EvictDynamicKeyGroup(pullToRefresh);
    return cacheProviders.meiZiTu(stringObservable, dynamicKeyGroup, evictDynamicKeyGroup).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> stringReply) throws Exception {
            return stringReply.getData();
        }
    }).map(new Function<String, BaseResult<List<MeiZiTu>>>() {

        @Override
        public BaseResult<List<MeiZiTu>> apply(String s) throws Exception {
            return ParseMeiZiTu.parseMzPosts(s, page);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) MeiZiTu(com.dante.data.model.MeiZiTu) ParseMeiZiTu(com.dante.parser.ParseMeiZiTu) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 2 with MeiZiTu

use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.

the class MeiZiTuFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    unbinder = ButterKnife.bind(this, view);
    swipeLayout.setOnRefreshListener(this);
    AppUtils.setColorSchemeColors(context, swipeLayout);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(meiZiTuAdapter);
    meiZiTuAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            loadData(false, false);
        }
    }, recyclerView);
    meiZiTuAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            MeiZiTu meiZiTu = (MeiZiTu) adapter.getItem(position);
            if (meiZiTu == null) {
                return;
            }
            Intent intent = new Intent(context, PictureViewerActivity.class);
            intent.putExtra(Keys.KEY_INTENT_MEI_ZI_TU_CONTENT_ID, meiZiTu.getId());
            startActivityWithAnimotion(intent);
        }
    });
}
Also used : BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) MeiZiTu(com.dante.data.model.MeiZiTu) Intent(android.content.Intent) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) PictureViewerActivity(com.dante.ui.images.viewimage.PictureViewerActivity)

Example 3 with MeiZiTu

use of com.dante.data.model.MeiZiTu in project 91Pop by DanteAndroid.

the class ParseMeiZiTu method parseMzPosts.

public static BaseResult<List<MeiZiTu>> parseMzPosts(String html, int page) {
    BaseResult<List<MeiZiTu>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Document doc = Jsoup.parse(html);
    Element ulPins = doc.getElementById("pins");
    Elements lis = ulPins.select("li");
    List<MeiZiTu> meiZiTuList = new ArrayList<>();
    for (Element li : lis) {
        MeiZiTu meiZiTu = new MeiZiTu();
        String contentUrl = li.select("a").first().attr("href");
        // meiZiTu.setContentUrl(contentUrl);
        int index = contentUrl.lastIndexOf("/");
        if (index >= 0 && index + 1 < contentUrl.length()) {
            String idStr = contentUrl.substring(index + 1, contentUrl.length());
            Logger.t(TAG).d(idStr);
            if (!TextUtils.isEmpty(idStr) && TextUtils.isDigitsOnly(idStr)) {
                meiZiTu.setId(Integer.parseInt(idStr));
            }
        }
        Element imageElement = li.selectFirst("img");
        String name = imageElement.attr("alt");
        meiZiTu.setName(name);
        String thumbUrl = imageElement.attr("data-original");
        meiZiTu.setThumbUrl(thumbUrl);
        Logger.t(TAG).d(thumbUrl);
        int height = Integer.parseInt(imageElement.attr("height"));
        meiZiTu.setHeight(height);
        int width = Integer.parseInt(imageElement.attr("width"));
        meiZiTu.setWidth(width);
        String date = li.getElementsByClass("time").first().text();
        meiZiTu.setDate(date);
        String viewCount = li.getElementsByClass("view").first().text();
        meiZiTu.setViewCount(viewCount);
        meiZiTuList.add(meiZiTu);
    }
    Logger.t(TAG).d("size::" + meiZiTuList.size());
    if (page == 1) {
        Elements pageElements = doc.getElementsByClass("page-numbers");
        if (pageElements != null && pageElements.size() > 3) {
            String pageStr = pageElements.get(pageElements.size() - 2).text();
            Logger.t(TAG).d("totalPage::" + pageStr);
            if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
                baseResult.setTotalPage(Integer.parseInt(pageStr));
            }
        }
    }
    baseResult.setData(meiZiTuList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MeiZiTu(com.dante.data.model.MeiZiTu) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

MeiZiTu (com.dante.data.model.MeiZiTu)3 BaseResult (com.dante.data.model.BaseResult)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 View (android.view.View)1 BindView (butterknife.BindView)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 FavoriteException (com.dante.exception.FavoriteException)1 MessageException (com.dante.exception.MessageException)1 ParseMeiZiTu (com.dante.parser.ParseMeiZiTu)1 PictureViewerActivity (com.dante.ui.images.viewimage.PictureViewerActivity)1 Function (io.reactivex.functions.Function)1 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)1 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)1 Reply (io.rx_cache2.Reply)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1