Search in sources :

Example 1 with PartyListViewholderAdapter

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

the class PartyListFragment 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);
    loadingView = view.findViewById(R.id.loading_view);
    partyListAdapter = new PartyListViewholderAdapter(documentList, new PartyListViewholderAdapter.OnPartyDocumentClickListener() {

        @Override
        public void onPartyDocumentClickListener(PartyDocument document) {
            Intent intent;
            if (document.isMotion()) {
                intent = new Intent(getContext(), MotionActivity.class);
            } else {
                intent = new Intent(getContext(), DocumentReaderActivity.class);
            }
            intent.putExtra("document", document);
            startActivity(intent);
        }
    });
    recyclerView = view.findViewById(R.id.recycler_view);
    recyclerView.setAdapter(partyListAdapter);
    recyclerView.setNestedScrollingEnabled(true);
    final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
    recyclerView.setLayoutManager(mLayoutManager);
    // Listener to determine when the scollview has reached the bottom. Then we load the next page
    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();
                }
            }
        }
    });
    itemsLoadingView = new ProgressBar(getContext());
    itemsLoadingView.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.primaryColor), android.graphics.PorterDuff.Mode.MULTIPLY);
    loadNextPage();
    return view;
}
Also used : Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DocumentReaderActivity(oscar.riksdagskollen.Activities.DocumentReaderActivity) PartyListViewholderAdapter(oscar.riksdagskollen.Utilities.PartyListViewholderAdapter) PartyDocument(oscar.riksdagskollen.Utilities.JSONModels.PartyDocument) MotionActivity(oscar.riksdagskollen.Activities.MotionActivity) RecyclerView(android.support.v7.widget.RecyclerView) ProgressBar(android.widget.ProgressBar) Nullable(android.support.annotation.Nullable)

Aggregations

Intent (android.content.Intent)1 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 ProgressBar (android.widget.ProgressBar)1 DocumentReaderActivity (oscar.riksdagskollen.Activities.DocumentReaderActivity)1 MotionActivity (oscar.riksdagskollen.Activities.MotionActivity)1 PartyDocument (oscar.riksdagskollen.Utilities.JSONModels.PartyDocument)1 PartyListViewholderAdapter (oscar.riksdagskollen.Utilities.PartyListViewholderAdapter)1