Search in sources :

Example 1 with CurrentNewsListAdapter

use of oscar.riksdagskollen.Utilities.CurrentNewsListAdapter in project Riksdagskollen by OAndell.

the class CurrentNewsListFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_party_list, null);
    currentNewsListAdapter = new CurrentNewsListAdapter(newsList);
    recyclerView = view.findViewById(R.id.recycler_view);
    recyclerView.setAdapter(currentNewsListAdapter);
    recyclerView.setNestedScrollingEnabled(true);
    final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (// check for scroll down
            dy > 0) {
                int visibleItemCount = mLayoutManager.getChildCount();
                int totalItemCount = mLayoutManager.getItemCount();
                pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    if (!loading)
                        loadNextPage();
                }
            }
        }
    });
    loadingView = view.findViewById(R.id.loading_view);
    loadNextPage();
    return view;
}
Also used : CurrentNewsListAdapter(oscar.riksdagskollen.Utilities.CurrentNewsListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 CurrentNewsListAdapter (oscar.riksdagskollen.Utilities.CurrentNewsListAdapter)1