Adapter


Source link: https://github.com/ThePacific/adapter

Adapter

A quick adapter library for RecyclerView, GridView, ListView, ViewPager, Spinner. It abstracts the boilerplate of item view types, item layouts, viewholders, span sizes , and more, in order to simplify building complex screens with multiple view types. 1.x is deprecated and please upgrade to 2.x

Features

  • Support DataBinding.
  • Multiple view types without any ViewHolder
  • Simple, flexible

Setup

compile 'com.github.thepacific:adapter:{
lastestVersion
}
'

Proguard

-keep class android.databinding.DataBindingUtil {

 public static *; 
}

Item

Extend SimpleItem or SimpleRecylcerItem. Optionally, you may implement Item or RecylcerItem

public class YourItem extends SimpleItem {

  String name;
  String description;
  String imageUrl;

@Override
  public int getLayout() {

return R.layout.item_cartoon;
  
}

@Override
  public void bind(ViewHolder holder) {

//bind data

DefaultBinding binding = holder.binding();

binding.setText(R.id.text_name, name);

binding.setText(R.id.text_desc, description);

 //attach listeners or load image

holder.attachImageLoader(R.id.img_header);

holder.attachOnClickListener(R.id.layout_root);

 //holder.attachOnLongClickListener(viewId);


//holder.attachOnTouchListener(viewId);


//holder.attachOnCheckedChangeListener(viewId);

  
}

//You may override any other method 
}

DataBinding

public class YourItem extends SimpleItem {

  @Override
  public void bind(ViewHolder holder) {

//Without DataBinding, just use DefaultBinding

DefaultBinding binding = holder.binding();

 //With DataBinding, use layout generated Binding instead of DefaultBinding

LayoutGeneratedBinding binding = holder.binding();

  
}
 
}

Listeners

Set OnClickListener, OnLongClickListener, OnTouchListener, OnCheckedChangeListener and ImageLoader:

RecyclerAdapter adapter = new RecyclerAdapter();
 //RecyclerView AbsAdapter adapter = new AbsAdapter(int viewTypeCount);
//GridView, ListView, Spinner PagerAdapter2 adapter2 =new PagerAdapter2();
//ViewPager  //set listeners or ImageLoader adapter.setOnClickListener(OnClickListener listener);
 adapter.setOnTouchListener(OnTouchListener listener);
 adapter.setOnLongClickListener(OnLongClickListener listener);
 adapter.setOnCheckedChangeListener(OnCheckedChangeListener listener);
 adapter.setImageLoader(ImageLoader imageLoader);
  adapter.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {

//get ViewHolder

ViewHolder holder = AdapterUtil.getHolder(v);

 //find view in ItemView

TextView textName = AdapterUtil.findView(holder.itemView, R.id.text_name);

 //get Item

Item item = holder.getItem();

 //get adapter data size

int size = holder.getSize();

 holder.isFirstItem();

holder.isLastItem();

 //for ListView,GridView, ViewPager, Spinner and RecyclerView

int position = holder.getCurrentPosition();

 //only for RecyclerView

int position = holder.getAdapterPosition();

  
}
 
}
);
  adapter.setImageLoader((imageView, holder) -> {

  YourItem item = holder.getItem();

  Glide.with(this)

  .load(item.imageUrl())

  .fitCenter()

  .into(imageView);
 
}
);

Others

adapter.setOnDataSetChanged(OnDataSetChanged onDataSetChanged);
  //data set changed callback , it's useful to show or hide empty view public interface OnDataSetChanged {

  //called when data size is 0
  void onEmptyData();

//called when data size larger than 0
  void onHasData();
 
}

License

The MIT License

Resources

The usual Toast, but with steroids.

Awesome digital speedometer for android.

Juste a funcy button with progress bar.

Proteus is meant to be a drop-in replacement for Android’s LayoutInflater; but unlike the compiled XML layouts bundled in the APK, Proteus inflates layouts at runtime.

With Proteus, you can control your Apps layout from the backend (no WebViews). Forget the boilerplate code to findViewById, cast it to a TextView, and then setText(). Proteus has runtime data bindings and formatters. Plugin in your own custom views and attributes and formatters.

SmartDeviceLink (SDL) is a standard set of protocols and messages that connect applications on a smartphone to a vehicle head unit. This messaging enables a consumer to interact with their application using common in-vehicle interfaces such as a touch screen display, embedded voice recognition, steering wheel controls and various vehicle knobs and buttons. There are three main components that make up the SDL ecosystem.

Simple custom ImageView for android giving you a simple way to enable overlapping of two images one over the other.

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