Search in sources :

Example 1 with ImageAdapter

use of com.funstill.kelefun.adapter.ImageAdapter in project keleFanfou by kelefun.

the class ImageListFragment method initView.

private void initView(View view) {
    SwipeRefreshLayout mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.line_swipe_refresh);
    // 禁用下拉刷新
    mRefreshLayout.setEnabled(false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.line_recycler);
    StaggeredGridLayoutManager mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ImageAdapter(getActivity(), data);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            lastPositions = mLayoutManager.findLastVisibleItemPositions(lastPositions);
            super.onScrolled(recyclerView, dx, dy);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (lastPositions == null || lastPositions.length == 0) {
                return;
            }
            lastVisibleItemPosition = getMax(lastPositions);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && (lastVisibleItemPosition + 1 >= mLayoutManager.getItemCount()) && !isLoadingMore) {
                if (data.size() > 0) {
                    Map<String, String> loadMoreParam = new ArrayMap<>();
                    loadMoreParam.put("max_id", data.get(data.size() - 1).getId());
                    loadMoreParam.put("count", "25");
                    loadMoreMentions(loadMoreParam);
                }
            }
        }
    });
}
Also used : ImageAdapter(com.funstill.kelefun.adapter.ImageAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Map(java.util.Map) ArrayMap(android.util.ArrayMap)

Example 2 with ImageAdapter

use of com.funstill.kelefun.adapter.ImageAdapter in project keleFanfou by kelefun.

the class ImageListFragment method initView.

private void initView(View view) {
    mRecyclerView = (RecyclerView) view.findViewById(R.id.line_recycler);
    StaggeredGridLayoutManager mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ImageAdapter(getActivity(), data);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            lastPositions = mLayoutManager.findLastVisibleItemPositions(lastPositions);
            super.onScrolled(recyclerView, dx, dy);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (lastPositions == null || lastPositions.length == 0) {
                return;
            }
            lastVisibleItemPosition = getMax(lastPositions);
            if (newState == RecyclerView.SCROLL_STATE_IDLE && (lastVisibleItemPosition + 1 >= mLayoutManager.getItemCount()) && !isLoadingMore) {
                if (data.size() > 0) {
                    Map<String, String> loadMoreParam = new ArrayMap<>();
                    loadMoreParam.put("max_id", data.get(data.size() - 1).getId());
                    loadMoreParam.put("count", "15");
                    loadMoreMentions(loadMoreParam);
                }
            }
        }
    });
}
Also used : ImageAdapter(com.funstill.kelefun.adapter.ImageAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) Map(java.util.Map) ArrayMap(android.util.ArrayMap)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 ArrayMap (android.util.ArrayMap)2 ImageAdapter (com.funstill.kelefun.adapter.ImageAdapter)2 Map (java.util.Map)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1