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;
}
Aggregations