Bapter


Source link: https://github.com/Ekalips/Bapter

Bapter

This is small library with few annotations and processors that will generate all RecyclerView.Adapters stuff that you need with only few lines of annotations

Usage

Just be sure, that DataBinding is enabled in your project.

@Adapter(
  dataSetType = @DataSetType(dataSetType = TestData.class),
  useViews = {

 @ViewFor(dataClass = TestData.class, viewRes = R.layout.rv_item_test_adapter)
  
}
,
  map = {
@Bind(bindClass = TestData.class, bindMode = BindMode.variable, bindingResourceName = "testData"),

 @Bind(bindClass = Void.class, bindMode = BindMode.method, bindingResourceName = "clickAdapter", methodName = "myMethod", methodCallMode = MethodCallMode.onClick)
}
) public class TestAdapter {
  
}
 

@Adapter - Main annotation that will contain other ones.

dataSetType = @DataSetType(dataSetType = TestData.class)

This will specify data that you'll use in your adapter. In this example, adapter will have private List<TestData> data as a data source.

useViews = { @ViewFor(dataClass = TestData.class, viewRes = R.layout.rv_item_test_adapter) }

Here you can specify what getItemViewType will return (based on data class)

map = { .. } - Annotation for specifying behaviour of onBindViewHolder method

@Bind

Basically all this is main thing that you carry about. bindingResourceName field corresponds to BR constant name. For example if your variable is 'BR.test' than you need bindingResourceName = "test"

@Bind can be 2 types ( bindMode):

  1. Bind as variable. This will generate simple binding.setVariable(BR.., object) based on bindClass ( if (object instacneof bindClass)..);

  2. Bind as method. Requires methodName specification for further abstract method generation. This can generate 3 things:

    a) Bind with return method ( methodCallMode = MethodCallMode.asReturn). This will generate abstract method with specified method name and set it's return value as variable ( binding.setVariable(BR.., result)); b) Bind as "onClick" ( methodCallMode = MethodCallMode.onClick). This will set View.OnClickListener to your BR variable. And then when click occurs it'll call specified method ('methodName'); c) Bind as "onLongClick" ( methodCallMode = MethodCallMode.onLongClick). Same as previous, but with View.OnLongClickListener.

All this stuff will be generated as "$CLASS_NAME$Generated" (in my example "TestAdapterGenerated"). And you can simply create instance of this class, implement generated abstract methods (if any was requested) and set it as adapter to your RecyclerView

To set data to this adapter you have 2 options:

  1. Just call adapter.setData(...) on your adapter instance.
  2. Bind it. There is one @BindingAdapter that coems from box. You can bind any List with src annotation and @BindingAdapter will call setData for you.

How to get

maven {

  url "http://dl.bintray.com/ekalips/Bapter" 
}
  compile 'com.ekalips:adapter-annotation:0.1.1' annotationProcessor 'com.ekalips:adapter-processor:0.1.1' 

Licence

Copyright 2017 Ekalips  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

A customizable indeterminate progress bar.

A gradle plugin to frame android screenshots with devices frames.

A very simple continuous click listener implementation for Android.

OAuth2Library is an extension for Retrofit that simplifies the process of authenticating against an OAuth 2 provider.

TedPicker is image selector library for android.

Do not waste your time for write image select function code. You can take a picture or select image from gallery. Also you can customize color, drawable, select count, etc for your application.

An easy to use Android library with a fluent interface to integrate voice interaction into your Application.

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