WonderAdapter


Source link: https://github.com/cesards/WonderAdapter

WonderAdapter

How many times do you copy ArrayAdapter, CursorAdapter and ViewHolders code? I've developed this library based mostly on the idea of UniversalAdapter library, but I've implemented a few improvements like ViewHolder pattern, multi view and cursor compatibility.

Screenshots

Usage

You just have to use the adapter that fits better to your needs. For now, there are only 3 wonder adapters you can use:

  • WArrayAdapter
  • WBaseAdapter
  • WCursorAdapter

Steps to use any of these adapters within a ListView:

  1. Create Custom Holder and let implement SingleWonder, MultiWonder or CursorWonder depending on the Adapter we want to use with. ..* T is the class of the item we want to show. ..* W the Holder class.
  2. Basic methods to implement (on single views): ..* W newInstance() returns an instance of W(holder) for every row in the list. Our holder contains row view fields initialized. ..* void bind(...) needed to draw desired object fields on the initialized view fields contained inside our class W. ..* View inflateView(...) needs explanation? :-).

Example: ListView with array list of items within a single row view

WArrayAdapter<Wonder, SingleViewHolder> adapter = new WArrayAdapter(this, getData(cursor), new SingleViewHolder());
 listView.setAdapter(adapter);

and our SingleViewHolder implementation:

public class SingleViewHolder implements SingleWonder<Wonder, SingleViewHolder> {

 // UI
@InjectView(R.id.row_wonder_image) ImageView imageView;
@InjectView(R.id.row_wonder_title) TextView titleView;
 @Override public SingleViewHolder newInstance() {

  return new SingleViewHolder();

}

 @Override public void bind(Context context, Wonder item) {

  Picasso.with(context).load(item.getImage()).into(imageView);

  titleView.setText(item.getTitle());

}

 @Override public View inflateView(LayoutInflater inflater, ViewGroup parent) {

  View view = inflater.inflate(R.layout.row_wonder, parent, false);

  ButterKnife.inject(this, view);

  return view;

}
  
}
 

I've used Jake Wharton's Butterknife library to avoid using findViewById on every view in our row layout :-)

Check the code for full demo samples.

Download

Not yet.

Download [the latest JAR][4] or grab via Maven:

<! -- Coming soon -->

or Gradle:

# Coming soon

TODO'S

  • CursorAdapter with multiple views support
  • My WMultiArrayAdapter extends Object for a reason. It's very possible to draw our headers from another list (having two separated array lists or more, depending the number of custom view rows we would like to use) I can discuss whether use Generics or Object...
  • I have to study carefully how to interact with other libraries, like StickyListHeaders, pinned-section-listview and other multi view ones.

Developed By

License

Copyright 2014 DogmaLabs  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

Fluent mockito.

Gradle Plugin to check library licenses and generate license pages.

A sweeter Espresso. Never write your own IdlingResource again. Never manually turn off system animations again.

NumberMorphView for Android.

Simple command pattern helper class.

InfiniteListView is a custom Android ListView that gets extended at each time new items are loaded by swiping to the bottom of list. It also supports swipe-to-refresh behavior.

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