Search in sources :

Example 1 with PartyDocument

use of oscar.riksdagskollen.Utilities.JSONModels.PartyDocument in project Riksdagskollen by OAndell.

the class PartyListFragment method loadNextPage.

/**
 * Load the next page and add it to the adapter when downloaded and parsed.
 * Hides the loading view.
 */
private void loadNextPage() {
    setLoading(true);
    RikdagskollenApp.getInstance().getRiksdagenAPIManager().getDocumentsForParty(party, pageToLoad, new PartyDocumentCallback() {

        @Override
        public void onDocumentsFetched(List<PartyDocument> documents) {
            loadingView.setVisibility(View.GONE);
            documentList.addAll(documents);
            partyListAdapter.notifyDataSetChanged();
            setLoading(false);
        }

        @Override
        public void onFail(VolleyError error) {
            setLoading(false);
            pageToLoad--;
        }
    });
    pageToLoad++;
}
Also used : VolleyError(com.android.volley.VolleyError) PartyDocument(oscar.riksdagskollen.Utilities.JSONModels.PartyDocument) PartyDocumentCallback(oscar.riksdagskollen.Utilities.Callbacks.PartyDocumentCallback)

Example 2 with PartyDocument

use of oscar.riksdagskollen.Utilities.JSONModels.PartyDocument 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)

Example 3 with PartyDocument

use of oscar.riksdagskollen.Utilities.JSONModels.PartyDocument in project Riksdagskollen by OAndell.

the class PartyListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    PartyDocument partyDocument = documentList.get(position);
    holder.publicerad.setText(partyDocument.getPublicerad());
    holder.document.setText(partyDocument.getTitel());
}
Also used : PartyDocument(oscar.riksdagskollen.Utilities.JSONModels.PartyDocument)

Example 4 with PartyDocument

use of oscar.riksdagskollen.Utilities.JSONModels.PartyDocument in project Riksdagskollen by OAndell.

the class PartyListViewholderAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (position < headers.size()) {
        View v = headers.get(position);
        // add our view to a header view and display it
        prepareHeaderFooter((HeaderFooterViewHolder) holder, v);
    } else if (position >= headers.size() + documentList.size()) {
        View v = footers.get(position - documentList.size() - headers.size());
        // add our view to a footer view and display it
        prepareHeaderFooter((HeaderFooterViewHolder) holder, v);
    } else {
        PartyDocument document = documentList.get(position);
        ((MyViewHolder) holder).bind(document, clickListener);
    }
}
Also used : PartyDocument(oscar.riksdagskollen.Utilities.JSONModels.PartyDocument) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

PartyDocument (oscar.riksdagskollen.Utilities.JSONModels.PartyDocument)4 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 Intent (android.content.Intent)1 Nullable (android.support.annotation.Nullable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 AdapterView (android.widget.AdapterView)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 VolleyError (com.android.volley.VolleyError)1 DocumentReaderActivity (oscar.riksdagskollen.Activities.DocumentReaderActivity)1 MotionActivity (oscar.riksdagskollen.Activities.MotionActivity)1 PartyDocumentCallback (oscar.riksdagskollen.Utilities.Callbacks.PartyDocumentCallback)1 PartyListViewholderAdapter (oscar.riksdagskollen.Utilities.PartyListViewholderAdapter)1