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++;
}
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;
}
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());
}
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);
}
}
Aggregations