Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. @Override
  2.     protected void onCreate(Bundle savedInstanceState) {
  3.         super.onCreate(savedInstanceState);
  4.         setContentView(R.layout.activity_timeline);
  5.         final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rvTweets);
  6.         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  7.         recyclerView.setLayoutManager(linearLayoutManager);
  8.         scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) {
  9.             @Override
  10.             public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
  11.                 // Triggered only when new data needs to be appended to the list
  12.                 // Add whatever code is needed to append new items to the bottom of the list
  13.                 loadNextDataFromApi(page);
  14.                 tweets.add(null);
  15.                 adapter.notifyItemInserted(tweets.size() -1);
  16.             }
  17.         };
  18.         recyclerView.addOnScrollListener(scrollListener);
  19.         // Append the next page of data into the adapter
  20.         // This method probably sends out a network request and appends new data items to your adapter.
  21.        public void loadNextDataFromApi(int offset) {
  22.             // Send an API request to retrieve appropriate paginated data
  23.  
  24.             //  --> Send the request including an offset value (i.e `page`) as a query parameter.
  25.  
  26.             //  --> Deserialize and construct new model objects from the API response
  27.             //  --> Append the new data objects to the existing set of items inside the array of items
  28.             //  --> Notify the adapter of the new items made with `notifyItemRangeInserted()`
  29.        }
  30.         client = TwitterApp.getRestClient(this);
  31.         //find the swipeContainer view
  32.         swipeContainer = findViewById(R.id.swipeContainer);
  33.         //Find the recycler view
  34.         // Configure the refreshing colors
  35.         swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
  36.                 android.R.color.holo_green_light,
  37.                 android.R.color.holo_orange_light,
  38.                 android.R.color.holo_red_light);
  39.         rvTweets = findViewById(R.id.rvTweets);
  40.         //Initialize list of tweets and from the adapter from the data source
  41.         tweets = new ArrayList<>();
  42.         adapter = new TweetAdapter(this, tweets);
  43.         //Recycler View setup: layout manager and setting  the adapter
  44.         rvTweets.setLayoutManager(new LinearLayoutManager(this ));
  45.         rvTweets.setAdapter(adapter);
  46.         populateHomeTimeline();
  47.         swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  48.             @Override
  49.             public void onRefresh() {
  50.                 Log.d("TwitterClient","content is being refreshed");
  51.                 populateHomeTimeline();
  52.             }
  53.         });
  54.  
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement