Search in sources :

Example 1 with PinnedHeaderEntity

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

the class Forum91IndexFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    unbinder = ButterKnife.bind(this, view);
    AppUtils.setColorSchemeColors(context, swipeLayout);
    swipeLayout.setOnRefreshListener(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
    recyclerView.addItemDecoration(new PinnedHeaderItemDecoration.Builder(BaseHeaderAdapter.TYPE_HEADER).setDividerId(R.drawable.divider).enableDivider(true).create());
    recyclerView.setAdapter(forum91PornIndexAdapter);
    forum91PornIndexAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            PinnedHeaderEntity<Forum91PronItem> forum91PronItemPinnedHeaderEntity = (PinnedHeaderEntity<Forum91PronItem>) adapter.getItem(position);
            if (forum91PronItemPinnedHeaderEntity == null || forum91PronItemPinnedHeaderEntity.getData() == null) {
                return;
            }
            Intent intent = new Intent(context, Browse91PornActivity.class);
            intent.putExtra(Keys.KEY_INTENT_BROWSE_FORUM_91_PORN_ITEM, forum91PronItemPinnedHeaderEntity.getData());
            startActivityWithAnimotion(intent);
        }
    });
}
Also used : Browse91PornActivity(com.dante.ui.porn91forum.browse91porn.Browse91PornActivity) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) Forum91PronItem(com.dante.data.model.Forum91PronItem) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) PinnedHeaderEntity(com.dante.data.model.PinnedHeaderEntity)

Example 2 with PinnedHeaderEntity

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

the class ParseForum91Porn method parseIndex.

public static BaseResult<List<PinnedHeaderEntity<Forum91PronItem>>> parseIndex(String html) {
    BaseResult<List<PinnedHeaderEntity<Forum91PronItem>>> baseResult = new BaseResult<>();
    Document doc = Jsoup.parse(html);
    Elements tds = doc.getElementsByAttributeValue("background", "images/listbg.gif");
    List<PinnedHeaderEntity<Forum91PronItem>> forum91PornItemSectionList = new ArrayList<>();
    for (Element td : tds) {
        Elements elements = td.select("a");
        if (td.select("a").first().attr("title").contains("最新精华")) {
            PinnedHeaderEntity<Forum91PronItem> pronItemPinnedHeaderEntity = new PinnedHeaderEntity<>(null, BaseHeaderAdapter.TYPE_HEADER, "最新精华");
            forum91PornItemSectionList.add(pronItemPinnedHeaderEntity);
        } else if (td.select("a").first().attr("title").contains("最新回复")) {
            PinnedHeaderEntity<Forum91PronItem> pronItemPinnedHeaderEntity = new PinnedHeaderEntity<>(null, BaseHeaderAdapter.TYPE_HEADER, "最新回复");
            forum91PornItemSectionList.add(pronItemPinnedHeaderEntity);
        } else {
            PinnedHeaderEntity<Forum91PronItem> pronItemPinnedHeaderEntity = new PinnedHeaderEntity<>(null, BaseHeaderAdapter.TYPE_HEADER, "本周热门");
            forum91PornItemSectionList.add(pronItemPinnedHeaderEntity);
        }
        for (Element element : elements) {
            Forum91PronItem forum91PronItem = new Forum91PronItem();
            String allInfo = element.attr("title").replaceAll("\n", "");
            int titleIndex = allInfo.indexOf("主题标题:");
            int authorIndex = allInfo.indexOf("主题作者:");
            int authorPublishTimeIndex = allInfo.indexOf("发表时间:");
            int viewCountIndex = allInfo.indexOf("浏览次数:");
            int replyCountIndex = allInfo.indexOf("回复次数:");
            int lastPostTimeIndex = allInfo.indexOf("最后回复:");
            int lastPostAuthorIndex = allInfo.indexOf("最后发表:");
            String title = StringUtils.subString(allInfo, titleIndex + 5, authorIndex);
            String author = StringUtils.subString(allInfo, authorIndex + 5, authorPublishTimeIndex);
            String authorPublishTime = StringUtils.subString(allInfo, authorPublishTimeIndex + 5, viewCountIndex);
            String viewCount = StringUtils.subString(allInfo, viewCountIndex + 5, replyCountIndex).replace("次", "").trim();
            String replyCount = StringUtils.subString(allInfo, replyCountIndex + 5, lastPostTimeIndex).replace("次", "").trim();
            String lastPostTime = StringUtils.subString(allInfo, lastPostTimeIndex + 5, lastPostAuthorIndex);
            String lastPostAuthor = StringUtils.subString(allInfo, lastPostAuthorIndex + 5, allInfo.length());
            forum91PronItem.setLastPostTime(lastPostTime);
            forum91PronItem.setLastPostAuthor(lastPostAuthor);
            forum91PronItem.setTitle(title);
            forum91PronItem.setAuthor(author);
            forum91PronItem.setViewCount(Long.parseLong(viewCount));
            forum91PronItem.setReplyCount(Long.parseLong(replyCount));
            forum91PronItem.setAuthorPublishTime(authorPublishTime);
            String contentUrl = element.attr("href");
            int starIndex = contentUrl.indexOf("tid=");
            String tidStr = StringUtils.subString(contentUrl, starIndex + 4, contentUrl.length());
            if (!TextUtils.isEmpty(tidStr) && TextUtils.isDigitsOnly(tidStr)) {
                forum91PronItem.setTid(Long.parseLong(tidStr));
            }
            PinnedHeaderEntity<Forum91PronItem> pronItemPinnedHeaderEntity = new PinnedHeaderEntity<>(forum91PronItem, BaseHeaderAdapter.TYPE_DATA, "");
            forum91PornItemSectionList.add(pronItemPinnedHeaderEntity);
        }
    }
    baseResult.setData(forum91PornItemSectionList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Element(org.jsoup.nodes.Element) Forum91PronItem(com.dante.data.model.Forum91PronItem) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) PinnedHeaderEntity(com.dante.data.model.PinnedHeaderEntity) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Forum91PronItem (com.dante.data.model.Forum91PronItem)2 PinnedHeaderEntity (com.dante.data.model.PinnedHeaderEntity)2 Intent (android.content.Intent)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 BaseResult (com.dante.data.model.BaseResult)1 Browse91PornActivity (com.dante.ui.porn91forum.browse91porn.Browse91PornActivity)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1