DataBindingAdapter


Source link: https://github.com/markzhai/DataBindingAdapter

DataBinding RecyclerViewAdapter

??? README

Free from writing adapters! NO MORE CLASSES!

Super simple RecyclerView adapter using Data Binding Technology, no longer need to write any adapter! You don't need to write any extra class like ViewHolder or ItemView.

One more reason you should try Data Binding!

Get Started

dependencies {

  compile 'com.github.markzhai:databinding-rv-adapter:1.0.1' 
}

This library provide two types of RecyclerView.Adapter.

SingleTypeAdapter:

SingleTypeAdapter<EmployeeViewModel> adapter = new SingleTypeAdapter<>(this, R.layout.item_single_type);

MultiTypeAdapter:

MultiTypeAdapter adapter = new MultiTypeAdapter(this);
 adapter.addViewTypeToLayoutMap(VIEW_TYPE_HEADER, R.layout.item_header);
 adapter.addViewTypeToLayoutMap(VIEW_TYPE_CODER, R.layout.item_coder);
 adapter.addViewTypeToLayoutMap(VIEW_TYPE_BOSS, R.layout.item_boss);

The only limitation is naming convention: your view model in xml should be named item, and your presenter should be named presenter, which I do think is a good practice.

Advanced Usage

Manipulation

singleTypeAdapter.addAll(EMPLOYEE_LIST);
 // clear and addAll singleTypeAdapter.set(EMPLOYEE_LIST);
 singleTypeAdapter.add(employee);
 // add with specific position singleTypeAdapter.add(2, employee);
  multiTypeAdapter.add(null, VIEW_TYPE_HEADER);
 multiTypeAdapter.addAll(EMPLOYEE_LIST, VIEW_TYPE_EMPLOYEE);
 multiTypeAdapter.addAll(EMPLOYER_LIST, VIEW_TYPE_EMPLOYER);
 multiTypeAdapter.add(2, employee, VIEW_TYPE_EMPLOYEE);
  // Like clear + addAll multiTypeAdapter.set(EMPLOYEE_LIST, VIEW_TYPE_EMPLOYEE);
  // both have these methods adapter.clear();
 adapter.remove(2);

Listener Binding

The library also provide an easy way to add listener binding, and by default provide a whole item click listener.

public class DemoAdapterPresenter implements BaseViewAdapter.Presenter {

  public void onItemClick(EmployeeViewModel model) {

Toast.makeText(MainActivity.this, "employee " + model.name, Toast.LENGTH_SHORT).show();

}

  public void onItemClick(EmployerViewModel model) {

Toast.makeText(MainActivity.this, "employer " + model.name, Toast.LENGTH_SHORT).show();

  
}
 
}
  multiTypeAdapter.setPresenter(new DemoAdapterPresenter());
  singleTypeAdapter.setPresenter(new SingleTypeAdapter.Presenter<EmployeeViewModel>() {

@Override
  public void onItemClick(EmployeeViewModel model) {

Toast.makeText(MainActivity.this, model.name, Toast.LENGTH_SHORT).show();

  
}
 
}
);

Decorator

Sometimes, we may want to do some extra works in onBindViewHolder, thus we provide a Decorator to let user implement and set it in.

public class DemoAdapterDecorator implements BaseViewAdapter.Decorator {

@Override
  public void decorator(BindingViewHolder holder, int position, int viewType) {

// you may do something according to position or view type
  
}
 
}
  adapter.setDecorator(new DemoAdapterDecorator());

Contributors

Welcome for issues and PR to fulfill your own features.

You may have interest in

They are somehow likely and powerful, enable you to save codes. However, both of them have the problems that lose flexibility and force you to create something like a wrapper which is annoyed.

License

Copyright (C) 2016 MarkZhai (http://zhaiyifan.cn).  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Magnet rest2mobile generates native code for mobile apps from REST APIs. It turns actual REST requests and responses into source code (Objective-C, Android, and JavaScript) that you can call from your mobile app. The source code automatically handles:

  • server connections
  • marshalling and unmarshalling JSON data
  • JSON data conversion into the native object types

This library is a version of Joda-Time built with Android in mind.

A SlidingPaneLayout that is partially visible, with a cross fade.

Compatibility library for dealing with various device photo albums.

Photo image selection activity set library.

Android-Device-Compatibility just yet another compatibility package for Android. This project aims to make the app compatible with various devices all over the world. The project will take care about lots of issues caused by device differences, so you don't need to write a weird compatibility code on your own.

Features:

  • Workarounds for device-specific problems
  • OS version compatibility
  • OS framework bug-fixes

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes