android-infinite-scroll
Demo application which aims to solve best practices for an "infinite" or "endless" scrolling newsfeed
Models will be stored in a Realm persistence layer and can be found here APIs / data sources can be found here
All Display business logic is separated into the NewsFeedPresenter. We are using an Model View Presenter architecture pattern to separate business and app logic from the UI. This allows us to more easily test business logic without having to worry about the intricacies of the UI.
When the user scrolls the NewsFeedActivity and NewsFeedAdapter will know to load more items ahead of time by checking if the last item that is visible is approaching our defined threshold. Currently, if there are only 5 items remaining in the list below the last currently visible item, the application will fetch more posts from the server unbeknownst to the user. This way, it simulates an infinite/endless scroll and the user isn't affected in any way. The user can fling their finger to scroll quickly, but the application will load more items with no visible pause (unless the network is slow). If the network is slow to load more items, there is a progressbar that will appear as the last item in the list to visually indicate that more items are being loaded.
There are 2 modules in this project:
api
- Android "Backend" data models and data sourcesapp
- Android Frontend client UI, MVP structures, all view and business logic
Goals: Android Client Backend
- Separate module which only exposes data sources with apis that provide immutable objects.
- Allows for data sources to be testable completely independent from UI
- Allows for easy switching out backend architecture, and as long as UI models and functions remain the same, the app shouldn’t break.
- Dependency Inversion Principle - UI has no knowledge of internal workings of network/caching architecture
- Only expose data models that must be exposed and only provide data sources via Dagger module
- OkHttpLogginInterceptor for debug builds to log network requests
Android Client UI
- Group packages by feature
- RecyclerView items - could optimize by using canvas and drawing own item views, but maintainability decreases due to increase in complexity here.
- Show placeholder image view frame or animated drawable for images while they’re loading
- Prefetch data and images with a buffer before items come into view so that users aren’t waiting on content to load
- Splash screen - give impression that it is loading quicker on cold boots
In a real client, there would be packages for Tests in each module, but due to timing, I do not have tests built out yet.