Gencycler


Source link: https://github.com/gilgoldzweig/gencycler

Gencycler

Gencycler is a compile time annotation processor, that writes the RecyclerView adapter code for you.

The adapter gives you a thread-safe way to access the elements just like a list. It does that by using extension functions like add, in(contains), remove, and much more(Look below to see full function list) And it's written in kotlin <3.

Install

  //if your'e using java you don't need to add the plugin
apply plugin: 'kotlin-kapt'
 repositories {

maven {
 url "https://jitpack.io" 
}

}

dependencies {

compile 'com.github.gilgoldzweig.Gencycler:annotations:version'

kapt 'com.github.gilgoldzweig.Gencycler:compiler:version' // if your'e using java replace 'kapt' with 'annotationProcessor'

}
 

Usage

In order to use it, your data types must implement an empty interface, GencyclerDataType The class lets the adapter identify between multiple view types and determine which is needed to be inflated.

In order for the adapter to decide when each type is inflated and at what time you pass a list of the interface.

I'm using 'data class' but it could be anything that implements the interface.
data class PersonType(val name: String = "Rick Sanchez", val age: Int = 1000, val homeLocation: String = "Hahahahah"): GencyclerDataType 
And another class just to have better example
data class AdType(val adId: String, val adType: String): GencyclerDataType 

Now to the actual adapter

@GencyclerAdapter(

 GencyclerViewHolder(R.layout.person_layout, //the layout res you want to be created

  GencyclerViewField("name", //fieldName

R.id.type_one_one_text, // view's id

  AppCompatTextView::class), // view's type

GencyclerViewField("age",

  R.id.age_text,

  AppCompatTextView::class), //same as above

  GencyclerViewField("homeLocation",

  R.id.home_location_text,

  AppCompatImageView::class), //same as above

classType = PersonType::class), //the class you want to use when the holder is binded

//another view holder
  GencyclerViewHolder(R.layout.ad_layout,

GencyclerViewField("adTitle",

  R.id.ad_title_text,

  AppCompatTextView::class),

  GencyclerViewField("adPreview",

  R.id.ad_preview_image,

  AppCompatImageView::class),

classType = AdType::class),

customName = ""

  // You can define a custom name for your generated adapter, if nothing is provided the name would be the same as your class name with a "Gencycler" prefix, example: "GencyclerYourAdapter")  class YourAdapter(val context: Context, val elements: ArrayList<GencyclerDataType>) ` 

Build your app and the adapter will be generated to use it just extend it

class YourAdapter(context: Context, elements: ArrayList<GencyclerDataType>): GencyclerYourAdapter(context, elements) {
  //for each of your view types you'll need to implement the customized onBind

 the method is an extension function of the view type you provided

 all of your views are there

  override fun PersonTypeViewHolder

.onBindPersonTypeViewHolder(position: Int, element: ProfileType) {

// use it however you like,

it could be simple as below or with a complex business logic. Your adapter your rules.

name.text = element.name

  age.text = element.age

  homeLocation = element.homeLocation

//You're also provided with an onClick and OnLongClick functions for easier usage.

 onClick {

  
}

 onLongClick {

}

 
}

  override fun AdTypeViewHolder

.onBindAdTypeViewHolder(position: Int, element: AdType) {

//same as above

 
}
  
}
 
When you extend the adapter you receive the following open functions.

val customRecyclerAdapter = GencyclerYourAdapter(context, ArrayList())

customRecyclerAdapter - adType //removing item and notifying the adapter if you are on uiThread

customRecyclerAdapter - 2 //removing item and notifying the adapter if you are on uiThread

customRecyclerAdapter + adType //adding item and notifying the adapter if you are on uiThread

customRecyclerAdapter.add(personType, 5)

customRecyclerAdapter[personType] //getPosition by type

customRecyclerAdapter[12] //getType by position

customRecyclerAdapter - 1..4 //removing position range and notifying the adapter if you are on uiThread

customRecyclerAdapter - listOf(adType, personType) //removing list of types and notifying the adapter if you are on uiThread

customRecyclerAdapter.setItem(5, newPersonType) // replaces the type in position 5 to newPersonType

customRecyclerAdapter.clear() // removes all the items and notifying the adapter if you are on uiThread

customRecyclerAdapter.count() // returns the list count

customRecyclerAdapter.setItems(listOf(personType, adType, adType, personType, morganFreemanPersonType)) //replace the current list and notifying the adapter if you are on uiThread

customRecyclerAdapter.isEmpty()

customRecyclerAdapter.isNotEmpty()

More functions and features will come in the future follow me on GitHub and receive updates as soon as I make them.

MIT License

Copyright (c) 2017 Gil Goldzweig

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

ToastLib is a library to customize Toast.

Easy-to-use animated clock icon.

This is light weight library for getting location updates periodically, can customize according to user requirement.

The flexible and easy to use WebView library with beautiful themes and extra options.

Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications.

SwipeCardview is a recyclerview that lists products, items or etc. with using cardview. Also it aligns the card to center.

  • Android API 14+
  • Optimized for the all screen sizes
  • Easy to use
  • Image loading with Ion library

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