Search in sources :

Example 1 with ArticlesBean

use of com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean in project CloudReader by youlookwhat.

the class NavigationViewModel method getNavigationJson.

public void getNavigationJson() {
    Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getNaviJson().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<NaviJsonBean>() {

        @Override
        public void accept(NaviJsonBean naviJsonBean) throws Exception {
            if (naviJsonBean != null && naviJsonBean.getData() != null && naviJsonBean.getData().size() > 0) {
                // title
                dataTitle.setValue(naviJsonBean.getData());
                // content
                ArrayList<ArticlesBean> list = new ArrayList<>();
                // content部分对应分类的position
                ArrayList<Integer> positions = new ArrayList<>();
                for (int i = 0; i < naviJsonBean.getData().size(); i++) {
                    NaviJsonBean.DataBean dataBean = naviJsonBean.getData().get(i);
                    ArticlesBean bean = new ArticlesBean();
                    bean.setNavigationName(dataBean.getName());
                    positions.add(list.size());
                    if (i != 0) {
                        // 最后一个item可能有一个或两个
                        hashMap.put(list.size() - 1, i - 1);
                        hashMap.put(list.size() - 2, i - 1);
                    }
                    hashMap.put(list.size(), i);
                    list.add(bean);
                    list.addAll(dataBean.getArticles());
                }
                data.setValue(list);
                titlePositions.setValue(positions);
            } else {
                data.setValue(null);
                dataTitle.setValue(null);
            }
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            data.setValue(null);
            dataTitle.setValue(null);
        }
    });
    addDisposable(subscribe);
}
Also used : Disposable(io.reactivex.disposables.Disposable) NaviJsonBean(com.example.jingbin.cloudreader.bean.wanandroid.NaviJsonBean) ArticlesBean(com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean) ArrayList(java.util.ArrayList)

Example 2 with ArticlesBean

use of com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean in project CloudReader by youlookwhat.

the class NavigationFragment method initRefreshView.

private void initRefreshView() {
    mNaviAdapter = new NavigationAdapter();
    layoutManager = new LinearLayoutManager(activity);
    bindingView.xrvNavi.setLayoutManager(layoutManager);
    bindingView.xrvNavi.setAdapter(mNaviAdapter);
    mContentAdapter = new NavigationContentAdapter();
    StickyGridLayoutManager gridLayoutManager = new StickyGridLayoutManager(activity, 6, GridLayoutManager.VERTICAL, mContentAdapter);
    bindingView.xrvNaviDetail.setLayoutManager(gridLayoutManager);
    bindingView.xrvNaviDetail.setAdapter(mContentAdapter);
    mNaviAdapter.setOnSelectListener(new NavigationAdapter.OnSelectListener() {

        @Override
        public void onSelected(int position) {
            selectItem(position);
            moveToCenter(position);
            Integer titlePosition = viewModel.getTitlePositions().getValue().get(position);
            gridLayoutManager.scrollToPositionWithOffset(titlePosition, 0);
        }
    });
    bindingView.xrvNaviDetail.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int itemPosition = gridLayoutManager.findFirstVisibleItemPosition();
            Integer integer = viewModel.getHashMap().get(itemPosition);
            if (integer != null && currentPosition != integer) {
                selectItem(integer);
                moveToCenter(integer);
            }
        }
    });
    bindingView.xrvNaviDetail.setOnItemClickListener(new OnItemFilterClickListener() {

        @Override
        public void onSingleClick(View v, int position) {
            ArticlesBean itemData = mContentAdapter.getItemData(position);
            if (!TextUtils.isEmpty(itemData.getLink())) {
                WebViewActivity.loadUrl(v.getContext(), itemData.getLink(), itemData.getTitle());
            }
        }
    });
    onObserveViewModel();
}
Also used : NavigationAdapter(com.example.jingbin.cloudreader.adapter.NavigationAdapter) StickyGridLayoutManager(me.jingbin.library.stickyview.StickyGridLayoutManager) ArticlesBean(com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean) OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ByRecyclerView(me.jingbin.library.ByRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavigationContentAdapter(com.example.jingbin.cloudreader.adapter.NavigationContentAdapter) ByRecyclerView(me.jingbin.library.ByRecyclerView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

ArticlesBean (com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean)2 View (android.view.View)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 NavigationAdapter (com.example.jingbin.cloudreader.adapter.NavigationAdapter)1 NavigationContentAdapter (com.example.jingbin.cloudreader.adapter.NavigationContentAdapter)1 NaviJsonBean (com.example.jingbin.cloudreader.bean.wanandroid.NaviJsonBean)1 Disposable (io.reactivex.disposables.Disposable)1 ArrayList (java.util.ArrayList)1 ByRecyclerView (me.jingbin.library.ByRecyclerView)1 StickyGridLayoutManager (me.jingbin.library.stickyview.StickyGridLayoutManager)1 OnItemFilterClickListener (me.jingbin.library.view.OnItemFilterClickListener)1