Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_timeline);
- final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rvTweets);
- LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
- recyclerView.setLayoutManager(linearLayoutManager);
- scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) {
- @Override
- public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
- // Triggered only when new data needs to be appended to the list
- // Add whatever code is needed to append new items to the bottom of the list
- loadNextDataFromApi(page);
- tweets.add(null);
- adapter.notifyItemInserted(tweets.size() -1);
- }
- };
- recyclerView.addOnScrollListener(scrollListener);
- // Append the next page of data into the adapter
- // This method probably sends out a network request and appends new data items to your adapter.
- public void loadNextDataFromApi(int offset) {
- // Send an API request to retrieve appropriate paginated data
- // --> Send the request including an offset value (i.e `page`) as a query parameter.
- // --> Deserialize and construct new model objects from the API response
- // --> Append the new data objects to the existing set of items inside the array of items
- // --> Notify the adapter of the new items made with `notifyItemRangeInserted()`
- }
- client = TwitterApp.getRestClient(this);
- //find the swipeContainer view
- swipeContainer = findViewById(R.id.swipeContainer);
- //Find the recycler view
- // Configure the refreshing colors
- swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
- android.R.color.holo_green_light,
- android.R.color.holo_orange_light,
- android.R.color.holo_red_light);
- rvTweets = findViewById(R.id.rvTweets);
- //Initialize list of tweets and from the adapter from the data source
- tweets = new ArrayList<>();
- adapter = new TweetAdapter(this, tweets);
- //Recycler View setup: layout manager and setting the adapter
- rvTweets.setLayoutManager(new LinearLayoutManager(this ));
- rvTweets.setAdapter(adapter);
- populateHomeTimeline();
- swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- Log.d("TwitterClient","content is being refreshed");
- populateHomeTimeline();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement