08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Recycler mvp
1. RECYCLER VIEW - MVP
By Bhavya Rattan
Handling Pagination, Tap To
Retry, No Internet Connection
and Swipe Refresh
simultaneously
2. The first and most confusing question when you start working on
a screen to display list of items is “Where do I keep the Data
List?”. The answer is debatable and there are 2 approaches to it :
1. Keep data list in the Presenter Implementer class
2. Keep data list in the Activity that implements
View class
Where do I keep the Data List ?
3. Pros :
● Presenter gets full control over data and data manipulation is easy
● Lesser to and fro between view, presenter and interactor
● Data manipulation is easy
● Easy to implement pagination
Cons :
● State maintenance is tricky
Approach 1 - Keeping data list in Presenter
Implementer :
4. Pros :
● Easy state maintenance - as activity life cycle is automatically followed
● Eliminates data manipulation operations from presenter
Cons :
● Additional overhead to fetch data from presenter - making the cycle like : view
requests data - calls presenter - presenter calls interactor - presenter returns data
back to view
● Data manipulation involves tedious to and fro between presenter and view
● Difficult to implement pagination as count and skip values are again to be fetched
from View - resulting in presenter-view communication overhead
Approach 2 - Keeping data list in Activity :
PS : We have followed Approach 1 in the project repository and would be
discussing same in upcoming slides
5. Handling Pagination
● We have handled pagination using limit and skip, where :
● Limit : specifies the number of items you want to fetch from server
● Skip : specifies the number of items to be skipped, beginning from 1st item.
Server skips items upto skip value and returns next consecutive items
● Total count : this value is provided by server in response and it specifies the
total number of items in the data list
● By default we have initialized limit to 10, skip to 0 and total count to -1 in the
project, after response from server updating values to : skip = dataList.size()
and total count = value fetched from server
To stop loading after all data is fetched :
if (totalCount != -1 && totalCount <= skip) {
mNotificationView.hideRecyclerLoader();
return;
}
6. Handling Screen
states through
Recycler Items
● VIEW_ITEM : How the default data item
would be displayed
● VIEW_PROG : To display progress loader
at bottom while fetching next page data
● VIEW_RETRY : To display Retry image
view at bottom when any failure occurs
while fetching next page
● VIEW_ERROR : To display error message
in case of failure
● VIEW_NO_DATA : To display “No Data
message” in case the list returned from
server is empty
Methods in recycler :
● showLoading
● dismissLoading
● addAll
● addItemMore
● displayErrorMessage
● displayNoDataString
● displayRetryView
● hideRetryView
7. Methods in recycler Explained:
/**
* show progress loader at bottom while recycler view
* is loading more items on scroll
*/
public void showLoading() {
if (isMoreLoading && notifications != null && onLoadMoreListener != null) {
isMoreLoading = false;
new Handler().post(new Runnable() {
@Override
public void run() {
notifications.add(new Notification());
notifications.get(notifications.size() - 1).setItemType(VIEW_PROG);
notifyItemInserted(notifications.size() - 1);
onLoadMoreListener.onLoadMore();
}
});
}
}
8. Methods in recycler Explained:
/**
* dismiss progress loader shown at bottom
* after the onLoadMore() method has performed its task
* and new data is added to recycler view.
* This function removes the progress loader item added at end of recycler view list
*/
public void dismissLoading() {
if (notifications != null && notifications.size() > 0
&& notifications.get(notifications.size() - 1).getItemType() ==
VIEW_PROG) {
notifications.remove(notifications.size() - 1);
notifyItemRemoved(notifications.size());
}
}
9. Methods in recycler Explained:
/**
* add all items to notification list, called
* to initialize the list a fresh
*
* @param allNotifications notification list
*/
public void addAll(final ArrayList<Notification> allNotifications) {
notifications.clear();
notifications.addAll(allNotifications);
notifyDataSetChanged();
}
10. Methods in recycler Explained:
/**
* add more items to notification list on scroll
*
* @param moreNotifications notification list
*/
public void addItemMore(final ArrayList<Notification> moreNotifications) {
int sizeInit = notifications.size();
notifications.addAll(moreNotifications);
notifyItemRangeChanged(sizeInit, notifications.size());
}
11. Methods in recycler Explained:
/**
* In case of an error
* clear the recycler view list and add a null value item
* notify adapter that data set has changed
* show error message to user
*
* @param message error message to be displayed
*/
public void displayErrorMessage(final String message) {
errorMessage = message;
notifications.clear();
notifications.add(new Notification());
notifications.get(notifications.size() - 1).setItemType(VIEW_ERROR);
notifyDataSetChanged();
}
12. Methods in recycler Explained:
/**
* In case the list of data received from server
* is empty
* show no data message to user
*
* @param message no data message to be displayed
*/
public void displayNoDataString(final String message) {
noDataString = message;
notifications.clear();
notifications.add(new Notification());
notifications.get(notifications.size() - 1).setItemType(VIEW_NO_DATA);
notifyDataSetChanged();
}
13. Methods in recycler Explained:
/**
*
*/
public void displayRetryView() {
if (notifications.get(notifications.size() - 1).getItemType() != VIEW_RETRY) {
notifications.add(new Notification());
notifications.get(notifications.size() - 1).setItemType(VIEW_RETRY);
notifyItemInserted(notifications.size() - 1);
}
}