SlideShare a Scribd company logo
1 of 16
RECYCLER VIEW - MVP
By Bhavya Rattan
Handling Pagination, Tap To
Retry, No Internet Connection
and Swipe Refresh
simultaneously
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 ?
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 :
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
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;
}
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
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();
}
});
}
}
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());
}
}
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();
}
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());
}
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();
}
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();
}
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);
}
}
Methods in recycler Explained:
/**
*
*/
public void hideRetryView() {
if (notifications != null && notifications.size() > 0
&& notifications.get(notifications.size() - 1).getItemType() ==
VIEW_RETRY) {
notifications.remove(notifications.size() - 1);
notifyItemRemoved(notifications.size());
}
}
References :
● Find the code at :
https://git.clicklabs.in/ClickLabs/
juggernaut-android-mvp.git,
recycler_module branch
● https://android.jlelse.eu/recyclerv
iew-in-mvp-passive-views-
approach-8dd74633158
● http://bajicdusko.com/2017/recy
cler-view-in-MVP/
● http://codetoart.com/implementat
ion-of-model-view-presenter-mvp-
design-pattern-on-android/
Recycler   mvp

More Related Content

What's hot

Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intentDiego Grancini
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Bpel activities to upload club oracle
Bpel activities to upload club oracleBpel activities to upload club oracle
Bpel activities to upload club oracleXAVIERCONSULTANTS
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in AndroidPerfect APK
 

What's hot (6)

React hooks
React hooksReact hooks
React hooks
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Bpel activities to upload club oracle
Bpel activities to upload club oracleBpel activities to upload club oracle
Bpel activities to upload club oracle
 
Hot React Hooks
Hot React HooksHot React Hooks
Hot React Hooks
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in Android
 

Similar to Recycler mvp

SH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptxSH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptxMongoDB
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
Thinking metrics on React apps
Thinking metrics on React appsThinking metrics on React apps
Thinking metrics on React appsJean Carlo Emer
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialKaty Slemon
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
Android app performance
Android app performanceAndroid app performance
Android app performanceSaksham Keshri
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practicesClickky
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...Nagios
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.AngularEvan Schultz
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informaticaBhuvana Priya
 

Similar to Recycler mvp (20)

SH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptxSH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptx
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
Thinking metrics on React apps
Thinking metrics on React appsThinking metrics on React apps
Thinking metrics on React apps
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorial
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Android app performance
Android app performanceAndroid app performance
Android app performance
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
 
Generic steps in informatica
Generic steps in informaticaGeneric steps in informatica
Generic steps in informatica
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
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); } }
  • 14. Methods in recycler Explained: /** * */ public void hideRetryView() { if (notifications != null && notifications.size() > 0 && notifications.get(notifications.size() - 1).getItemType() == VIEW_RETRY) { notifications.remove(notifications.size() - 1); notifyItemRemoved(notifications.size()); } }
  • 15. References : ● Find the code at : https://git.clicklabs.in/ClickLabs/ juggernaut-android-mvp.git, recycler_module branch ● https://android.jlelse.eu/recyclerv iew-in-mvp-passive-views- approach-8dd74633158 ● http://bajicdusko.com/2017/recy cler-view-in-MVP/ ● http://codetoart.com/implementat ion-of-model-view-presenter-mvp- design-pattern-on-android/