Search in sources :

Example 1 with Mm99

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

the class AppApiHelper method list99Mm.

@Override
public Observable<BaseResult<List<Mm99>>> list99Mm(String category, final int page, boolean cleanCache) {
    String url = buildUrl(category, page);
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(category, page);
    EvictDynamicKeyGroup evictDynamicKeyGroup = new EvictDynamicKeyGroup(cleanCache);
    return cacheProviders.cacheWithLimitTime(mm99ServiceApi.imageList(url), dynamicKeyGroup, evictDynamicKeyGroup).map(new Function<Reply<String>, String>() {

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

        @Override
        public BaseResult<List<Mm99>> apply(String s) {
            return Parse99Mm.parse99MmList(s, page);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) Mm99(com.dante.data.model.Mm99) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup)

Example 2 with Mm99

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

the class PictureViewerActivity method init.

private void init() {
    // fixSwipeBack();
    imageList = getIntent().getStringArrayListExtra(Keys.KEY_INTENT_PICTURE_VIEWER_IMAGE_ARRAY_LIST);
    int currentPosition = getIntent().getIntExtra(Keys.KEY_INTENT_PICTURE_VIEWER_CURRENT_IMAGE_POSITION, 0);
    updateNumberText(currentPosition);
    if (imageList == null) {
        imageList = new ArrayList<>();
    }
    pictureAdapter = new PictureAdapter(imageList);
    viewPager.setAdapter(pictureAdapter);
    viewPager.setCurrentItem(currentPosition);
    int id = getIntent().getIntExtra(Keys.KEY_INTENT_MEI_ZI_TU_CONTENT_ID, 0);
    if (id > 0) {
        presenter.listMeZiPicture(id, false);
    }
    Mm99 mm99 = (Mm99) getIntent().getSerializableExtra(Keys.KEY_INTENT_99_MM_ITEM);
    if (mm99 != null) {
        presenter.list99MmPicture(mm99.getId(), mm99.getImgUrl(), false);
    }
}
Also used : Mm99(com.dante.data.model.Mm99) PictureAdapter(com.dante.adapter.PictureAdapter) SuppressLint(android.annotation.SuppressLint)

Example 3 with Mm99

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

the class Parse99Mm method parse99MmList.

public static BaseResult<List<Mm99>> parse99MmList(String html, int page) {
    BaseResult<List<Mm99>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Logger.t(TAG).d(html);
    Document doc = Jsoup.parse(html);
    Element ul = doc.getElementById("piclist");
    Elements lis = ul.select("li");
    List<Mm99> mm99List = new ArrayList<>();
    for (Element li : lis) {
        Mm99 mm99 = new Mm99();
        Element a = li.selectFirst("dt").selectFirst("a");
        String contentUrl = "http://www.99mm.me" + a.attr("href");
        mm99.setContentUrl(contentUrl);
        int startIndex = contentUrl.lastIndexOf("/");
        int endIndex = contentUrl.lastIndexOf(".");
        String idStr = StringUtils.subString(contentUrl, startIndex + 1, endIndex);
        if (!TextUtils.isEmpty(idStr) && TextUtils.isDigitsOnly(idStr)) {
            mm99.setId(Integer.parseInt(idStr));
        } else {
            Logger.t(TAG).d(idStr);
        }
        Element img = a.selectFirst("img");
        String title = img.attr("alt");
        mm99.setTitle(title);
        String imgUrl = img.attr("src");
        mm99.setImgUrl(imgUrl);
        int imgWidth = Integer.parseInt(img.attr("width"));
        mm99.setImgWidth(imgWidth);
        mm99List.add(mm99);
    }
    if (page == 1) {
        Element pageElement = doc.getElementsByClass("all").first();
        if (pageElement != null) {
            String pageStr = pageElement.text().replace("...", "").trim();
            if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
                baseResult.setTotalPage(Integer.parseInt(pageStr));
            } else {
                Logger.t(TAG).d(pageStr);
            }
        }
    }
    baseResult.setData(mm99List);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Mm99(com.dante.data.model.Mm99) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 4 with Mm99

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

the class Mm99Fragment 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(mm99Adapter);
    mm99Adapter.setWidth(QMUIDisplayHelper.getScreenWidth(context) / 2);
    mm99Adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {

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

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

Aggregations

Mm99 (com.dante.data.model.Mm99)4 BaseResult (com.dante.data.model.BaseResult)2 SuppressLint (android.annotation.SuppressLint)1 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 PictureAdapter (com.dante.adapter.PictureAdapter)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 Elements (org.jsoup.select.Elements)1