android-mvvm
android-mvvm copied to clipboard
[Discussion] One Adapter to rule them all
There is a common pattern between ViewPagerAdapter and RecyclerViewAdapter, which will likely be present in other adapters to come.
This functionality can be extracted in a separate class MVVMAdapter perhaps.
All adapter methods would simply call methods of MVVMAdapter.
For users of library, it would then be possible to bind MVVMAdapter to all views (for basic functionality)
This abstract adapter would have the same three fields:
Observable<List<ViewModel>>ViewProviderViewModelBinder(Optional as library has a default instance)
In xml, its convenient to provide the first 2 fields separately as the sources are different. items come form the ViewModel, while ViewProvider comes from some static source.
Adapters provided by the library are simple ArrayAdapters. They take a list of VMS and display in a List of VMS.
More complex scenario could be possible. For example: SectionedAdapter which could take an Observable<List<List<ViewModels>> as an argument. At that point, separation between ArrayAdapter and SectionedAdapter would be required. Until then, this class doesn't provide much benefit.